forked from UCL-COMP0233-2022-2023/times-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_times.py
37 lines (29 loc) · 1.68 KB
/
test_times.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import times
from pytest import raises
def test_given_input():
large = times.time_range("2010-01-12 10:00:00", "2010-01-12 12:00:00")
short = times.time_range("2010-01-12 10:30:00", "2010-01-12 10:45:00", 2, 60)
result = times.compute_overlap_time(large, short)
expected = [('2010-01-12 10:30:00', '2010-01-12 10:37:00'), ('2010-01-12 10:38:00', '2010-01-12 10:45:00')]
assert result == expected
def test_several_intervals_empty_intersection():
large = times.time_range("2010-01-12 10:00:00", "2010-01-12 12:00:00")
short = times.time_range("2011-01-12 10:30:00", "2011-01-12 10:45:00", 2, 60)
result = times.compute_overlap_time(large, short)
expected = []
assert result == expected
def test_several_intervals_nonempty_intersections():
large = times.time_range("2010-01-12 10:00:00", "2010-01-12 12:00:00", 12, 15)
short = times.time_range("2010-01-12 10:30:00", "2010-01-12 10:45:00", 2, 60)
result = times.compute_overlap_time(large, short)
expected = [('2010-01-12 10:30:03', '2010-01-12 10:37:00'), ('2010-01-12 10:38:00', '2010-01-12 10:39:50'), ('2010-01-12 10:40:05', '2010-01-12 10:45:00')]
assert result == expected
def test_several_intervals_one_second_intersections():
large = times.time_range("2010-01-12 10:00:00", "2010-01-12 10:30:00", 12, 15)
short = times.time_range("2010-01-12 10:30:00", "2010-01-12 10:45:00", 2, 60)
result = times.compute_overlap_time(large, short)
expected = [('2010-01-12 10:30:00', '2010-01-12 10:30:00')]
assert result == expected
def test_invalid_date_order_raise_error():
with raises(ValueError):
times.time_range("2010-01-12 10:30:00", "2010-01-12 10:00:00", 12, 15)