-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.py
124 lines (113 loc) · 6.16 KB
/
tests.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import datetime
import unittest
from main import Event, Interviewer
class InterviewerTests(unittest.TestCase):
def test_successfully_add_meetings(self):
"""
Create two interviewers.
Book some interviews with the interviewers.
All booked interviews should be successfully booked.
"""
andy = Interviewer(work_start=datetime.time(hour=8, minute=0, second=0),
work_end=datetime.time(hour=16, minute=0, second=0))
brook = Interviewer(work_start=datetime.time(hour=10, minute=0, second=0),
work_end=datetime.time(hour=18, minute=35, second=0))
andy.book(datetime.datetime(year=2020, month=3, day=14, hour=10, minute=0, second=0),
datetime.timedelta(seconds=3599))
brook.book(datetime.datetime(year=2020, month=3, day=14, hour=10, minute=0, second=0),
datetime.timedelta(seconds=3599))
andy.book(datetime.datetime(year=2020, month=3, day=14, hour=11, minute=0, second=0),
datetime.timedelta(seconds=1800))
andy.book(datetime.datetime(year=2020, month=3, day=14, hour=15, minute=9, second=26),
datetime.timedelta(seconds=1))
brook.book(datetime.datetime(year=2020, month=2, day=7, hour=18, minute=28, second=18),
datetime.timedelta(seconds=28))
# Book an interview to be at the same time of day as an already booked interview,
# but on a different day.
andy.book(datetime.datetime(year=2020, month=3, day=1, hour=10, minute=0, second=0),
datetime.timedelta(seconds=3599))
self.assertEqual(len(andy.booked_events), 4)
self.assertEqual(len(brook.booked_events), 2)
def test_meeting_too_early(self):
""" Attempt to book an interview which starts before the working day of the interviewer starts. """
cameron = Interviewer(work_start=datetime.time(hour=9, minute=15, second=0),
work_end=datetime.time(hour=17, minute=45, second=0))
with self.assertRaises(AssertionError):
cameron.book(datetime.datetime(year=2000, month=1, day=2, hour=3, minute=4, second=5),
datetime.timedelta(seconds=12345))
self.assertEqual(len(cameron.booked_events), 0)
def test_meeting_too_late(self):
""" Attempt to book an interview which ends after the working day of the interviewer ends. """
danny = Interviewer(work_start=datetime.time(hour=9, minute=25, second=18),
work_end=datetime.time(hour=17, minute=38, second=42))
with self.assertRaises(AssertionError):
danny.book(datetime.datetime(year=2098, month=7, day=6, hour=17),
datetime.timedelta(seconds=3600))
self.assertEqual(len(danny.booked_events), 0)
def test_meeting_overlap_first_before_second(self):
"""
Attempt to book two overlapping interviews
First |----------|
Second |----------|
"""
ed = Interviewer(work_start=datetime.time(hour=13),
work_end=datetime.time(hour=18))
ed.book(datetime.datetime(year=2020, month=10, day=27, hour=14),
datetime.timedelta(seconds=3600))
with self.assertRaises(AssertionError):
ed.book(datetime.datetime(year=2020, month=10, day=27, hour=14),
datetime.timedelta(seconds=3600))
self.assertEqual(len(ed.booked_events), 1)
def test_meeting_overlap_first_after_second(self):
"""
Attempt to book two overlapping interviews
First |----------|
Second |----------|
"""
lisa = Interviewer(work_start=datetime.time(hour=8, minute=29, second=48),
work_end=datetime.time(hour=16, minute=29, second=48))
lisa.book(datetime.datetime(year=2020, month=2, day=2, hour=12),
datetime.timedelta(seconds=3600))
with self.assertRaises(AssertionError):
lisa.book(datetime.datetime(year=2020, month=2, day=2, hour=11, minute=30),
datetime.timedelta(seconds=3600))
self.assertEqual(len(lisa.booked_events), 1)
def test_meeting_overlap_first_contains_second(self):
"""
Attempt to book two overlapping interviews
First |---------------|
Second |--------|
"""
miark = Interviewer(work_start=datetime.time(hour=20),
work_end=datetime.time(hour=23, minute=59, second=59))
miark.book(datetime.datetime(year=2999, month=12, day=31, hour=21),
datetime.timedelta(seconds=9000))
with self.assertRaises(AssertionError):
miark.book(datetime.datetime(year=2999, month=12, day=31, hour=21, minute=30),
datetime.timedelta(seconds=3600))
self.assertEqual(len(miark.booked_events), 1)
def test_meeting_overlap_second_contains_first(self):
"""
Attempt to book two overlapping interviews
First |--------|
Second |---------------|
"""
mark = Interviewer(work_start=datetime.time(hour=12, minute=8),
work_end=datetime.time(hour=20, minute=15))
mark.book(datetime.datetime(year=1900, month=1, day=1, hour=15),
datetime.timedelta(seconds=3600))
with self.assertRaises(AssertionError):
mark.book(datetime.datetime(year=1900, month=1, day=1, hour=14),
datetime.timedelta(seconds=10800))
self.assertEqual(len(mark.booked_events), 1)
class EventTests(unittest.TestCase):
""" Verify that an event end is correctly computed. """
def test_end(self):
event = Event(start=datetime.datetime(year=2000, month=6, day=15, hour=12, minute=30, second=30),
duration=datetime.timedelta(seconds=3700))
self.assertEqual(event.end().year, 2000)
self.assertEqual(event.end().month, 6)
self.assertEqual(event.end().day, 15)
self.assertEqual(event.end().hour, 13)
self.assertEqual(event.end().minute, 32)
self.assertEqual(event.end().second, 10)