-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.py
161 lines (134 loc) · 5.2 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
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
159
160
161
import unittest
from datetime import datetime, timedelta, timezone
from big_number_computation import big_number_computation, to_int
from date_time_transformation import transform_datetime
from string_and_words import word_count, word_replacement, grep_line
# Big Number Computation
class BigNumberComputationTests(unittest.TestCase):
def test_to_int_normal_positive(self):
self.assertEqual(to_int("1"), 1)
def test_to_int_big_positive(self):
self.assertEqual(
to_int("100000000000000000000000000000000000000000"),
100000000000000000000000000000000000000000
)
def test_to_int_normal_negative(self):
self.assertEqual( to_int("-1"), -1)
def test_to_int_big_negative(self):
self.assertEqual(
to_int("-100000000000000000000000000000000000000000"),
-100000000000000000000000000000000000000000
)
def test_to_int_zero(self):
self.assertEqual(to_int("0"), 0)
def test_big_number_computation_normal_addition(self):
self.assertEqual(big_number_computation("2", "+", "1"), "3")
def test_big_number_computation_normal_subtraction(self):
self.assertEqual(big_number_computation("2", "-", "1"), "1")
def test_big_number_computation_normal_multiplication(self):
self.assertEqual(big_number_computation("2", "*", "1"), "2")
def test_big_number_computation_big_addition(self):
self.assertEqual(
big_number_computation(
"200000000000000000000000000000000000000000",
"+",
"100000000000000000000000000000000000000000"
)
, "300000000000000000000000000000000000000000"
)
def test_big_number_computation_big_subtraction(self):
self.assertEqual(
big_number_computation(
"200000000000000000000000000000000000000000",
"-",
"100000000000000000000000000000000000000000"
),
"100000000000000000000000000000000000000000"
)
def test_big_number_computation_big_multiplication(self):
self.assertEqual(
big_number_computation(
"200000000000000000000000000000000000000000",
"*",
"100000000000000000000000000000000000000000"
),
"20000000000000000000000000000000000000000000000000000000000000000000000000000000000"
)
# Datetime transformation
class DateTimeTransformationTests(unittest.TestCase):
def setUp(self):
self.f = '%Y-%m-%dT%H:%M:%S%z'
def test_transform_datetime_outside_dst(self):
self.assertEqual(
transform_datetime(
datetime.strptime("2000-01-01T00:00:00+0000", self.f),
-6,
datetime.strptime("2000-03-01T00:00:00+0000", self.f),
datetime.strptime("2000-11-01T00:00:00+0000", self.f)
),
datetime(1999, 12, 31, 18, 0, 0, tzinfo=timezone(timedelta(hours=-6)))
)
def test_transform_datetime_inside_dst(self):
self.assertEqual(
transform_datetime(
datetime.strptime("2000-07-01T00:00:00+0000", self.f),
-6,
datetime.strptime("2000-03-01T00:00:00+0000", self.f),
datetime.strptime("2000-11-01T00:00:00+0000", self.f)
),
datetime(2000, 6, 30, 19, 0, 0, tzinfo=timezone(timedelta(hours=-6)))
)
def test_transform_datetime_start_dst(self):
d = datetime.strptime("2000-03-01T00:00:00+0000", self.f)
self.assertEqual(
transform_datetime(
d,
-6,
d,
datetime.strptime("2000-11-01T00:00:00+0000", self.f)
),
datetime(2000, 2, 29, 19, 0, 0, tzinfo=timezone(timedelta(hours=-6)))
)
def test_transform_datetime_end_dst(self):
d = datetime.strptime("2000-11-01T00:00:00+0000", self.f)
self.assertEqual(
transform_datetime(
d,
-6,
datetime.strptime("2000-03-01T00:00:00+0000", self.f),
d,
),
datetime(2000, 10, 31, 18, 0, 0, tzinfo=timezone(timedelta(hours=-6)))
)
# String and words
class StringAndWords(unittest.TestCase):
def setUp(self):
self.test_text = "The cosmos is all that is...\n...or ever was or ever will be."
def test_word_count(self):
self.assertEqual(
word_count(self.test_text),
{
'The': 1,
'cosmos': 1,
'is': 2,
'all': 1,
'that': 1,
'or': 2,
'ever': 2,
'was': 1,
'will': 1,
'be': 1
}
)
def test_word_replacement(self):
self.assertEqual(
word_replacement('cosmos', 'universe', self.test_text),
"The universe is all that is...\n...or ever was or ever will be."
)
def test_grep_line(self):
self.assertEqual(
grep_line("cosmos", self.test_text),
['1: The cosmos is all that is...']
)
if __name__ == '__main__':
unittest.main()