|
16 | 16 | class TestCalculateAgeAtVaccination(unittest.TestCase): |
17 | 17 | """Tests for age calculation at vaccination time.""" |
18 | 18 |
|
19 | | - def test_age_calculation_yyyymmdd_format(self): |
20 | | - birth_date = "20040609" |
21 | | - vaccination_date = "20260212" |
22 | | - age = calculate_age_at_vaccination(birth_date, vaccination_date) |
23 | | - self.assertEqual(age, 21) |
24 | | - |
25 | | - def test_age_calculation_with_time(self): |
26 | | - birth_date = "20040609T120000" |
27 | | - vaccination_date = "20260212T174437" |
28 | | - age = calculate_age_at_vaccination(birth_date, vaccination_date) |
29 | | - self.assertEqual(age, 21) |
30 | | - |
31 | | - def test_age_calculation_after_birthday(self): |
32 | | - birth_date = "20040609" |
33 | | - vaccination_date = "20260815" |
34 | | - age = calculate_age_at_vaccination(birth_date, vaccination_date) |
35 | | - self.assertEqual(age, 22) |
36 | | - |
37 | | - def test_age_calculation_on_birthday(self): |
38 | | - birth_date = "20040609" |
39 | | - vaccination_date = "20260609" |
40 | | - age = calculate_age_at_vaccination(birth_date, vaccination_date) |
41 | | - self.assertEqual(age, 22) |
42 | | - |
43 | | - def test_age_calculation_infant(self): |
44 | | - birth_date = "20260609" |
45 | | - vaccination_date = "20260915" |
46 | | - age = calculate_age_at_vaccination(birth_date, vaccination_date) |
47 | | - self.assertEqual(age, 0) |
48 | | - |
49 | | - def test_age_calculation_leap_year_birthday(self): |
50 | | - birth_date = "20000229" |
51 | | - vaccination_date = "20240228" |
52 | | - age = calculate_age_at_vaccination(birth_date, vaccination_date) |
53 | | - self.assertEqual(age, 23) |
54 | | - |
55 | | - def test_age_calculation_same_day_different_year(self): |
56 | | - birth_date = "20000101" |
57 | | - vaccination_date = "20250101" |
58 | | - age = calculate_age_at_vaccination(birth_date, vaccination_date) |
59 | | - self.assertEqual(age, 25) |
| 19 | + def test_age_calculation_core_cases(self): |
| 20 | + cases = [ |
| 21 | + ("20040609", "20260212", 21), # YYYYMMDD format |
| 22 | + ("20040609", "20260609", 22), # On birthday |
| 23 | + ("20040609", "20260815", 22), # After birthday |
| 24 | + ("20260609", "20260915", 0), # Infant |
| 25 | + ("20040609T120000", "20260212T17443700", 21), # With time |
| 26 | + ("20000101", "20250101", 25), # Same day different year |
| 27 | + ("20000229", "20240228", 23), # Leap year birthday |
| 28 | + ("20000229", "20240229", 24), # Leap year birthday on leap day |
| 29 | + ("20000229", "20250228", 24), # day before; birthday hasn't happened yet |
| 30 | + ] |
| 31 | + |
| 32 | + for birth_date, vaccination_date, expected_age in cases: |
| 33 | + with self.subTest(birth_date=birth_date, vaccination_date=vaccination_date): |
| 34 | + self.assertEqual( |
| 35 | + calculate_age_at_vaccination(birth_date, vaccination_date), |
| 36 | + expected_age, |
| 37 | + ) |
| 38 | + |
| 39 | + def test_rejects_invalid_birth_date_format(self): |
| 40 | + with self.assertRaisesRegex(ValueError, "PERSON_DOB"): |
| 41 | + calculate_age_at_vaccination("2004-06-09", "20260212") |
| 42 | + |
| 43 | + def test_rejects_invalid_vaccination_date_format(self): |
| 44 | + with self.assertRaisesRegex(ValueError, "DATE_AND_TIME"): |
| 45 | + calculate_age_at_vaccination("20040609", "2026-02-12") |
| 46 | + |
| 47 | + def test_rejects_nonexistent_birth_date(self): |
| 48 | + with self.assertRaisesRegex(ValueError, "PERSON_DOB"): |
| 49 | + calculate_age_at_vaccination("20040230", "20260212") |
| 50 | + |
| 51 | + def test_rejects_vaccination_before_birth(self): |
| 52 | + with self.assertRaisesRegex(ValueError, "cannot be before"): |
| 53 | + calculate_age_at_vaccination("20260212", "20250212") |
60 | 54 |
|
61 | 55 |
|
62 | 56 | class TestCreateMnsNotification(unittest.TestCase): |
|
0 commit comments