Skip to content

Commit

Permalink
cleanest solution
Browse files Browse the repository at this point in the history
  • Loading branch information
ucapgum committed Nov 6, 2020
1 parent fd87e4d commit 751dc4c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 13 deletions.
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pytest
pytest-cov
codecov
codecov
pyyaml
28 changes: 28 additions & 0 deletions week05-testing/fixture.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
generic:
interval1: time_range("2010-01-12 10:00:00", "2010-01-12 12:00:00")
interval2: time_range("2010-01-12 10:30:00", "2010-01-12 10:45:00", 2, 60)
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')

no_overlap:
interval1: time_range("2010-01-12 10:00:00", "2010-01-12 11:00:00")
interval2: time_range("2010-01-12 12:00:00", "2010-01-12 13:00:00")
expected: []

no_overlap_reversed:
interval1: time_range("2010-01-12 12:00:00", "2010-01-12 13:00:00")
interval2: time_range("2010-01-12 10:00:00", "2010-01-12 11:00:00")
expected: []

multiple_intervals:
interval1: time_range("2010-01-12 10:00:00", "2010-01-12 12:00:00", 2, 60)
interval2: time_range("2010-01-12 11:00:00", "2010-01-12 13:00:00", 2, 60)
expected:
- ("2010-01-12 11:00:30", "2010-01-12 11:59:30")

same_end:
interval1: time_range("2010-01-12 10:00:00", "2010-01-12 11:00:00")
interval2: time_range("2010-01-12 11:00:00", "2010-01-12 13:00:00")
expected: []

19 changes: 7 additions & 12 deletions week05-testing/test_times.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
import pytest
import yaml
from times import compute_overlap_time, time_range

inputs = []
inputs.append([time_range("2010-01-12 10:00:00", "2010-01-12 12:00:00"), time_range("2010-01-12 10:30:00", "2010-01-12 10:45:00", 2, 60), \
[('2010-01-12 10:30:00', '2010-01-12 10:37:00'), ('2010-01-12 10:38:00', '2010-01-12 10:45:00')]])
inputs.append([time_range("2010-01-12 10:00:00", "2010-01-12 11:00:00"), time_range("2010-01-12 12:00:00", "2010-01-12 13:00:00"), []])
inputs.append([time_range("2010-01-12 10:00:00", "2010-01-12 11:00:00"), time_range("2010-01-12 12:00:00", "2010-01-12 13:00:00"), []])
inputs.append([time_range("2010-01-12 10:00:00", "2010-01-12 12:00:00", 2, 60), time_range("2010-01-12 11:00:00", "2010-01-12 13:00:00", 2, 60), \
[("2010-01-12 11:00:30", "2010-01-12 11:59:30")]])
inputs.append([time_range("2010-01-12 10:00:00", "2010-01-12 11:00:00"), time_range("2010-01-12 11:00:00", "2010-01-12 13:00:00"), []])
with open('week05-testing/fixture.yaml') as f:
inputs = yaml.load(f, Loader=yaml.FullLoader)

@pytest.mark.parametrize("interval1, interval2, expected", inputs)
@pytest.mark.parametrize("interval1, interval2, expected", [x.values() for x in inputs.values()], ids=inputs.keys())
def test_input(interval1, interval2, expected):
result = compute_overlap_time(interval1, interval2)
assert result == expected
result = compute_overlap_time(eval(interval1), eval(interval2))
assert result == list(map(eval, expected))

def test_backwards_date():
with pytest.raises(ValueError):
interval = time_range("2010-01-12 11:00:00", "2010-01-12 10:00:00")
time_range("2010-01-12 11:00:00", "2010-01-12 10:00:00")

0 comments on commit 751dc4c

Please sign in to comment.