github.com/nyan233/littlerpc@v0.4.6-0.20230316182519-0c8d5c48abaf/core/container/iterator_test.go (about) 1 package container 2 3 import ( 4 "github.com/stretchr/testify/assert" 5 "testing" 6 ) 7 8 func TestIterator(t *testing.T) { 9 elems := []int{10, 18, 20, 40, 58, 68} 10 iter := NewIterator[int](len(elems), true, func(current int) int { 11 return elems[current] 12 }, func() { 13 return 14 }) 15 for _, v := range elems { 16 assert.Equal(t, iter.Take(), v, "Iterator take data no equal raw data") 17 } 18 assert.Equal(t, iter.Next(), false, "Iterator no end") 19 iter.Reset() 20 assert.Equal(t, iter.Next(), true, "Iterator no reset") 21 e, ok := iter.Index(len(elems) - 1) 22 assert.Equal(t, ok, true, "Iterator no able index access") 23 assert.Equal(t, e, elems[len(elems)-1], "Iterator index get data no equal raw data") 24 }