Skip to content

Commit

Permalink
优化单元测试
Browse files Browse the repository at this point in the history
  • Loading branch information
flycash committed Oct 1, 2022
1 parent 6bf2310 commit 5028881
Showing 1 changed file with 1 addition and 30 deletions.
31 changes: 1 addition & 30 deletions syncx/atomicx/atomic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,9 @@ func TestValue_Swap(t *testing.T) {
assert.Equal(t, tc.new, newVal)
})
}

val := NewValue[*User]()
oldVal := val.Swap(&User{})
assert.Nil(t, oldVal)
}

func TestValue_Store(t *testing.T) {
func TestValue_Store_Load(t *testing.T) {
testCases := []struct {
name string
input *User
Expand Down Expand Up @@ -147,31 +143,6 @@ func TestValue_Store(t *testing.T) {
}
}

func TestValue_Load(t *testing.T) {
testCases := []struct {
name string
val *Value[*User]
wantVal *User
}{
{
name: "nil",
val: NewValue[*User](),
},
{
name: "get user",
val: NewValueOf[*User](&User{Name: "Tom"}),
wantVal: &User{Name: "Tom"},
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
val := tc.val.Load()
assert.Equal(t, tc.wantVal, val)
})
}
}

func BenchmarkValue_Load(b *testing.B) {
b.Run("Value", func(b *testing.B) {
val := NewValueOf[int](123)
Expand Down

0 comments on commit 5028881

Please sign in to comment.