-
Notifications
You must be signed in to change notification settings - Fork 0
/
16199.py
executable file
·39 lines (28 loc) · 1.09 KB
/
16199.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
# -*- coding: utf-8 -*-
import unittest
def calculate_age(birth, standard):
b_y, b_m, b_d = birth
s_y, s_m, s_d = standard
m, s, y = 0, 0, 0
y = s_y - b_y
s = y + 1
m = y if s_m - b_m > 0 or (s_m == b_m and s_d >= b_d) else y - 1
return([m, s, y])
class TestCalculateAge(unittest.TestCase):
def test_calculate_age(self):
for birth, standard, expected in [
([2003, 3, 5], [2003, 3, 5], [0, 1, 0]),
([2003, 3, 5], [2003, 3, 6], [0, 1, 0]),
([2003, 3, 5], [2003, 4, 1], [0, 1, 0]),
([2003, 3, 5], [2003, 4, 5], [0, 1, 0]),
([2003, 3, 5], [2004, 1, 1], [0, 2, 1]),
([2003, 3, 5], [2004, 3, 4], [0, 2, 1]),
([2003, 3, 5], [2004, 3, 5], [1, 2, 1]),
([2005, 1, 1], [2007, 1, 1], [2, 3, 2]),
([2005, 1, 2], [2007, 1, 1], [1, 3, 2]),
([2005, 12, 31], [2007, 1, 1], [1, 3, 2]),
([2006, 1, 1], [2007, 1, 1], [1, 2, 1])
]:
self.assertEqual(expected, calculate_age(birth, standard))
if __name__ == '__main__':
unittest.main()