-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_snag.py
42 lines (36 loc) · 2.17 KB
/
test_snag.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
import snag
import datetime
import unittest
class TestDateTimeFunctions(unittest.TestCase):
def test_half_hour_floor(self):
test_cases = (
(datetime.datetime(2023, 4, 25, 11, 0, 0), datetime.datetime(2023, 4, 25, 11, 0, 0)),
(datetime.datetime(2023, 4, 25, 11, 1, 0), datetime.datetime(2023, 4, 25, 11, 0, 0)),
(datetime.datetime(2023, 4, 25, 11, 15, 0), datetime.datetime(2023, 4, 25, 11, 0, 0)),
(datetime.datetime(2023, 4, 25, 11, 16, 0), datetime.datetime(2023, 4, 25, 11, 0, 0)),
(datetime.datetime(2023, 4, 25, 11, 30, 0), datetime.datetime(2023, 4, 25, 11, 30, 0)),
(datetime.datetime(2023, 4, 25, 11, 31, 0), datetime.datetime(2023, 4, 25, 11, 30, 0)),
(datetime.datetime(2023, 4, 25, 11, 45, 0), datetime.datetime(2023, 4, 25, 11, 30, 0)),
(datetime.datetime(2023, 4, 25, 11, 46, 0), datetime.datetime(2023, 4, 25, 11, 30, 0)),
)
for dt, expected in test_cases:
with self.subTest(dt=dt):
result = snag.half_hour_floor(dt)
self.assertEqual(result, expected)
def test_half_hour_ceil(self):
test_cases = (
(datetime.datetime(2023, 4, 25, 11, 0, 0), datetime.datetime(2023, 4, 25, 11, 30, 0)),
(datetime.datetime(2023, 4, 25, 11, 1, 0), datetime.datetime(2023, 4, 25, 11, 30, 0)),
(datetime.datetime(2023, 4, 25, 11, 15, 0), datetime.datetime(2023, 4, 25, 11, 30, 0)),
(datetime.datetime(2023, 4, 25, 11, 16, 0), datetime.datetime(2023, 4, 25, 11, 30, 0)),
(datetime.datetime(2023, 4, 25, 11, 30, 0), datetime.datetime(2023, 4, 25, 12, 0, 0)),
(datetime.datetime(2023, 4, 25, 11, 31, 0), datetime.datetime(2023, 4, 25, 12, 0, 0)),
(datetime.datetime(2023, 4, 25, 11, 45, 0), datetime.datetime(2023, 4, 25, 12, 0, 0)),
(datetime.datetime(2023, 4, 25, 11, 46, 0), datetime.datetime(2023, 4, 25, 12, 0, 0)),
)
for dt, expected in test_cases:
with self.subTest(dt=dt):
result = snag.half_hour_ceil(dt)
self.assertEqual(result, expected)
if __name__ == '__main__':
unittest.main()