github.com/sandwich-go/boost@v1.3.29/xcontainer/sset/gen_int_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 TestInt(t *testing.T) { 16 Convey("test sync set", t, func() { 17 for _, tr := range []*Int{NewInt(), NewSyncInt()} { 18 So(tr.Size(), ShouldBeZeroValue) 19 var e0 = __formatToInt(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(__formatToInt(2)), ShouldBeTrue) 26 So(tr.Size(), ShouldEqual, 2) 27 28 tr.AddIfNotExistFunc(__formatToInt(3), func() bool { 29 return false 30 }) 31 So(tr.Size(), ShouldEqual, 2) 32 tr.AddIfNotExistFunc(__formatToInt(3), func() bool { 33 return true 34 }) 35 So(tr.Size(), ShouldEqual, 3) 36 37 tr.AddIfNotExistFuncLock(__formatToInt(4), func() bool { 38 return false 39 }) 40 So(tr.Size(), ShouldEqual, 3) 41 tr.AddIfNotExistFuncLock(__formatToInt(4), func() bool { 42 return true 43 }) 44 So(tr.Size(), ShouldEqual, 4) 45 46 So(tr.Contains(__formatToInt(4)), ShouldBeTrue) 47 48 tr.Remove(__formatToInt(4)) 49 So(tr.Size(), ShouldEqual, 3) 50 51 So(tr.Slice(), ShouldContain, __formatToInt(30)) 52 So(tr.Slice(), ShouldContain, __formatToInt(2)) 53 So(tr.Slice(), ShouldContain, __formatToInt(3)) 54 55 tr.Clear() 56 So(tr.Size(), ShouldEqual, 0) 57 58 tr.Add(__formatToInt(3), __formatToInt(2)) 59 tr2 := newWithSafeInt(false) 60 tr2.Add(__formatToInt(3), __formatToInt(2)) 61 So(tr.Equal(tr2), ShouldBeTrue) 62 63 tr3 := newWithSafeInt(true) 64 tr3.Add(__formatToInt(3), __formatToInt(2)) 65 So(tr.Equal(tr3), ShouldBeTrue) 66 67 tr4, tr5 := newWithSafeInt(true), newWithSafeInt(true) 68 tr4.Add(__formatToInt(1), __formatToInt(4)) 69 tr5.Add(__formatToInt(1), __formatToInt(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 int) int { 78 return item 79 }) 80 }, ShouldNotPanic) 81 } 82 }) 83 }