Skip to content

Commit

Permalink
parametrize answer UCL-RITS#89
Browse files Browse the repository at this point in the history
  • Loading branch information
umitozmen committed Nov 6, 2020
1 parent 5935677 commit 8f7b257
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 55 deletions.
Binary file modified week05-testing/__pycache__/test_times.cpython-38-pytest-6.1.2.pyc
Binary file not shown.
Binary file modified week05-testing/__pycache__/times.cpython-38.pyc
Binary file not shown.
73 changes: 21 additions & 52 deletions week05-testing/test_times.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
from times import time_range ,compute_overlap_time
from pytest import raises
from times import time_range ,compute_overlap_time, compute_overlap_helper
import pytest

testdata = [[('2010-01-12 10:30:00', '2010-01-12 10:37:00'),('2010-01-12 10:38:00', '2010-01-12 12:20:00'),tuple()] #test_no_overlap_helper
,(('2010-01-12 10:30:00', '2010-01-12 10:37:00'),('2010-01-12 10:30:00', '2010-01-12 10:35:00'),('2010-01-12 10:30:00', '2010-01-12 10:35:00')) #test_inside_edge_overlap_helper
,(('2010-01-12 10:30:00', '2010-01-12 10:37:00'),('2010-01-12 10:30:00', '2010-01-12 10:37:00'),('2010-01-12 10:30:00', '2010-01-12 10:37:00')) #test_same_overlap_helper
,(('2010-01-12 10:30:00', '2010-01-12 10:37:00'),('2010-01-12 10:37:00', '2010-01-12 10:39:00'),tuple()) #test_outside_edge_overlap_helper
,(('2010-01-12 10:30:00', '2010-01-12 10:37:00'),('2010-01-12 10:34:00', '2010-01-12 10:42:00'),('2010-01-12 10:34:00', '2010-01-12 10:37:00')) #test_partial_overlap_helper
,(('2010-01-12 10:30:00', '2010-01-12 10:37:00'),('2010-01-12 10:32:00', '2010-01-12 10:36:30'),('2010-01-12 10:32:00', '2010-01-12 10:36:30'))#test_subset_overlap_helper
]

@pytest.mark.parametrize(
"time_range1,time_range2,expected",testdata
)

def test_eval(time_range1,time_range2,expected):
assert compute_overlap_helper(time_range1,time_range2) == expected

def test_given_input():

Expand All @@ -9,62 +24,16 @@ def test_given_input():
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')]
assert result == expected

def test_no_overlap_helper():
assert(
times.compute_overlap_helper(
('2010-01-12 10:30:00', '2010-01-12 10:37:00'),
('2010-01-12 10:38:00', '2010-01-12 12:20:00')
)
== tuple()
)

def test_inside_edge_overlap_helper():
assert(
times.compute_overlap_helper(
('2010-01-12 10:30:00', '2010-01-12 10:37:00'),
('2010-01-12 10:30:00', '2010-01-12 10:35:00')
)
== ('2010-01-12 10:30:00', '2010-01-12 10:35:00')
)


def test_same_overlap_helper():
assert(
times.compute_overlap_helper(
('2010-01-12 10:30:00', '2010-01-12 10:37:00'),
('2010-01-12 10:30:00', '2010-01-12 10:37:00')
)
== ('2010-01-12 10:30:00', '2010-01-12 10:37:00')
)

def test_outside_edge_overlap_helper():
assert(
times.compute_overlap_helper(
('2010-01-12 10:30:00', '2010-01-12 10:37:00'),
('2010-01-12 10:37:00', '2010-01-12 10:39:00')
)
== tuple()
)

def test_partial_overlap_helper():
assert(
times.compute_overlap_helper(
('2010-01-12 10:30:00', '2010-01-12 10:37:00'),
('2010-01-12 10:34:00', '2010-01-12 10:42:00')
)
== ('2010-01-12 10:34:00', '2010-01-12 10:37:00')
)

"""
def test_subset_overlap_helper():
assert(
times.compute_overlap_helper(
compute_overlap_helper(
('2010-01-12 10:30:00', '2010-01-12 10:37:00'),
('2010-01-12 10:32:00', '2010-01-12 10:36:30')
)
== ('2010-01-12 10:32:00', '2010-01-12 10:36:30')
)
"""
def test_negative():
with raises(ValueError):
with pytest.raises(ValueError):
time_range("2010-01-12 12:00:00", "2010-01-12 10:00:00")
7 changes: 4 additions & 3 deletions week05-testing/times.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import datetime


import datetime

def time_range(start_time, end_time, number_of_intervals=1, gap_between_intervals_s=0):
start_time_s = datetime.datetime.strptime(start_time, "%Y-%m-%d %H:%M:%S")
end_time_s = datetime.datetime.strptime(end_time, "%Y-%m-%d %H:%M:%S")

if start_time_s > end_time_s:
raise ValueError("Start time is later than end time")

d = (end_time_s - start_time_s).total_seconds() / number_of_intervals + gap_between_intervals_s * (1 / number_of_intervals - 1)
sec_range = [(start_time_s + datetime.timedelta(seconds=i * d + i * gap_between_intervals_s),
start_time_s + datetime.timedelta(seconds=(i + 1) * d + i * gap_between_intervals_s))
Expand Down

0 comments on commit 8f7b257

Please sign in to comment.