@@ -272,11 +272,31 @@ func TestIntervalTreeDelete(t *testing.T) {
272
272
func TestIntervalTreeFind (t * testing.T ) {
273
273
ivt := NewIntervalTree ()
274
274
ivl1 := NewInt64Interval (3 , 6 )
275
- assert .Nilf (t , ivt .Find (ivl1 ), "find expected nil on empty tree" )
276
- ivt .Insert (ivl1 , 123 )
277
- assert .Equalf (t , ivl1 , ivt .Find (ivl1 ).Ivl , "find expected to return exact-matched interval" )
275
+ val := 123
276
+ assert .Nilf (t , ivt .Find (ivl1 ), "find for %v expected nil on empty tree" , ivl1 )
277
+ // insert interval [3, 6) into tree
278
+ ivt .Insert (ivl1 , val )
279
+ // check cases of expected find matches and non-matches
280
+ assert .NotNilf (t , ivt .Find (ivl1 ), "find expected not-nil on exact-matched interval %v" , ivl1 )
281
+ assert .Equalf (t , ivl1 , ivt .Find (ivl1 ).Ivl , "find expected to return exact-matched interval %v" , ivl1 )
278
282
ivl2 := NewInt64Interval (3 , 7 )
279
- assert .Nilf (t , ivt .Find (ivl2 ), "find expected nil on single-matched endpoint" )
283
+ assert .Nilf (t , ivt .Find (ivl2 ), "find expected nil on matched start, different end %v" , ivl2 )
284
+ ivl3 := NewInt64Interval (2 , 6 )
285
+ assert .Nilf (t , ivt .Find (ivl3 ), "find expected nil on different start, matched end %v" , ivl3 )
286
+ ivl4 := NewInt64Interval (10 , 20 )
287
+ assert .Nilf (t , ivt .Find (ivl4 ), "find expected nil on different start, different end %v" , ivl4 )
288
+ // insert the additional intervals into the tree, and check they can each be found.
289
+ ivls := []Interval {ivl2 , ivl3 , ivl4 }
290
+ for _ , ivl := range ivls {
291
+ ivt .Insert (ivl , val )
292
+ assert .NotNilf (t , ivt .Find (ivl ), "find expected not-nil on exact-matched interval %v" , ivl )
293
+ assert .Equalf (t , ivl , ivt .Find (ivl ).Ivl , "find expected to return exact-matched interval %v" , ivl )
294
+ }
295
+ // check additional intervals no longer found after deletion
296
+ for _ , ivl := range ivls {
297
+ assert .Truef (t , ivt .Delete (ivl ), "expected successful delete on %v" , ivl )
298
+ assert .Nilf (t , ivt .Find (ivl ), "find expected nil after deleted interval %v" , ivl )
299
+ }
280
300
}
281
301
282
302
func TestIntervalTreeIntersects (t * testing.T ) {
@@ -357,6 +377,8 @@ func TestIntervalTreeRandom(t *testing.T) {
357
377
assert .Equalf (t , ivl , iv .Ivl , "find did not get matched interval %v" , ab )
358
378
assert .Truef (t , ivt .Delete (ivl ), "did not delete %v as expected" , ab )
359
379
delete (ivs , ab )
380
+ ivAfterDel := ivt .Find (ivl )
381
+ assert .Nilf (t , ivAfterDel , "expected find nil after deletion on %v" , ab )
360
382
}
361
383
362
384
assert .Equalf (t , 0 , ivt .Len (), "got ivt.Len() = %v, expected 0" , ivt .Len ())
0 commit comments