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