예제 #1
0
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)))
예제 #2
0
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)))
예제 #3
0
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 ) ) )
예제 #4
0
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)))
예제 #5
0
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 )
예제 #6
0
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 )
예제 #7
0
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 ) ) )
예제 #8
0
def Construction_test():
    eq_( IntervalSet( Interval( 1, 10 ), Interval( 20, 30 ) ),
         IntervalSet( Interval( 20, 30 ), Interval( 1, 10 ) ) )
예제 #9
0
def String_test():
    # 100% coverity baby
    eq_( "%s" % IntervalSet( Interval( 1, 10 ), Interval( 20, 30 ) ),
         "([1, 10], [20, 30])" )
예제 #10
0
def SubtractError_test():
    IntervalSet( Interval( 1, 10 ) ) - IntervalSet( Interval( 2, 8 ) )
예제 #11
0
def IntersectError_test():
    IntervalSet( Interval( 2, 8 ) ) & IntervalSet( Interval( 1, 10 ) )
예제 #12
0
def ContainsError_test():
    IntervalSet( Interval( 2, 8 ) ) in IntervalSet( Interval( 1, 10 ) )
예제 #13
0
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 ) ) )