@@ -82,18 +82,18 @@ func checkRedBlack(tb testing.TB, node *node, dimension int) (int64, int64, int6
82
82
fn (minR , maxR )
83
83
84
84
min := min (minL , minR )
85
- if min == - 1 && node .min != node .low {
85
+ if min == - 1 && node .min != node .interval . LowAtDimension ( 1 ) {
86
86
tb .Errorf (`Min not set correctly, node: %+v` , node )
87
87
} else if min != - 1 && node .children [0 ] != nil && node .children [0 ].min != node .min {
88
88
tb .Errorf (`Min not set correctly: node: %+v, child: %+v` , node , node .children [0 ])
89
- } else if min != - 1 && node .children [0 ] == nil && node .min != node .low {
89
+ } else if min != - 1 && node .children [0 ] == nil && node .min != node .interval . LowAtDimension ( 1 ) {
90
90
tb .Errorf (`Min not set correctly: %+v` , node )
91
91
}
92
92
93
93
max := max (maxL , maxR )
94
- if max == - 1 && node .max != node .high {
94
+ if max == - 1 && node .max != node .interval . HighAtDimension ( 1 ) {
95
95
tb .Errorf (`Max not set correctly, node: %+v` , node )
96
- } else if max > node .high && max != node .max {
96
+ } else if max > node .interval . HighAtDimension ( 1 ) && max != node .max {
97
97
tb .Errorf (`Max not set correctly, max: %+v, node: %+v` , max , node )
98
98
}
99
99
@@ -598,155 +598,6 @@ func TestAddDeleteDuplicatesRebalanceRandomOrder(t *testing.T) {
598
598
assert .Equal (t , uint64 (0 ), it .Len ())
599
599
}
600
600
601
- func TestInsertSingleAtDimension (t * testing.T ) {
602
- tree , ivs := constructSingleDimensionTestTree (3 )
603
-
604
- modified , deleted := tree .Insert (1 , 11 , 1 )
605
- assert .Len (t , deleted , 0 )
606
- assert .Equal (t , ivs [1 :], modified )
607
-
608
- result := tree .Query (constructSingleDimensionInterval (11 , 20 , 0 ))
609
- assert .Equal (t , ivs [1 :], result )
610
- checkRedBlack (t , tree .root , 1 )
611
-
612
- assert .Equal (t , int64 (0 ), tree .root .min )
613
- assert .Equal (t , int64 (13 ), tree .root .max )
614
- }
615
-
616
- func TestInsertMultipleAtDimension (t * testing.T ) {
617
- tree , ivs := constructSingleDimensionTestTree (3 )
618
-
619
- modified , deleted := tree .Insert (1 , 11 , 2 )
620
- assert .Len (t , deleted , 0 )
621
- assert .Equal (t , ivs [1 :], modified )
622
-
623
- result := tree .Query (constructSingleDimensionInterval (11 , 20 , 0 ))
624
- assert .Equal (t , ivs [1 :], result )
625
- checkRedBlack (t , tree .root , 1 )
626
-
627
- assert .Equal (t , int64 (0 ), tree .root .min )
628
- assert .Equal (t , int64 (14 ), tree .root .max )
629
- }
630
-
631
- func TestInsertAtLowestIndex (t * testing.T ) {
632
- tree , ivs := constructSingleDimensionTestTree (3 )
633
-
634
- modified , deleted := tree .Insert (1 , - 1 , 1 )
635
- assert .Equal (t , ivs [0 :], modified )
636
- assert .Len (t , deleted , 0 )
637
-
638
- result := tree .Query (constructSingleDimensionInterval (0 , 0 , 0 ))
639
- assert .Len (t , result , 0 )
640
-
641
- result = tree .Query (constructSingleDimensionInterval (1 , 4 , 0 ))
642
- assert .Equal (t , ivs , result )
643
-
644
- checkRedBlack (t , tree .root , 1 )
645
-
646
- assert .Equal (t , int64 (1 ), tree .root .min )
647
- assert .Equal (t , int64 (13 ), tree .root .max )
648
- }
649
-
650
- func TestDeleteSingleAtDimension (t * testing.T ) {
651
- tree , ivs := constructSingleDimensionTestTree (3 )
652
-
653
- modified , deleted := tree .Insert (1 , 11 , - 1 )
654
- assert .Equal (t , ivs [1 :], modified )
655
- assert .Len (t , deleted , 0 )
656
-
657
- result := tree .Query (constructSingleDimensionInterval (11 , 20 , 0 ))
658
- assert .Equal (t , ivs [1 :], result )
659
-
660
- result = tree .Query (constructSingleDimensionInterval (9 , 20 , 0 ))
661
- assert .Equal (t , ivs , result )
662
-
663
- checkRedBlack (t , tree .root , 1 )
664
-
665
- assert .Equal (t , int64 (0 ), tree .root .min )
666
- assert .Equal (t , int64 (11 ), tree .root .max )
667
- }
668
-
669
- func TestDeleteBelowLowestIndex (t * testing.T ) {
670
- tree := newTree (1 )
671
-
672
- ivs := make (Intervals , 0 , 3 )
673
- for i := int64 (0 ); i < 3 ; i ++ {
674
- iv := constructSingleDimensionInterval (i + 1 , i + 11 , uint64 (i ))
675
- ivs = append (ivs , iv )
676
- }
677
-
678
- tree .Add (ivs ... )
679
-
680
- modified , deleted := tree .Insert (1 , 0 , - 1 )
681
- assert .Equal (t , ivs , modified )
682
- assert .Len (t , deleted , 0 )
683
-
684
- result := tree .Query (constructSingleDimensionInterval (0 , 0 , 0 ))
685
- assert .Equal (t , ivs [:1 ], result )
686
-
687
- result = tree .Query (constructSingleDimensionInterval (0 , 10 , 0 ))
688
- assert .Equal (t , ivs , result )
689
-
690
- checkRedBlack (t , tree .root , 1 )
691
- assert .Equal (t , int64 (0 ), tree .root .min )
692
- assert .Equal (t , int64 (12 ), tree .root .max )
693
- }
694
-
695
- func TestInsertDeletesInterval (t * testing.T ) {
696
- tree , ivs := constructSingleDimensionTestTree (3 )
697
-
698
- modified , deleted := tree .Insert (1 , 0 , - 11 )
699
- assert .Equal (t , ivs [1 :], modified )
700
- assert .Equal (t , ivs [:1 ], deleted )
701
-
702
- result := tree .Query (constructSingleDimensionInterval (3 , 10 , 0 ))
703
- assert .Len (t , result , 0 )
704
-
705
- result = tree .Query (constructSingleDimensionInterval (0 , 2 , 0 ))
706
- assert .Equal (t , ivs [1 :], result )
707
-
708
- checkRedBlack (t , tree .root , 1 )
709
- assert .Equal (t , uint64 (2 ), tree .Len ())
710
- assert .Equal (t , int64 (0 ), tree .root .min )
711
- assert .Equal (t , int64 (1 ), tree .root .max )
712
- }
713
-
714
- func TestDeleteMiddleOfRange (t * testing.T ) {
715
- tree , ivs := constructSingleDimensionTestTree (3 )
716
-
717
- modified , deleted := tree .Insert (1 , 5 , - 10 )
718
- assert .Equal (t , ivs , modified )
719
- assert .Len (t , deleted , 0 )
720
-
721
- checkRedBlack (t , tree .root , 1 )
722
- assert .Equal (t , int64 (0 ), tree .root .min )
723
- assert .Equal (t , int64 (5 ), tree .root .max )
724
- }
725
-
726
- func BenchmarkInsertPositive (b * testing.B ) {
727
- numItems := 1000
728
-
729
- tree , _ := constructSingleDimensionTestTree (numItems )
730
-
731
- b .ResetTimer ()
732
-
733
- for i := 0 ; i < b .N ; i ++ {
734
- tree .Insert (1 , 0 , 1 )
735
- }
736
- }
737
-
738
- func BenchmarkInsertNegative (b * testing.B ) {
739
- numItems := 1000
740
-
741
- tree , _ := constructSingleDimensionTestTree (numItems )
742
-
743
- b .ResetTimer ()
744
-
745
- for i := 0 ; i < b .N ; i ++ {
746
- tree .Insert (1 , 0 , int64 (numItems ))
747
- }
748
- }
749
-
750
601
func TestInsertDuplicateIntervalsToRoot (t * testing.T ) {
751
602
tree := newTree (1 )
752
603
iv1 := constructSingleDimensionInterval (0 , 10 , 1 )
@@ -771,14 +622,3 @@ func TestInsertDuplicateIntervalChildren(t *testing.T) {
771
622
result := tree .Query (constructSingleDimensionInterval (0 , 10 , 0 ))
772
623
assert .Contains (t , result , iv1 )
773
624
}
774
-
775
- func TestDeleteAtDimensionalSinglePositionReference (t * testing.T ) {
776
- tree := newTree (2 )
777
- iv := constructMultiDimensionInterval (
778
- 0 , & dimension {low : 0 , high : 1 }, & dimension {low : 4 , high : 5 },
779
- )
780
- tree .Add (iv )
781
- modified , deleted := tree .Insert (2 , 1 , - 1 )
782
- assert .Equal (t , Intervals {iv }, modified )
783
- assert .Len (t , deleted , 0 )
784
- }
0 commit comments