Example #1
0
    def test_ivl_overlap_change_schedule(self):
        clnd = tb_12_days()
        my_schedule = clnd.add_schedule('my_schedule', lambda x: True)
        my_schedule_2 = clnd.add_schedule('my_schedule_2', lambda x: True)

        ivl = Interval(clnd, (2, 8), schedule=my_schedule)
        other = Interval(clnd, (6, 12))
        overlap = ivl.overlap(other)
        assert overlap._loc == (6, 8)
        assert overlap.schedule.name == 'my_schedule'

        ivl = Interval(clnd, (2, 8))
        other = Interval(clnd, (6, 12), schedule=my_schedule)
        overlap = ivl.overlap(other)
        assert overlap._loc == (6, 8)
        assert overlap.schedule.name == clnd.default_schedule.name

        ivl = Interval(clnd, (2, 8), schedule=my_schedule)
        other = Interval(clnd, (6, 12))
        overlap = ivl.overlap(other, schedule=my_schedule_2)
        assert overlap._loc == (6, 8)
        assert overlap.schedule.name == 'my_schedule_2'

        ivl = Interval(clnd, (2, 8), schedule=my_schedule)
        other = Interval(clnd, (10, 12))
        overlap = ivl.overlap(other)
        assert isinstance(overlap, _VoidInterval)
        assert overlap.schedule.name == 'my_schedule'
Example #2
0
    def test_ivl_overlap_one(self):
        clnd = tb_12_days()
        ivl = Interval(clnd, (2, 8))
        other = Interval(clnd, (1, 2))
        overlap = ivl.overlap(other)
        assert overlap._loc == (2, 2)
        assert len(overlap) == 1

        other = Interval(clnd, (2, 2))
        overlap = ivl.overlap(other)
        assert overlap._loc == (2, 2)
        assert len(overlap) == 1
Example #3
0
    def test_ivl_overlap_partial(self):
        clnd = tb_12_days()
        ivl = Interval(clnd, (2, 8))
        other = Interval(clnd, (6, 12))
        overlap = ivl.overlap(other)
        assert overlap._loc == (6, 8)
        assert len(overlap) == 3

        other = Interval(clnd, (1, 3))
        overlap = ivl.overlap(other)
        assert overlap._loc == (2, 3)
        assert len(overlap) == 2
Example #4
0
 def test_ivl_overlap_within(self):
     clnd = tb_12_days()
     ivl = Interval(clnd, (2, 8))
     other = Interval(clnd, (3, 7))
     overlap = ivl.overlap(other)
     assert overlap._loc == (3, 7)
     assert len(overlap) == 5
Example #5
0
 def test_ivl_overlap_total(self):
     clnd = tb_12_days()
     ivl = Interval(clnd, (2, 8))
     other = Interval(clnd, (0, 12))
     overlap = ivl.overlap(other)
     assert overlap._loc == (2, 8)
     assert len(overlap) == 7
Example #6
0
    def test_ivl_overlap_void(self):
        clnd = tb_12_days()
        ivl = Interval(clnd, (2, 8))
        other = Interval(clnd, (9, 10))
        overlap = ivl.overlap(other)
        assert overlap._loc == (9, 8)
        assert len(overlap) == 0
        assert isinstance(overlap, _VoidInterval)

        other = Interval(clnd, (1, 1))
        overlap = ivl.overlap(other)
        assert overlap._loc == (2, 1)
        assert len(overlap) == 0
        assert isinstance(overlap, _VoidInterval)

        overlap_with_void = ivl.overlap(overlap)
        assert overlap_with_void._loc == (2, 1)
        assert len(overlap_with_void) == 0
        assert isinstance(overlap_with_void, _VoidInterval)
Example #7
0
 def test_ivl_overlap_with_self(self):
     clnd = tb_12_days()
     ivl = Interval(clnd, (2, 8))
     overlap = ivl.overlap(ivl)
     assert overlap._loc == (2, 8)
     assert len(overlap) == 7