Separate test function into smaller cases

This commit is contained in:
Tevin Zhang 2020-07-16 15:01:49 +08:00
parent 8ae5c93531
commit 78e36140ca
No known key found for this signature in database
GPG Key ID: EE7DA2A50F0960FB
1 changed files with 31 additions and 17 deletions

View File

@ -7,27 +7,36 @@ import (
"testing"
)
func TestBool(t *testing.T) {
func TestDefaultValue(t *testing.T) {
t.Parallel()
v := NewBool(true)
if !v.IsSet() {
t.Fatal("NewValue(true) failed")
}
v = NewBool(false)
if v.IsSet() {
t.Fatal("NewValue(false) failed")
}
v = New()
v := New()
if v.IsSet() {
t.Fatal("Empty value of AtomicBool should be false")
}
v = NewBool(true)
if !v.IsSet() {
t.Fatal("NewValue(true) should be true")
}
v = NewBool(false)
if v.IsSet() {
t.Fatal("NewValue(false) should be false")
}
}
func TestIsNotSet(t *testing.T) {
t.Parallel()
v := New()
if v.IsSet() == v.IsNotSet() {
t.Fatal("AtomicBool.IsNotSet() should be the opposite of IsSet()")
}
}
func TestSetUnSet(t *testing.T) {
t.Parallel()
v := New()
v.Set()
if !v.IsSet() {
@ -38,6 +47,11 @@ func TestBool(t *testing.T) {
if v.IsSet() {
t.Fatal("AtomicBool.UnSet() failed")
}
}
func TestSetTo(t *testing.T) {
t.Parallel()
v := New()
v.SetTo(true)
if !v.IsSet() {
@ -56,12 +70,12 @@ func TestBool(t *testing.T) {
if set := v.SetToIf(false, true); !set || !v.IsSet() {
t.Fatal("AtomicBool.SetTo(false, true) failed")
}
v = New()
if v.IsSet() {
t.Fatal("Empty value of AtomicBool should be false")
}
func TestToggle(t *testing.T) {
t.Parallel()
v := New()
_ = v.Toggle()
if !v.IsSet() {
t.Fatal("AtomicBool.Toggle() to true failed")