-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtest-saytime.py
More file actions
50 lines (44 loc) · 1.44 KB
/
test-saytime.py
File metadata and controls
50 lines (44 loc) · 1.44 KB
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
#!/usr/bin/python3
# test-saytime.py
import saytime
import unittest
class TestSaytime(unittest.TestCase):
def setUp(self):
self.nums = list(range(11))
def test_numbers(self):
# make sure the numbers translate correctly
words = (
'oh', 'one', 'two', 'three', 'four', 'five',
'six', 'seven', 'eight', 'nine', 'ten'
)
for i, n in enumerate(self.nums):
self.assertEqual(saytime.numwords(n).numwords(), words[i])
def test_time(self):
time_tuples = (
(0, 0), (0, 1), (11, 0), (12, 0), (13, 0), (12, 29), (12, 30),
(12, 31), (12, 15), (12, 30), (12, 45), (11, 59), (23, 15),
(23, 59), (12, 59), (13, 59), (1, 60), (24, 0)
)
time_words = (
"midnight",
"one past midnight",
"eleven o'clock",
"noon",
"one o'clock",
"twenty-nine past noon",
"half past noon",
"twenty-nine til one",
"quarter past noon",
"half past noon",
"quarter til one",
"one til noon",
"quarter past eleven",
"one til midnight",
"one til one",
"one til two",
"OOR",
"OOR"
)
for i, t in enumerate(time_tuples):
self.assertEqual(saytime.saytime(*t).words(), time_words[i])
if __name__ == "__main__": unittest.main()