github.com/sandwich-go/boost@v1.3.29/xcontainer/sarray/gen_uint8_test.go (about) 1 // Code generated by gotemplate. DO NOT EDIT. 2 3 package sarray 4 5 import ( 6 . "github.com/smartystreets/goconvey/convey" 7 8 "testing" 9 ) 10 11 func TestUint8(t *testing.T) { 12 Convey("test sync array", t, func() { 13 for _, tr := range []*Uint8{NewUint8(), NewSyncUint8()} { 14 So(tr.Len(), ShouldBeZeroValue) 15 _, exists := tr.Get(0) 16 So(exists, ShouldBeFalse) 17 So(tr.Empty(), ShouldBeTrue) 18 var e0 = __formatToUint8(3) 19 tr.PushLeft(e0) 20 So(tr.Len(), ShouldEqual, 1) 21 22 e := tr.At(0) 23 So(e, ShouldEqual, e0) 24 v, f := tr.Get(0) 25 So(f, ShouldBeTrue) 26 So(v, ShouldEqual, e) 27 _, f = tr.Get(1) 28 So(f, ShouldBeFalse) 29 30 tr.SetArray([]uint8{__formatToUint8(1), __formatToUint8(1), __formatToUint8(1), __formatToUint8(1), __formatToUint8(1)}) 31 So(tr.Len(), ShouldEqual, 5) 32 tr.SetArray([]uint8{__formatToUint8(1), __formatToUint8(2), __formatToUint8(3), __formatToUint8(4), __formatToUint8(5)}) 33 So(tr.Len(), ShouldEqual, 5) 34 35 rpv := __formatToUint8(20) 36 err := tr.Set(2, rpv) 37 So(err, ShouldBeEmpty) 38 So(tr.At(2), ShouldEqual, rpv) 39 40 tr.Replace([]uint8{__formatToUint8(1), __formatToUint8(1)}) 41 So(tr.Len(), ShouldEqual, 5) 42 So(tr.At(0), ShouldEqual, tr.At(1)) 43 So(tr.At(2), ShouldNotEqual, tr.At(0)) 44 45 iv1 := __formatToUint8(11) 46 err = tr.InsertBefore(0, iv1) 47 So(err, ShouldBeNil) 48 So(tr.At(0), ShouldEqual, iv1) 49 50 iv2 := __formatToUint8(12) 51 err = tr.InsertAfter(0, iv2) 52 So(err, ShouldBeNil) 53 So(tr.At(1), ShouldEqual, iv2) 54 55 So(tr.Contains(iv1), ShouldBeTrue) 56 So(tr.Search(iv1), ShouldNotEqual, -1) 57 58 So(tr.DeleteValue(iv2), ShouldBeTrue) 59 v, f = tr.LoadAndDelete(0) 60 So(f, ShouldBeTrue) 61 So(v, ShouldEqual, iv1) 62 63 pl := __formatToUint8(11) 64 tr.PushLeft(pl) 65 So(tr.At(0), ShouldEqual, pl) 66 pr := __formatToUint8(21) 67 tr.PushRight(pr) 68 So(tr.At(tr.Len()-1), ShouldEqual, pr) 69 70 v, f = tr.PopLeft() 71 So(v, ShouldEqual, pl) 72 v, f = tr.PopRight() 73 So(v, ShouldEqual, pr) 74 l := tr.Len() 75 _, f = tr.PopRand() 76 So(f, ShouldBeTrue) 77 So(tr.Len()+1, ShouldEqual, l) 78 l = tr.Len() 79 poplen := 2 80 pv := tr.PopRands(poplen) 81 So(len(pv), ShouldEqual, poplen) 82 So(tr.Len(), ShouldBeGreaterThanOrEqualTo, l-poplen) 83 84 aps := []uint8{__formatToUint8(35), __formatToUint8(40), __formatToUint8(45), __formatToUint8(50)} 85 tr.Append(aps...) 86 for i := len(aps); i > 0; i-- { 87 So(aps[i-1], ShouldEqual, func() uint8 { v, f = tr.PopRight(); So(f, ShouldBeTrue); return v }()) 88 } 89 90 tr.Clear() 91 So(tr.Len(), ShouldEqual, 0) 92 93 tr.Append(aps...) 94 s := tr.Slice() 95 So(len(s), ShouldEqual, tr.Len()) 96 97 k := 0 98 tr.WalkAsc(func(key int, val uint8) bool { 99 So(key, ShouldEqual, k) 100 So(val, ShouldEqual, s[k]) 101 k++ 102 return true 103 }) 104 105 k = len(s) - 1 106 tr.WalkDesc(func(key int, val uint8) bool { 107 So(key, ShouldEqual, k) 108 So(val, ShouldEqual, s[k]) 109 k-- 110 return true 111 }) 112 113 So(func() { 114 tr.LockFunc(func(array []uint8) { 115 return 116 }) 117 }, ShouldNotPanic) 118 119 So(func() { 120 tr.RLockFunc(func(array []uint8) { 121 return 122 }) 123 }, ShouldNotPanic) 124 125 j, err := tr.MarshalJSON() 126 So(err, ShouldBeNil) 127 err = tr.UnmarshalJSON(j) 128 So(err, ShouldBeNil) 129 } 130 }) 131 }