github.com/sandwich-go/boost@v1.3.29/xcontainer/slist/gen_uint8_test.go (about) 1 // Code generated by gotemplate. DO NOT EDIT. 2 3 // slist 包提供了一个同步的链表实现 4 // 可以产生一个带读写锁的线程安全的SyncList,也可以产生一个非线程安全的SyncList 5 // New 产生非协程安全的版本 6 // NewSync 产生协程安全的版本 7 package slist 8 9 import ( 10 "container/list" 11 12 . "github.com/smartystreets/goconvey/convey" 13 14 "testing" 15 ) 16 17 func TestUint8(t *testing.T) { 18 Convey("test sync list", t, func() { 19 for _, tr := range []*Uint8{NewUint8(), NewSyncUint8()} { 20 So(tr.Len(), ShouldBeZeroValue) 21 var e0 = __formatToUint8(3) 22 tr.PushBack(e0) 23 So(tr.Len(), ShouldEqual, 1) 24 e := tr.PopBack() 25 So(e, ShouldEqual, e0) 26 27 tr.PushFront(e0) 28 So(tr.Len(), ShouldEqual, 1) 29 e = tr.PopFront() 30 So(e, ShouldEqual, e0) 31 32 ps := []uint8{__formatToUint8(1), __formatToUint8(1), __formatToUint8(3), __formatToUint8(4), __formatToUint8(5)} 33 tr.PushFronts(ps) 34 So(tr.Len(), ShouldEqual, len(ps)) 35 pops := tr.PopFronts(2) 36 So(len(pops), ShouldEqual, 2) 37 pops = tr.PopFrontAll() 38 So(len(pops), ShouldEqual, 3) 39 40 ps = []uint8{__formatToUint8(1), __formatToUint8(2), __formatToUint8(3), __formatToUint8(4)} 41 tr.PushBacks(ps) 42 So(tr.Len(), ShouldEqual, len(ps)) 43 pops = tr.PopBacks(2) 44 So(len(pops), ShouldEqual, 2) 45 pops = tr.PopBackAll() 46 So(len(pops), ShouldEqual, 2) 47 48 ps = []uint8{__formatToUint8(1), __formatToUint8(2), __formatToUint8(3), __formatToUint8(4)} 49 tr.Clear() 50 tr.PushBacks(ps) 51 So(tr.FrontAll(), ShouldResemble, ps) 52 tr.Clear() 53 54 psrev := []uint8{__formatToUint8(4), __formatToUint8(3), __formatToUint8(2), __formatToUint8(1)} 55 tr.PushBacks(ps) 56 So(tr.BackAll(), ShouldResemble, psrev) 57 58 So(tr.FrontValue(), ShouldEqual, __formatToUint8(1)) 59 So(tr.Front().Value, ShouldEqual, __formatToUint8(1)) 60 So(tr.BackValue(), ShouldEqual, __formatToUint8(4)) 61 So(tr.Back().Value, ShouldEqual, __formatToUint8(4)) 62 63 b, b1 := tr.Back(), tr.Back().Prev() 64 tr.MoveBefore(tr.Back(), tr.Front()) 65 So(tr.Front(), ShouldEqual, b) 66 So(tr.Back(), ShouldEqual, b1) 67 68 f0, f1 := tr.Front(), tr.Front().Next() 69 tr.MoveAfter(tr.Front(), tr.Back()) 70 So(tr.Back(), ShouldEqual, f0) 71 So(tr.Front(), ShouldEqual, f1) 72 73 b, b1 = tr.Back(), tr.Back().Prev() 74 tr.MoveToFront(tr.Back()) 75 So(tr.Front(), ShouldEqual, b) 76 So(tr.Back(), ShouldEqual, b1) 77 78 f0, f1 = tr.Front(), tr.Front().Next() 79 tr.MoveToBack(tr.Front()) 80 So(tr.Back(), ShouldEqual, f0) 81 So(tr.Front(), ShouldEqual, f1) 82 83 n, ns, ol := NewUint8(), NewSyncUint8(), tr.Len() 84 n.PushFronts([]uint8{__formatToUint8(1), __formatToUint8(2)}) 85 ns.PushFronts([]uint8{__formatToUint8(1), __formatToUint8(2)}) 86 tr.PushFrontList(n) 87 So(tr.Len(), ShouldEqual, ol+2) 88 tr.PushFrontList(ns) 89 So(tr.Len(), ShouldEqual, ol+2+2) 90 91 f0, trl := tr.Front(), tr.Len() 92 tr.InsertBefore(tr.Front(), __formatToUint8(10)) 93 So(tr.Front().Next(), ShouldEqual, f0) 94 So(tr.Front().Value, ShouldEqual, __formatToUint8(10)) 95 So(tr.Len(), ShouldEqual, trl+1) 96 97 b, trl = tr.Back(), tr.Len() 98 tr.InsertAfter(tr.Back(), __formatToUint8(10)) 99 So(tr.Back().Prev(), ShouldEqual, b) 100 So(tr.Back().Value, ShouldEqual, __formatToUint8(10)) 101 So(tr.Len(), ShouldEqual, trl+1) 102 103 bv := tr.Back().Value 104 So(tr.Remove(tr.Back()), ShouldEqual, bv) 105 106 So(func() { tr.Removes([]*ElementUint8{tr.Front(), tr.Front().Next()}) }, ShouldNotPanic) 107 So(func() { tr.RemoveAll() }, ShouldNotPanic) 108 So(tr.Len(), ShouldEqual, 0) 109 110 tr.PushFrontList(n) 111 tr.Clear() 112 So(tr.Len(), ShouldEqual, 0) 113 114 tr.PushFronts([]uint8{__formatToUint8(10), __formatToUint8(20), __formatToUint8(30), __formatToUint8(40)}) 115 116 So(func() { 117 tr.RLockFunc(func(list *list.List) { 118 So(list.Front().Value, ShouldEqual, __formatToUint8(40)) 119 }) 120 }, ShouldNotPanic) 121 122 So(func() { 123 tr.LockFunc(func(list *list.List) { 124 So(list.Front().Value, ShouldEqual, __formatToUint8(40)) 125 }) 126 }, ShouldNotPanic) 127 128 So(func() { 129 tr.Iterator(func(e *ElementUint8) bool { 130 return true 131 }) 132 }, ShouldNotPanic) 133 134 So(func() { 135 tr.IteratorAsc(func(e *ElementUint8) bool { 136 return true 137 }) 138 }, ShouldNotPanic) 139 140 So(func() { 141 tr.IteratorDesc(func(e *ElementUint8) bool { 142 return true 143 }) 144 }, ShouldNotPanic) 145 146 } 147 }) 148 }