def test_relative_complement_overlap_right(self):
     c1_5c = Interval.closed(1, 5)
     c3_7c = Interval.closed(3, 7)
     complement = c1_5c.complement_relative_to(c3_7c)
     o5_7c = Interval.over(5, False, 7, True)
     assert_that(len(complement), equal_to(1))
     assert_that(complement[0], equal_to(o5_7c))
 def test_relative_complement_overlap_left(self):
     c1_5c = Interval.closed(1, 5)
     c3_7c = Interval.closed(3, 7)
     complement = c3_7c.complement_relative_to(c1_5c)
     c1_3o = Interval.over(1, True, 3, False)
     assert_that(len(complement), equal_to(1))
     assert_that(complement[0], equal_to(c1_3o))
    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))
 def setUpClass(cls):
     cls.c5_10c = Interval.closed(Decimal(5), Decimal(10))
     cls.o10_12c = Interval.over(Decimal(10), False, Decimal(12), True)
     cls.o11_20c = Interval.over(Decimal(11), False, Decimal(20), True)
     cls.o12_20o = Interval.over(Decimal(12), False, Decimal(20), False)
     cls.c20_25c = Interval.closed(Decimal(20), Decimal(25))
     cls.o25_30c = Interval.over(Decimal(25), False, Decimal(30), True)
     cls.o30_35o = Interval.over(Decimal(30), False, Decimal(35), False)
 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))
 def test_remove(self):
     map = LinearIntervalMap()
     map.put(Interval.closed(1, 10), "one-ten")
     map.remove(Interval.closed(3, 5))
     assert_that(map.get(2), equal_to("one-ten"))
     assert_that(map.get(3), equal_to(None))
     assert_that(map.get(4), equal_to(None))
     assert_that(map.get(5), equal_to(None))
     assert_that(map.get(6), equal_to("one-ten"))
 def test_relative_complement_enclosed(self):
     c3_5c = Interval.closed(3, 5)
     c1_7c = Interval.closed(1, 7)
     c1_3o = Interval.over(1, True, 3, False)
     o5_7c = Interval.over(5, False, 7, True)
     complement = c3_5c.complement_relative_to(c1_7c)
     assert_that(len(complement), equal_to(2))
     assert_that(complement[0], equal_to(c1_3o))
     assert_that(complement[1], equal_to(o5_7c))
    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))
 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_multiple(self):
     map = LinearIntervalMap()
     map.put(Interval.closed(1, 2), "one-two")
     map.put(Interval.closed(3, 4), "three-four")
     map.put(Interval.closed(5, 6), "five-six")
     map.put(Interval.closed(8, 9), "eight-nine")
     map.put(Interval.closed(3, 8), "three-eight")
     assert_that(map.get(2), equal_to("one-two"))
     assert_that(map.get(3), equal_to("three-eight"))
     assert_that(map.get(4), equal_to("three-eight"))
     assert_that(map.get(5), equal_to("three-eight"))
     assert_that(map.get(6), equal_to("three-eight"))
     assert_that(map.get(7), equal_to("three-eight"))
     assert_that(map.get(8), equal_to("three-eight"))
     assert_that(map.get(9), equal_to("eight-nine"))
    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"))
Esempio n. 13
0
 def testIncludes(self):
     range = Interval.closed(Decimal(-5.5), Decimal(6.6))
     assert_that(range.includes(Decimal(5.0)), equal_to(True))
     assert_that(range.includes(Decimal(-5.5)), equal_to(True))
     assert_that(range.includes(Decimal(-5.4999)), equal_to(True))
     assert_that(range.includes(Decimal(6.6)), equal_to(True))
     assert_that(range.includes(Decimal(6.601)), equal_to(False))
     assert_that(range.includes(Decimal(-5.501)), equal_to(False))
Esempio n. 14
0
 def test_relative_complement_disjoint_adjacent_open(self):
     c1_3o = Interval.over(1, True, 3, False)
     c3_7c = Interval.closed(3, 7)
     complement = c1_3o.complement_relative_to(c3_7c)
     assert_that(len(complement), equal_to(1))
     assert_that(complement[0], equal_to(c3_7c))
Esempio n. 15
0
 def test_relative_complement_adjacent_closed(self):
     c1_3c = Interval.closed(1, 3)
     c5_7c = Interval.closed(5, 7)
     complement = c1_3c.complement_relative_to(c5_7c)
     assert_that(len(complement), equal_to(1))
     assert_that(complement[0], equal_to(c5_7c))
Esempio n. 16
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))
Esempio n. 17
0
 def test_relative_complement_enclosing(self):
     c3_5c = Interval.closed(3, 5)
     c1_7c = Interval.closed(1, 7)
     complement = c1_7c.complement_relative_to(c3_5c)
     assert_that(len(complement), equal_to(0))
Esempio n. 18
0
 def test_relative_complement_equal(self):
     c1_7c = Interval.closed(1, 7)
     complement = c1_7c.complement_relative_to(c1_7c)
     assert_that(len(complement), equal_to(0))
Esempio n. 19
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))
 def test_extent(self):
     interval_sequence = IntervalSequence()
     interval_sequence.add(self.c5_10c)
     interval_sequence.add(self.o10_12c)
     interval_sequence.add(self.c20_25c)
     assert_that(Interval.closed(5, 25), interval_sequence.extent())