Browse Source

test: test Interval.overlaps()

main
Rob Hallam 2 months ago
parent
commit
4cf406935b
1 changed files with 16 additions and 0 deletions
  1. +16
    -0
      test/test_utils.py

+ 16
- 0
test/test_utils.py View File

@@ -225,6 +225,22 @@ class TestInterval(unittest.TestCase):
interval.update_duration(5, relative=True) interval.update_duration(5, relative=True)
self.assertEqual(interval.start, 0) self.assertEqual(interval.start, 0)


def test_overlaps(self):
"""Test the overlaps method - returns True if the interval overlaps with another interval"""
interval1 = utils.Interval(start=0, end=10)
interval2 = utils.Interval(start=5, end=15) # overlaps with interval1
interval3 = utils.Interval(start=15, end=20) # does not overlap with interval1
interval4 = utils.Interval(start=10, end=15) # touch overlap with interval1
# test with overlapping interval
self.assertTrue(interval1.overlaps(interval2))
self.assertTrue(interval2.overlaps(interval1))
# test with non-overlapping interval
self.assertFalse(interval1.overlaps(interval3))
self.assertFalse(interval3.overlaps(interval1))
# test with touching interval
self.assertTrue(interval1.overlaps(interval4))
self.assertTrue(interval4.overlaps(interval1))

# Unhappy path tests # Unhappy path tests


def test_init_no_start_end(self): def test_init_no_start_end(self):


Loading…
Cancel
Save