def test_lookup(self):
        map = LinearIntervalMap()
        map.put(Interval.closed(1, 3), "one-three")
        map.put(Interval.closed(5, 9), "five-nine")
        map.put(Interval.open(9, 12), "ten-eleven")

        assert_that(map.contains_key(0), equal_to(False))
        assert_that(map.contains_key(1), equal_to(True))
        assert_that(map.contains_key(2), equal_to(True))
        assert_that(map.contains_key(3), equal_to(True))
        assert_that(map.contains_key(4), equal_to(False))
        assert_that(map.contains_key(5), equal_to(True))
        assert_that(map.contains_key(9), equal_to(True))
        assert_that(map.contains_key(11), equal_to(True))
        assert_that(map.contains_key(12), equal_to(False))
        assert_that(map.contains_key(13), equal_to(False))
        assert_that(map.contains_key(None), equal_to(False))

        assert_that(map.get(0), equal_to(None))
        assert_that(map.get(1), equal_to("one-three"))
        assert_that(map.get(2), equal_to("one-three"))
        assert_that(map.get(3), equal_to("one-three"))
        assert_that(map.get(4), equal_to(None))
        assert_that(map.get(5), equal_to("five-nine"))
        assert_that(map.get(9), equal_to("five-nine"))
        assert_that(map.get(10), equal_to("ten-eleven"))
        assert_that(map.get(11), equal_to("ten-eleven"))
        assert_that(map.get(12), equal_to(None))
        assert_that(map.get(13), equal_to(None))
        assert_that(map.get(None), equal_to(None))
Exemplo n.º 2
0
 def test_relative_complement_enclosed_open(self):
     o3_5o = Interval.open(3, 5)
     c1_7c = Interval.closed(1, 7)
     c1_3c = Interval.closed(1, 3)
     c5_7c = Interval.closed(5, 7)
     complement = o3_5o.complement_relative_to(c1_7c)
     assert_that(len(complement), equal_to(2))
     assert_that(complement[0], equal_to(c1_3c))
     assert_that(complement[1], equal_to(c5_7c))
Exemplo n.º 3
0
    def test_gap(self):
        c1_3c = Interval.closed(1, 3)
        c5_7c = Interval.closed(5, 7)
        o3_5o = Interval.open(3, 5)
        c2_3o = Interval.over(2, True, 3, False)

        assert_that(o3_5o, equal_to(c1_3c.gap(c5_7c)))
        assert_that(c1_3c.gap(o3_5o).is_empty(), equal_to(True))
        assert_that(c1_3c.gap(c2_3o).is_empty(), equal_to(True))
        assert_that(c2_3o.gap(o3_5o).is_single_element(), equal_to(True))
Exemplo n.º 4
0
 def setUpClass(cls):
     cls.empty = Interval.open(Decimal(1), Decimal(1))
     cls.c5_10c = Interval.closed(Decimal(5), Decimal(10))
     cls.c1_10c = Interval.closed(Decimal(1), Decimal(10))
     cls.c4_6c = Interval.closed(Decimal(4), Decimal(6))
     cls.c5_15c = Interval.closed(Decimal(5), Decimal(15))
     cls.c12_16c = Interval.closed(Decimal(12), Decimal(16))
     cls.o10_12c = Interval.over(Decimal(10), False, Decimal(12), True)
     cls.o1_1c = Interval.over(Decimal(1), False, Decimal(1), True)
     cls.c1_1o = Interval.over(Decimal(1), True, Decimal(1), False)
     cls.c1_1c = Interval.over(Decimal(1), True, Decimal(1), True)
     cls.o1_1o = Interval.over(Decimal(1), False, Decimal(1), False)
    def test_construction_overwrite_overlap(self):
        map = LinearIntervalMap()
        map.put(Interval.closed(1, 2), "one-three")
        map.put(Interval.closed(5, 9), "five-nine")
        map.put(Interval.open(9, 12), "ten-eleven")
        assert_that(map.get(10), equal_to("ten-eleven"))
        assert_that(map.get(11), equal_to("ten-eleven"))
        assert_that(map.get(12), equal_to(None))

        eleven_thirteen = Interval.closed(11, 13)
        assert_that(map.contains_intersecting_key(eleven_thirteen),
                    equal_to(True))
        map.put(eleven_thirteen, "eleven-thirteen")
        assert_that(map.get(10), equal_to("ten-eleven"))
        assert_that(map.get(11), equal_to("eleven-thirteen"))
        assert_that(map.get(12), equal_to("eleven-thirteen"))
    def test_construction_overwrite_middle(self):
        map = LinearIntervalMap()
        map.put(Interval.closed(1, 3), "one-three")
        map.put(Interval.closed(5, 9), "five-nine")
        map.put(Interval.open(9, 12), "ten-eleven")
        assert_that(map.get(6), equal_to("five-nine"))
        assert_that(map.get(7), equal_to("five-nine"))
        assert_that(map.get(8), equal_to("five-nine"))
        assert_that(map.get(9), equal_to("five-nine"))

        seven_eight = Interval.closed(7, 8)
        assert_that(map.contains_intersecting_key(seven_eight), equal_to(True))
        map.put(seven_eight, "seven-eight")
        assert_that(map.get(6), equal_to("five-nine"))
        assert_that(map.get(7), equal_to("seven-eight"))
        assert_that(map.get(8), equal_to("seven-eight"))
        assert_that(map.get(9), equal_to("five-nine"))
Exemplo n.º 7
0
 def test_is_empty(self):
     assert_that(Interval.closed(5, 6).is_empty(), equal_to(False))
     assert_that(Interval.closed(6, 6).is_empty(), equal_to(False))
     assert_that(Interval.open(6, 6).is_empty(), equal_to(True))
     assert_that(self.c1_10c.empty_of_same_type().is_empty(),
                 equal_to(True))
Exemplo n.º 8
0
 def test_relative_complement_enclosed_end_point(self):
     o3_5o = Interval.open(3, 5)
     c3_5c = Interval.closed(3, 5)
     complement = o3_5o.complement_relative_to(c3_5c)
     assert_that(len(complement), equal_to(2))
     assert_that(complement[0].includes(3), equal_to(True))