|
|
@@ -155,6 +155,11 @@ class TestInterval(unittest.TestCase): |
|
|
|
self.assertTrue(interval3 > interval2) # interval3 start is larger |
|
|
|
self.assertTrue(interval3 < interval4) # same start, interval3 has smaller end |
|
|
|
|
|
|
|
def test_to_json(self): |
|
|
|
"""Test to_json method""" |
|
|
|
interval = utils.Interval(start=self.start, end=self.end) |
|
|
|
self.assertEqual(interval.to_json(), {"start": self.start, "end": self.end, "duration": self.duration}) |
|
|
|
|
|
|
|
def test_move_start(self): |
|
|
|
"""Test the move_start method - changes start time to time specified, keeps end time constant""" |
|
|
|
interval = utils.Interval(start=self.start, end=self.end) |
|
|
@@ -171,6 +176,44 @@ class TestInterval(unittest.TestCase): |
|
|
|
self.assertEqual(interval.end, 10) |
|
|
|
self.assertEqual(interval.duration, 8) |
|
|
|
|
|
|
|
def test_move_end(self): |
|
|
|
"""Test the move_end method - changes end time to time specified, keeps start time constant""" |
|
|
|
interval = utils.Interval(start=self.start, end=self.end) |
|
|
|
interval.move_end(15) |
|
|
|
self.assertEqual(interval.start, 0) |
|
|
|
self.assertEqual(interval.end, 15) |
|
|
|
self.assertEqual(interval.duration, 15) |
|
|
|
|
|
|
|
def test_update_duration(self): |
|
|
|
"""Test the update_duration method - changes duration to time specified, keeps start time constant""" |
|
|
|
interval = utils.Interval(start=self.start, end=self.end) |
|
|
|
interval.update_duration(15) |
|
|
|
self.assertEqual(interval.start, 0) |
|
|
|
self.assertEqual(interval.end, 15) |
|
|
|
self.assertEqual(interval.duration, 15) |
|
|
|
# test with relative=True |
|
|
|
interval.update_duration(5, relative=True) |
|
|
|
self.assertEqual(interval.start, 0) |
|
|
|
|
|
|
|
# Unhappy path tests |
|
|
|
|
|
|
|
def test_init_no_start_end(self): |
|
|
|
with self.assertRaises(ValueError): |
|
|
|
utils.Interval() |
|
|
|
|
|
|
|
def test_init_start_end_duration(self): |
|
|
|
with self.assertRaises(ValueError): |
|
|
|
utils.Interval(start=self.start, end=self.end, duration=self.duration) |
|
|
|
|
|
|
|
def test_init_start_after_end(self): |
|
|
|
with self.assertRaises(ValueError): |
|
|
|
utils.Interval(start=10, end=0) |
|
|
|
|
|
|
|
def test_init_negative_duration(self): |
|
|
|
with self.assertRaises(ValueError): |
|
|
|
utils.Interval(start=0, duration=-10) |
|
|
|
with self.assertRaises(ValueError): |
|
|
|
utils.Interval(end=0, duration=-10) |
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
|