forked from UCL-RITS/rse-classwork-2020
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid code repetition in the tests UCL-RITS#89
- Loading branch information
Aixi
committed
Nov 5, 2020
1 parent
db8893b
commit f2df2e9
Showing
4 changed files
with
30 additions
and
19 deletions.
There are no files selected for viewing
Binary file modified
BIN
-145 Bytes
(95%)
week05-testing/__pycache__/test_times.cpython-38-pytest-5.4.3.pyc
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,45 @@ | ||
from times import time_range, compute_overlap_time | ||
from pytest import raises | ||
import pytest | ||
|
||
def test_given_input(): | ||
large = time_range("2010-01-12 10:00:00", "2010-01-12 12:00:00") | ||
short = time_range("2010-01-12 10:30:00", "2010-01-12 10:45:00", 2, 60) | ||
@pytest.mark.parametrize("large, short, expected", | ||
[(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')]) | ||
, (time_range("2010-01-12 11:00:00", "2010-01-12 12:00:00"), time_range("2010-01-12 10:30:00", "2010-01-12 10:45:00"), []) | ||
, (time_range("2010-01-12 10:00:00", "2010-01-12 13:00:00", 2, 0), time_range("2010-01-12 11:00:00", "2010-01-12 12:00:00", 2, 0), [('2010-01-12 11:00:00', '2010-01-12 11:30:00'), ('2010-01-12 11:30:00', '2010-01-12 12:00:00')]) | ||
,(time_range("2010-01-12 10:00:00", "2010-01-12 13:00:00", 2, 0), time_range("2010-01-12 13:00:00", "2010-01-12 14:00:00", 2, 0), []) | ||
,(time_range("2010-01-12 13:00:00", "2010-01-12 12:00:00", 4, 60), time_range("2010-01-12 14:30:00", "2010-01-12 12:00:00", 2, 60), []) | ||
]) | ||
|
||
def test_given_input(large, short,expected): | ||
# large = time_range("2010-01-12 10:00:00", "2010-01-12 12:00:00") | ||
# short = time_range("2010-01-12 10:30:00", "2010-01-12 10:45:00", 2, 60) | ||
result = 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')] | ||
# 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_no_overlap(): | ||
large = time_range("2010-01-12 11:00:00", "2010-01-12 12:00:00") | ||
short = time_range("2010-01-12 10:30:00", "2010-01-12 10:45:00") | ||
def test_no_overlap(large, short,expected): | ||
# large = time_range("2010-01-12 11:00:00", "2010-01-12 12:00:00") | ||
# short = time_range("2010-01-12 10:30:00", "2010-01-12 10:45:00") | ||
result = compute_overlap_time(large, short) | ||
expected = [] | ||
# expected = [] | ||
assert result == expected | ||
|
||
def test_contain_intervals(): | ||
large = time_range("2010-01-12 10:00:00", "2010-01-12 13:00:00", 2, 0) | ||
short = time_range("2010-01-12 11:00:00", "2010-01-12 12:00:00", 2, 0) | ||
def test_contain_intervals(large, short,expected): | ||
# large = time_range("2010-01-12 10:00:00", "2010-01-12 13:00:00", 2, 0) | ||
# short = time_range("2010-01-12 11:00:00", "2010-01-12 12:00:00", 2, 0) | ||
result = compute_overlap_time(large, short) | ||
expected = [('2010-01-12 11:00:00', '2010-01-12 11:30:00'), ('2010-01-12 11:30:00', '2010-01-12 12:00:00')] | ||
# expected = [('2010-01-12 11:00:00', '2010-01-12 11:30:00'), ('2010-01-12 11:30:00', '2010-01-12 12:00:00')] | ||
assert result == expected | ||
|
||
def test_touching_times(): | ||
large = time_range("2010-01-12 10:00:00", "2010-01-12 13:00:00", 2, 0) | ||
short = time_range("2010-01-12 13:00:00", "2010-01-12 14:00:00", 2, 0) | ||
def test_touching_times(large, short,expected): | ||
# large = time_range("2010-01-12 10:00:00", "2010-01-12 13:00:00", 2, 0) | ||
# short = time_range("2010-01-12 13:00:00", "2010-01-12 14:00:00", 2, 0) | ||
result = compute_overlap_time(large, short) | ||
expected = [] | ||
# expected = [] | ||
assert result == expected | ||
|
||
def test_backfoward_date(): | ||
large = time_range("2010-01-12 13:00:00", "2010-01-12 12:00:00", 4, 60) | ||
short = time_range("2010-01-12 14:30:00", "2010-01-12 12:00:00", 2, 60) | ||
def test_backfoward_date(large,short,expected): | ||
# large = time_range("2010-01-12 13:00:00", "2010-01-12 12:00:00", 4, 60) | ||
# short = time_range("2010-01-12 14:30:00", "2010-01-12 12:00:00", 2, 60) | ||
with raises(ValueError): | ||
compute_overlap_time(large, short) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters