MCPcopy
hub / github.com/RoaringBitmap/roaring / TestIteratorAdvance

Function TestIteratorAdvance

roaring_test.go:3108–3173  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

3106}
3107
3108func TestIteratorAdvance(t *testing.T) {
3109 values := []uint32{1, 2, 15, 16, 31, 32, 33, 9999, MaxUint16}
3110 bm := New()
3111
3112 for n := 0; n < len(values); n++ {
3113 bm.Add(values[n])
3114 }
3115
3116 cases := []struct {
3117 minval uint32
3118 expected uint32
3119 }{
3120 {0, 1},
3121 {1, 1},
3122 {2, 2},
3123 {3, 15},
3124 {30, 31},
3125 {33, 33},
3126 {9998, 9999},
3127 {MaxUint16, MaxUint16},
3128 }
3129
3130 t.Run("advance by using a new int iterator", func(t *testing.T) {
3131 for _, c := range cases {
3132 i := bm.Iterator()
3133 i.AdvanceIfNeeded(c.minval)
3134
3135 assert.True(t, i.HasNext())
3136 assert.Equal(t, c.expected, i.PeekNext())
3137 }
3138 })
3139
3140 t.Run("advance by using the same int iterator", func(t *testing.T) {
3141 i := bm.Iterator()
3142
3143 for _, c := range cases {
3144 i.AdvanceIfNeeded(c.minval)
3145
3146 assert.True(t, i.HasNext())
3147 assert.Equal(t, c.expected, i.PeekNext())
3148 }
3149 })
3150
3151 t.Run("advance out of a container value", func(t *testing.T) {
3152 i := bm.Iterator()
3153
3154 i.AdvanceIfNeeded(MaxUint32)
3155 assert.False(t, i.HasNext())
3156
3157 i.AdvanceIfNeeded(MaxUint32)
3158 assert.False(t, i.HasNext())
3159 })
3160
3161 t.Run("advance on a value that is less than the pointed value", func(t *testing.T) {
3162 i := bm.Iterator()
3163 i.AdvanceIfNeeded(29)
3164
3165 assert.True(t, i.HasNext())

Callers

nothing calls this directly

Calls 6

NewFunction · 0.70
AdvanceIfNeededMethod · 0.65
HasNextMethod · 0.65
PeekNextMethod · 0.65
AddMethod · 0.45
IteratorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…