@@ -119,3 +119,160 @@ func TestValues(t *testing.T) {
119119
120120 assert .Equal (t , testSize , n )
121121}
122+
123+ func TestUnset (t * testing.T ) {
124+ t .Run ("empty bitmap" , func (t * testing.T ) {
125+ b := New ()
126+ it := Unset (b , 5 , 10 )
127+
128+ expected := []uint32 {5 , 6 , 7 , 8 , 9 , 10 }
129+ actual := make ([]uint32 , 0 )
130+
131+ it (func (val uint32 ) bool {
132+ actual = append (actual , val )
133+ return true
134+ })
135+
136+ assert .Equal (t , expected , actual )
137+ })
138+
139+ t .Run ("bitmap with some values set" , func (t * testing.T ) {
140+ b := New ()
141+ b .AddInt (3 )
142+ b .AddInt (7 )
143+ b .AddInt (12 )
144+
145+ it := Unset (b , 5 , 10 )
146+
147+ expected := []uint32 {5 , 6 , 8 , 9 , 10 }
148+ actual := make ([]uint32 , 0 )
149+
150+ it (func (val uint32 ) bool {
151+ actual = append (actual , val )
152+ return true
153+ })
154+
155+ assert .Equal (t , expected , actual )
156+ })
157+
158+ t .Run ("range completely outside bitmap" , func (t * testing.T ) {
159+ b := New ()
160+ b .AddInt (1 )
161+ b .AddInt (2 )
162+ b .AddInt (3 )
163+
164+ it := Unset (b , 10 , 15 )
165+
166+ expected := []uint32 {10 , 11 , 12 , 13 , 14 , 15 }
167+ actual := make ([]uint32 , 0 )
168+
169+ it (func (val uint32 ) bool {
170+ actual = append (actual , val )
171+ return true
172+ })
173+
174+ assert .Equal (t , expected , actual )
175+ })
176+
177+ t .Run ("range includes set and unset values" , func (t * testing.T ) {
178+ b := New ()
179+ b .AddInt (5 )
180+ b .AddInt (8 )
181+ b .AddInt (9 )
182+
183+ it := Unset (b , 3 , 12 )
184+
185+ expected := []uint32 {3 , 4 , 6 , 7 , 10 , 11 , 12 }
186+ actual := make ([]uint32 , 0 )
187+
188+ it (func (val uint32 ) bool {
189+ actual = append (actual , val )
190+ return true
191+ })
192+
193+ assert .Equal (t , expected , actual )
194+ })
195+
196+ t .Run ("min greater than max" , func (t * testing.T ) {
197+ b := New ()
198+ it := Unset (b , 10 , 5 )
199+
200+ count := 0
201+ it (func (val uint32 ) bool {
202+ count ++
203+ return true
204+ })
205+
206+ assert .Equal (t , 0 , count )
207+ })
208+
209+ t .Run ("single value range - unset" , func (t * testing.T ) {
210+ b := New ()
211+ b .AddInt (5 )
212+
213+ it := Unset (b , 3 , 3 )
214+
215+ expected := []uint32 {3 }
216+ actual := make ([]uint32 , 0 )
217+
218+ it (func (val uint32 ) bool {
219+ actual = append (actual , val )
220+ return true
221+ })
222+
223+ assert .Equal (t , expected , actual )
224+ })
225+
226+ t .Run ("single value range - set" , func (t * testing.T ) {
227+ b := New ()
228+ b .AddInt (5 )
229+
230+ it := Unset (b , 5 , 5 )
231+
232+ count := 0
233+ it (func (val uint32 ) bool {
234+ count ++
235+ return true
236+ })
237+
238+ assert .Equal (t , 0 , count )
239+ })
240+
241+ t .Run ("early termination" , func (t * testing.T ) {
242+ b := New ()
243+
244+ it := Unset (b , 1 , 10 )
245+
246+ actual := make ([]uint32 , 0 )
247+ it (func (val uint32 ) bool {
248+ actual = append (actual , val )
249+ return len (actual ) < 3 // Stop after 3 values
250+ })
251+
252+ expected := []uint32 {1 , 2 , 3 }
253+ assert .Equal (t , expected , actual )
254+ })
255+
256+ t .Run ("large range with sparse bitmap" , func (t * testing.T ) {
257+ b := New ()
258+ b .AddInt (100 )
259+ b .AddInt (500 )
260+ b .AddInt (1000 )
261+
262+ it := Unset (b , 50 , 150 )
263+
264+ actual := make ([]uint32 , 0 )
265+ it (func (val uint32 ) bool {
266+ actual = append (actual , val )
267+ return true
268+ })
269+
270+ // Should include all values from 50-150 except 100
271+ assert .Equal (t , 100 , len (actual )) // 150-50+1 - 1 = 101 - 1 = 100
272+ assert .Contains (t , actual , uint32 (50 ))
273+ assert .Contains (t , actual , uint32 (99 ))
274+ assert .NotContains (t , actual , uint32 (100 ))
275+ assert .Contains (t , actual , uint32 (101 ))
276+ assert .Contains (t , actual , uint32 (150 ))
277+ })
278+ }
0 commit comments