-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_check_time_of_use_coverage.py
159 lines (138 loc) · 7.9 KB
/
test_check_time_of_use_coverage.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import unittest
import check_time_of_use_coverage
import datetime
class TestCompilingOverlaps(unittest.TestCase):
def testSimpleOverlappingCase(self):
test_tariff = {'first_comp': {'Month': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],
'TimeIntervals': {'T1': ['00:00', '13:00'],
'T2': ['13:00', '00:00']
},
'Weekday': True,
'Weekend': True
},
'second_comp': {'Month': [1, 2],
'TimeIntervals': {'T1': ['11:00', '12:00']},
'Weekday': True,
'Weekend': True
}
}
expect_answer = \
'''Overlaps on Month: 1, Week time: Weekday, Half hour ending: 11:30 are, first_comp T1, second_comp T1
Overlaps on Month: 1, Week time: Weekday, Half hour ending: 12:00 are, first_comp T1, second_comp T1
Overlaps on Month: 1, Week time: Weekend, Half hour ending: 11:30 are, first_comp T1, second_comp T1
Overlaps on Month: 1, Week time: Weekend, Half hour ending: 12:00 are, first_comp T1, second_comp T1
Overlaps on Month: 2, Week time: Weekday, Half hour ending: 11:30 are, first_comp T1, second_comp T1
Overlaps on Month: 2, Week time: Weekday, Half hour ending: 12:00 are, first_comp T1, second_comp T1
Overlaps on Month: 2, Week time: Weekend, Half hour ending: 11:30 are, first_comp T1, second_comp T1
Overlaps on Month: 2, Week time: Weekend, Half hour ending: 12:00 are, first_comp T1, second_comp T1
No gaps in the component time intervals were found.'''
answer = check_time_of_use_coverage.compile_set_of_overlapping_components_on_yearly_basis(test_tariff)
self.assertEqual(answer, expect_answer)
class TestCheckForOverlap(unittest.TestCase):
def testSimpleOverlappingCase(self):
test_tariff = {'first_comp': {'Month': [1, 2],
'TimeIntervals': {'T1': ['11:00', '12:00'],
'T2': ['12:00', '13:00']
},
'Weekday': False,
'Weekend': True
},
'second_comp': {'Month': [1, 2],
'TimeIntervals': {'T1': ['11:00', '12:00'],
'T2': ['12:00', '13:00']
},
'Weekday': False,
'Weekend': True
}
}
expect_answer = ['first_comp T1', 'second_comp T1']
answer = check_time_of_use_coverage._overlapping_components(test_tariff, month=1, hour=11,
minute=30, week_time='Weekend')
self.assertListEqual(answer, expect_answer)
def testSimpleOverlappingWithinComponent(self):
test_tariff = {'first_comp': {'Month': [1, 2],
'TimeIntervals': {'T1': ['11:00', '12:00'],
'T2': ['11:00', '13:00']
},
'Weekday': False,
'Weekend': True
},
'second_comp': {'Month': [1, 2],
'TimeIntervals': {'T1': ['11:00', '12:00'],
'T2': ['12:00', '13:00']
},
'Weekday': False,
'Weekend': True
}
}
expect_answer = ['first_comp T1', 'first_comp T2', 'second_comp T1']
answer = check_time_of_use_coverage._overlapping_components(test_tariff, month=1, hour=11,
minute=30, week_time='Weekend')
self.assertListEqual(answer, expect_answer)
class TestCheckIfTestTimeInInterval(unittest.TestCase):
def testFailAtStartTime(self):
test_interval = ['12:00', '13:00']
expected_answer = False
answer = check_time_of_use_coverage._is_right_time(interval=test_interval, hour=12, minute=00)
self.assertEqual(answer, expected_answer)
def testAcceptAtEndTime(self):
test_interval = ['12:00', '13:00']
expected_answer = True
answer = check_time_of_use_coverage._is_right_time(interval=test_interval, hour=13, minute=00)
self.assertEqual(answer, expected_answer)
def testGoodTime(self):
test_interval = ['12:00', '13:00']
expected_answer = True
answer = check_time_of_use_coverage._is_right_time(interval=test_interval, hour=12, minute=30)
self.assertEqual(answer, expected_answer)
def testReversedFailAtStartTime(self):
test_interval = ['13:00', '12:00']
expected_answer = True
answer = check_time_of_use_coverage._is_right_time(interval=test_interval, hour=12, minute=00)
self.assertEqual(answer, expected_answer)
def testAcceptReversedAtEndTime(self):
test_interval = ['13:00', '12:00']
expected_answer = False
answer = check_time_of_use_coverage._is_right_time(interval=test_interval, hour=13, minute=00)
self.assertEqual(answer, expected_answer)
def testReversedGoodTime(self):
test_interval = ['13:00', '12:00']
expected_answer = True
answer = check_time_of_use_coverage._is_right_time(interval=test_interval, hour=13, minute=30)
self.assertEqual(answer, expected_answer)
def testFailReversedBadTime(self):
test_interval = ['13:00', '12:00']
expected_answer = False
answer = check_time_of_use_coverage._is_right_time(interval=test_interval, hour=12, minute=30)
self.assertEqual(answer, expected_answer)
class TestInterpretUserTimeString(unittest.TestCase):
def testGoodTimeString(self):
test_string = '12:00'
expected_answer = datetime.time(hour=12, minute=0)
answer = check_time_of_use_coverage._interpret_user_time_string(test_string)
self.assertEqual(answer, expected_answer)
def testHoursLeadingZeros(self):
test_string = '02:0'
expected_answer = datetime.time(hour=2, minute=0)
answer = check_time_of_use_coverage._interpret_user_time_string(test_string)
self.assertEqual(answer, expected_answer)
def testHoursNoLeadingZeros(self):
test_string = '2:0'
expected_answer = datetime.time(hour=2, minute=0)
answer = check_time_of_use_coverage._interpret_user_time_string(test_string)
self.assertEqual(answer, expected_answer)
def testMinutesWithLeadingZeros(self):
test_string = '2:01'
expected_answer = datetime.time(hour=2, minute=1)
answer = check_time_of_use_coverage._interpret_user_time_string(test_string)
self.assertEqual(answer, expected_answer)
def testMinutesWithoutLeadingZeros(self):
test_string = '2:1'
expected_answer = datetime.time(hour=2, minute=1)
answer = check_time_of_use_coverage._interpret_user_time_string(test_string)
self.assertEqual(answer, expected_answer)
def test2400WrapsTo0000(self):
test_string = '24:00'
expected_answer = datetime.time(hour=0, minute=0)
answer = check_time_of_use_coverage._interpret_user_time_string(test_string)
self.assertEqual(answer, expected_answer)