gitee.com/sy_183/go-common@v1.0.5-0.20231205030221-958cfe129b47/container/linked-list_test.go (about) 1 package container 2 3 import ( 4 "fmt" 5 "math/rand" 6 "testing" 7 ) 8 9 func TestLinkedList(t *testing.T) { 10 l := 200000 11 list := NewLinkedList[int](l) 12 for i := 0; i < l; i++ { 13 if rand.Int()&1 == 0 { 14 list.Push(i) 15 } else { 16 list.Unshift(i) 17 } 18 } 19 for i := 0; i < l; i++ { 20 if rand.Int()&1 == 0 { 21 list.Shift() 22 } else { 23 list.Pop() 24 } 25 } 26 fmt.Println(list.Len()) 27 } 28 29 func BenchmarkLinkedList(b *testing.B) { 30 l := 200000 31 list := NewLinkedList[int](l) 32 for i := 0; i < b.N; i++ { 33 for i := 0; i < l; i++ { 34 list.Push(i) 35 } 36 for i := 0; i < l; i++ { 37 list.Shift() 38 } 39 } 40 }