github.com/sandwich-go/boost@v1.3.29/xcontainer/sset/gen_int32_test.go (about) 1 // Code generated by gotemplate. DO NOT EDIT. 2 3 // sset 包提供了多种类型的集合 4 // 可以产生一个带读写锁的线程安全的SyncSet,也可以产生一个非线程安全的SyncSet 5 // New 产生非协程安全的版本 6 // NewSync 产生协程安全的版本 7 package sset 8 9 import ( 10 . "github.com/smartystreets/goconvey/convey" 11 12 "testing" 13 ) 14 15 func TestInt32(t *testing.T) { 16 Convey("test sync set", t, func() { 17 for _, tr := range []*Int32{NewInt32(), NewSyncInt32()} { 18 So(tr.Size(), ShouldBeZeroValue) 19 var e0 = __formatToInt32(30) 20 tr.Add(e0) 21 So(tr.Size(), ShouldEqual, 1) 22 tr.Add(e0) 23 So(tr.Size(), ShouldEqual, 1) 24 25 So(tr.AddIfNotExist(__formatToInt32(2)), ShouldBeTrue) 26 So(tr.Size(), ShouldEqual, 2) 27 28 tr.AddIfNotExistFunc(__formatToInt32(3), func() bool { 29 return false 30 }) 31 So(tr.Size(), ShouldEqual, 2) 32 tr.AddIfNotExistFunc(__formatToInt32(3), func() bool { 33 return true 34 }) 35 So(tr.Size(), ShouldEqual, 3) 36 37 tr.AddIfNotExistFuncLock(__formatToInt32(4), func() bool { 38 return false 39 }) 40 So(tr.Size(), ShouldEqual, 3) 41 tr.AddIfNotExistFuncLock(__formatToInt32(4), func() bool { 42 return true 43 }) 44 So(tr.Size(), ShouldEqual, 4) 45 46 So(tr.Contains(__formatToInt32(4)), ShouldBeTrue) 47 48 tr.Remove(__formatToInt32(4)) 49 So(tr.Size(), ShouldEqual, 3) 50 51 So(tr.Slice(), ShouldContain, __formatToInt32(30)) 52 So(tr.Slice(), ShouldContain, __formatToInt32(2)) 53 So(tr.Slice(), ShouldContain, __formatToInt32(3)) 54 55 tr.Clear() 56 So(tr.Size(), ShouldEqual, 0) 57 58 tr.Add(__formatToInt32(3), __formatToInt32(2)) 59 tr2 := newWithSafeInt32(false) 60 tr2.Add(__formatToInt32(3), __formatToInt32(2)) 61 So(tr.Equal(tr2), ShouldBeTrue) 62 63 tr3 := newWithSafeInt32(true) 64 tr3.Add(__formatToInt32(3), __formatToInt32(2)) 65 So(tr.Equal(tr3), ShouldBeTrue) 66 67 tr4, tr5 := newWithSafeInt32(true), newWithSafeInt32(true) 68 tr4.Add(__formatToInt32(1), __formatToInt32(4)) 69 tr5.Add(__formatToInt32(1), __formatToInt32(4)) 70 s := tr.Size() 71 tr.Merge(tr4) 72 tr2.Merge(tr5) 73 So(tr.Equal(tr2), ShouldBeTrue) 74 So(tr.Size(), ShouldEqual, s+2) 75 76 So(func() { 77 tr5.Walk(func(item int32) int32 { 78 return item 79 }) 80 }, ShouldNotPanic) 81 } 82 }) 83 }