def Boolean_test(): ok_(Interval(1, 1)) ok_(Interval(1, 10)) ok_(not Interval(2, 1)) ok_(not Interval(0, 0)) ok_(not Interval(0, 5)) ok_(not Interval(-1, 1)) ok_(not Interval.Empty())
def Reference_test(): i1 = Interval(1, 10) i1c = Interval(1, 10) i2 = Interval(5, 15) i2c = Interval(5, 15) i3 = i1 - i2 eq_(i1, i1c) eq_(i2, i2c) i3 = i1 | i2 eq_(i1, i1c) eq_(i2, i2c) i3 = i1 & i2 eq_(i1, i1c) eq_(i2, i2c) eq_(i3, Interval(5, 10))
def IntersectError_test(): IntervalSet( Interval( 2, 8 ) ) & IntervalSet( Interval( 1, 10 ) )
def ContainsError_test(): IntervalSet( Interval( 2, 8 ) ) in IntervalSet( Interval( 1, 10 ) )
def BestQueryRange_test(): s = IntervalSet() r = s.GetIntervalForQuery( Interval( 30, 40 ), 10 ) eq_( r, Interval( 30, 40 ) ) s |= r # [ [30, 40] ] r = s.GetIntervalForQuery( Interval( 29, 29 ), 10 ) eq_( r, Interval( 20, 29 ) ) s |= r # [ [20, 40] ] r = s.GetIntervalForQuery( Interval( 31, 41 ), 10 ) eq_( r, Interval( 41, 50 ) ) s |= r # [ [20, 50] ] r = s.GetIntervalForQuery( Interval( 60, 60 ), 10 ) eq_( r, Interval( 60, 69 ) ) s |= r # [ [20, 50], [60, 69] ] r = s.GetIntervalForQuery( Interval( 59, 68 ), 10 ) eq_( r, Interval( 51, 59 ) ) s |= r # [ [20, 69] ] r = s.GetIntervalForQuery( Interval( 85, 100 ), 10 ) eq_( r, Interval( 85, 100 ) ) s |= r # [ [20, 69], [85, 100] ] r = s.GetIntervalForQuery( Interval( 61, 70 ), 10 ) eq_( r, Interval( 70, 79 ) ) # [ [20, 69], [85, 100] ] r = s.GetIntervalForQuery( Interval( 83, 92 ), 10 ) eq_( r, Interval( 75, 84 ) ) # [ [20, 69], [85, 100] ] r = s.GetIntervalForQuery( Interval( 72, 81 ), 10 ) eq_( r, Interval( 72, 81 ) ) s |= r # [ [20, 69], [72, 81], [85, 100] ] r = s.GetIntervalForQuery( Interval( 105, 106 ), 10 ) eq_( r, Interval( 105, 114 ) ) s |= r # [ [20, 69], [72, 81], [85, 100], [105, 114] ] r = s.GetIntervalForQuery( Interval( 70, 104 ), 10 ) eq_( r, IntervalSet( Interval( 70, 71 ), Interval( 82, 84 ), Interval( 101, 104 ) ) ) s |= r # [20, 114] eq_( s, IntervalSet( Interval( 20, 114 ) ) ) s = IntervalSet() r = s.GetIntervalForQuery( Interval( 9, 9 ), 20 ) eq_( r, Interval( 9, 28 ) ) s |= r # [9, 28] r = s.GetIntervalForQuery( Interval( 8, 8 ), 20 ) eq_( r, Interval( 1, 8 ) ) s |= r # [1, 28] r = s.GetIntervalForQuery( Interval( 35, 40 ), 10 ) eq_( r, Interval( 35, 44 ) ) s |= r # [ [1, 28], [35, 44] ] r = s.GetIntervalForQuery( Interval( 30, 31 ), 10 ) eq_( r, Interval( 29, 34 ) ) r = s.GetIntervalForQuery( Interval( 26, 31 ), 10 ) eq_( r, Interval( 29, 34 ) ) s |= r # [1, 44] eq_( s, IntervalSet( Interval( 1, 44 ) ) )
def Subtract_test(): s = IntervalSet( Interval( 1, 10 ), Interval( 20, 30 ), Interval( 40, 50 ) ) eq_( s - Interval( 1, 50 ), IntervalSet() ) eq_( s - Interval( 1, 9 ), IntervalSet( Interval( 10, 10 ), Interval( 20, 30 ), Interval( 40, 50 ) ) ) eq_( s - Interval( 25, 25 ), IntervalSet( Interval( 1, 10 ), Interval( 20, 24 ), Interval( 26, 30 ), Interval( 40, 50 ) ) ) eq_( s - Interval( 12, 18 ), IntervalSet( Interval( 1, 10 ), Interval( 20, 30 ), Interval( 40, 50 ) ) )
def Union_test(): eq_(Interval(1, 10) | Interval(11, 20), Interval(1, 20)) eq_(Interval(20, 30) | Interval(10, 19), Interval(10, 30)) eq_(Interval(1, 10) | Interval(8, 20), Interval(1, 20)) eq_( Interval(1, 10) | Interval(15, 20), IntervalSet(Interval(1, 10), Interval(15, 20))) eq_( Interval(15, 20) | Interval(1, 10), IntervalSet(Interval(1, 10), Interval(15, 20)))
def Union_test(): s = IntervalSet() s |= Interval( 1, 10 ) eq_( s, IntervalSet( Interval( 1, 10 ) ) ) s |= Interval( 20, 30 ) eq_( s, IntervalSet( Interval( 1, 10 ), Interval( 20, 30 ) ) ) s |= Interval( 40, 50 ) eq_( s, IntervalSet( Interval( 1, 10 ), Interval( 20, 30 ), Interval( 40, 50 ) ) ) eq_( s | Interval( 11, 19 ), IntervalSet( Interval( 1, 30 ), Interval( 40, 50 ) ) ) eq_( s | Interval( 11, 15 ), IntervalSet( Interval( 1, 15 ), Interval( 20, 30 ), Interval( 40, 50 ) ) ) eq_( s | Interval( 32, 39 ), IntervalSet( Interval( 1, 10 ), Interval( 20, 30 ), Interval( 32, 50 ) ) ) eq_( s | Interval( 32, 38 ), IntervalSet( Interval( 1, 10 ), Interval( 20, 30 ), Interval( 32, 38 ), Interval( 40, 50 ) ) ) eq_( s | Interval(15, 35), IntervalSet( Interval( 1, 10 ), Interval( 15, 35 ), Interval( 40, 50 ) ) ) eq_( s | Interval(5, 45), IntervalSet( Interval( 1, 50 ) ) ) eq_( s | IntervalSet( Interval( 11, 19 ), Interval( 35, 39 ) ), IntervalSet( Interval( 1, 30 ), Interval( 35, 50 ) ) )
def Construction_test(): eq_( IntervalSet( Interval( 1, 10 ), Interval( 20, 30 ) ), IntervalSet( Interval( 20, 30 ), Interval( 1, 10 ) ) )
def Comparison_test(): eq_(Interval(1, 10), Interval(1, 10)) ok_(Interval(1, 10) != Interval(1, 11)) ok_(Interval(1, 10) != Interval(2, 10)) ok_(Interval(1, 10) != Interval(2, 11)) ok_(Interval(1, 10) < Interval(11, 20)) ok_(not (Interval(1, 10) < Interval(10, 20))) ok_(not (Interval(1, 10) < Interval(5, 20))) ok_(not (Interval(1, 10) < Interval(2, 9))) ok_(Interval(11, 20) > Interval(1, 10)) ok_(not (Interval(10, 20) > Interval(1, 10))) ok_(not (Interval(10, 20) > Interval(1, 15))) ok_(not (Interval(10, 20) > Interval(12, 19)))
def Length_test(): eq_(len(Interval(1, 1)), 1) eq_(len(Interval(1, 10)), 10) eq_(len(Interval(10, 20)), 11) eq_(len(Interval(0, 1)), 2)
def String_test(): # 100% coverage baby eq_("%s" % Interval(1, 10), "[1, 10]")
def Operations_test(): eq_(Interval(5, 10).EnlargeTopTo(10), Interval(1, 10)) eq_(Interval(5, 10).EnlargeTopTo(11), Interval(1, 10)) eq_(Interval(10, 20).EnlargeTopTo(15), Interval(6, 20)) eq_(Interval(1, 10).EnlargeBottomTo(20), Interval(1, 20)) eq_(Interval(10, 20).MoveUpBy(5), Interval(5, 15)) eq_(Interval(11, 20).MoveUpBy(10), Interval(1, 10)) eq_(Interval(2, 10).MoveUpBy(5), Interval(1, 9)) eq_(Interval(1, 10).MoveDownBy(10), Interval(11, 20)) eq_(Interval(1, 5).LimitBottomBy(10), Interval(1, 5)) eq_(Interval(1, 5).LimitBottomBy(5), Interval(1, 5)) eq_(Interval(1, 10).LimitBottomBy(5), Interval(1, 5))
def Intersect_test(): eq_(Interval(10, 20) & Interval(1, 9), Interval.Empty()) eq_(Interval(10, 20) & Interval(21, 30), Interval.Empty()) eq_(Interval(10, 20) & Interval(20, 30), Interval(20, 20)) eq_(Interval(10, 20) & Interval(1, 10), Interval(10, 10)) eq_(Interval(10, 20) & Interval(1, 15), Interval(10, 15)) eq_(Interval(10, 20) & Interval(17, 25), Interval(17, 20)) eq_(Interval(10, 20) & Interval(1, 30), Interval(10, 20)) s = IntervalSet(Interval(5, 10), Interval(20, 25)) eq_(Interval(1, 4) & s, Interval.Empty()) eq_(Interval(7, 15) & s, Interval(7, 10)) eq_(Interval(23, 30) & s, Interval(23, 25)) eq_(Interval(26, 30) & s, Interval.Empty()) eq_(Interval(7, 25) & s, IntervalSet(Interval(7, 10), Interval(20, 25)))
def SubtractError_test(): IntervalSet( Interval( 1, 10 ) ) - IntervalSet( Interval( 2, 8 ) )
def Contains_test(): ok_(1 in Interval(1, 10)) ok_(10 in Interval(1, 10)) ok_(5 in Interval(1, 10)) ok_(0 not in Interval(1, 10)) ok_(11 not in Interval(1, 10)) ok_(Interval(10, 20) in Interval(10, 20)) ok_(Interval(12, 20) in Interval(10, 20)) ok_(Interval(10, 18) in Interval(10, 20)) ok_(Interval(12, 18) in Interval(10, 20)) ok_(Interval(1, 9) not in Interval(10, 20)) ok_(Interval(1, 10) not in Interval(10, 20)) ok_(Interval(9, 15) not in Interval(10, 20)) ok_(Interval(21, 30) not in Interval(10, 20)) ok_(Interval(20, 30) not in Interval(10, 20)) ok_(Interval(15, 21) not in Interval(10, 20)) ok_(Interval(5, 25) not in Interval(10, 20))
def String_test(): # 100% coverity baby eq_( "%s" % IntervalSet( Interval( 1, 10 ), Interval( 20, 30 ) ), "([1, 10], [20, 30])" )
def Operlap_test(): ok_(Interval(10, 20).Overlaps(Interval(10, 20))) ok_(Interval(10, 20).Overlaps(Interval(1, 10))) ok_(Interval(10, 20).Overlaps(Interval(1, 15))) ok_(Interval(10, 20).Overlaps(Interval(20, 30))) ok_(Interval(10, 20).Overlaps(Interval(17, 30))) ok_(Interval(10, 20).Overlaps(Interval(12, 18))) ok_(Interval(10, 20).Overlaps(Interval(5, 25)))
def Contains_test(): s = IntervalSet( Interval( 1, 10 ), Interval( 20, 30 ), Interval( 40, 50 ) ) ok_( Interval( 1, 10 ) in s ) ok_( Interval( 25, 27 ) in s ) ok_( Interval( 40, 48 ) in s ) ok_( Interval( 8, 11 ) not in s ) ok_( Interval( 11, 15 ) not in s ) ok_( Interval( 5, 25 ) not in s ) ok_( Interval( 25, 45 ) not in s ) ok_( Interval( 15, 35 ) not in s ) ok_( Interval( 0, 55 ) not in s ) ok_( 1 in s ) ok_( 30 in s ) ok_( 45 in s ) ok_( 0 not in s ) ok_( 11 not in s ) ok_( 35 not in s ) ok_( 39 not in s ) ok_( 55 not in s )
def Intersect_test(): s = IntervalSet() eq_( s & Interval( 1, 10 ), IntervalSet() ) s = IntervalSet( Interval( 1, 10 ), Interval( 20, 30 ), Interval( 40, 50 ) ) eq_( s & Interval( 11, 19 ), IntervalSet() ) eq_( s & Interval( 5, 15 ), IntervalSet( Interval( 5, 10 ) ) ) eq_( s & Interval( 5, 25 ), IntervalSet( Interval( 5, 10 ), Interval( 20, 25 ) ) ) eq_( s & Interval( 0, 51 ), s )
def Current(): return Interval(vimsupport.GetCurrentTopLine(), vimsupport.GetCurrentBottomLine())
def Subtract_test(): ok_(not (Interval(10, 20) - Interval(10, 20))) ok_(not (Interval(10, 20) - Interval(5, 25))) eq_(Interval(10, 20) - Interval(10, 20), Interval.Empty()) eq_(Interval(10, 20) - Interval(5, 25), Interval.Empty()) eq_(Interval(10, 20) - Interval(1, 10), Interval(11, 20)) eq_(Interval(10, 20) - Interval(1, 13), Interval(14, 20)) eq_(Interval(10, 20) - Interval(20, 30), Interval(10, 19)) eq_(Interval(10, 20) - Interval(16, 30), Interval(10, 15)) eq_( Interval(10, 20) - Interval(14, 17), IntervalSet(Interval(10, 13), Interval(18, 20))) eq_( Interval(1, 10) - IntervalSet(Interval(2, 3), Interval(5, 7)), IntervalSet(Interval(1, 1), Interval(4, 4), Interval(8, 10)))