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(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 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_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_open_interval(self):
     exRange = Interval.over(Decimal(-5.5), False, Decimal(6.6), True)
     assert_that(exRange.includes(Decimal(5.0)), equal_to(True))
     assert_that(exRange.includes(Decimal(-5.5)), equal_to(False))
     assert_that(exRange.includes(Decimal(-5.4999)), equal_to(True))
     assert_that(exRange.includes(Decimal(6.6)), equal_to(True))
     assert_that(exRange.includes(Decimal(6.601)), equal_to(False))
     assert_that(exRange.includes(Decimal(-5.501)), equal_to(False))
    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 test_covers_interval(self):
     assert_that(self.c5_10c.covers(self.c1_10c), equal_to(False))
     assert_that(self.c1_10c.covers(self.c5_10c), equal_to(True))
     assert_that(self.c4_6c.covers(self.c1_10c), equal_to(False))
     assert_that(self.c1_10c.covers(self.c4_6c), equal_to(True))
     assert_that(self.c5_10c.covers(self.c5_10c), equal_to(True))
     half_open5_10 = Interval.over(Decimal(5), False, Decimal(10), True)
     assert_that(self.c5_10c.covers(half_open5_10), equal_to(True),
                 "closed incl left-open")
     assert_that(half_open5_10.covers(half_open5_10), equal_to(True),
                 "left-open incl left-open")
     assert_that(half_open5_10.covers(self.c5_10c), equal_to(False),
                 "left-open doesn't include closed")
     half_closed5_10 = Interval.over(Decimal(5), True, Decimal(10), False)
     assert_that(self.c5_10c.covers(half_closed5_10), equal_to(True),
                 "closed incl right-open")
     assert_that(half_closed5_10.covers(half_closed5_10), equal_to(True),
                 "right-open incl right-open")
     assert_that(half_closed5_10.covers(self.c5_10c), equal_to(False),
                 "right-open doesn't include closed")
 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))