-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmath.py
38 lines (28 loc) · 841 Bytes
/
math.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
import unittest
class TestMathMethods(unittest.TestCase):
# TODO:
# - intersection of sets: a[i].intersection(b[j]):
# - caching/memoizing: functools.lru_cache
# - combinations itertools.permutations
# - random.randint(a, b)
def test_add_strings(self):
s1 = "1234"
s2 = "111"
test_ans = "1345"
base = 10
n1 = len(s1)
n2 = len(s2)
change = 0
i = 0
ans = ""
while (0 < change) or (i < n1) or (i < n2):
if i < n1:
change += int(s1[n1 - i - 1])
if i < n2:
change += int(s2[n2 - i - 1])
ans = str(change % base) + ans
change = change // base
i += 1
self.assertEqual(test_ans, ans)
if __name__ == "__main__":
unittest.main()