@@ -43,6 +43,38 @@ def test_get_age_from_cpr(self):
4343 with self .assertRaises (ValueError ):
4444 cpr_util .get_age ("010190xxxx" )
4545
46+ def test_get_birth_date_from_cpr (self ):
47+ """Test getting the age from a cpr number."""
48+ # A table of fictional cpr-numbers and the expected birth dates.
49+ test_data = (
50+ ("0101920000" , date (1992 , 1 , 1 )),
51+ ("0101921000" , date (1992 , 1 , 1 )),
52+ ("0101922000" , date (1992 , 1 , 1 )),
53+ ("0101923000" , date (1992 , 1 , 1 )),
54+ ("0101154000" , date (2015 , 1 , 1 )),
55+ ("0101924000" , date (1992 , 1 , 1 )),
56+ ("0101155000" , date (2015 , 1 , 1 )),
57+ ("0101925000" , date (1892 , 1 , 1 )),
58+ ("0101156000" , date (2015 , 1 , 1 )),
59+ ("0101926000" , date (1892 , 1 , 1 )),
60+ ("0101157000" , date (2015 , 1 , 1 )),
61+ ("0101927000" , date (1892 , 1 , 1 )),
62+ ("0101158000" , date (2015 , 1 , 1 )),
63+ ("0101928000" , date (1892 , 1 , 1 )),
64+ ("0101159000" , date (2015 , 1 , 1 )),
65+ ("0101929000" , date (1992 , 1 , 1 )),
66+ )
67+
68+ for cpr , birth_date in test_data :
69+ with self .subTest (cpr = cpr , birth_date = birth_date ):
70+ self .assertEqual (cpr_util .get_birth_date (cpr ), birth_date )
71+
72+ with self .assertRaises (ValueError ):
73+ cpr_util .get_birth_date ("010190-1234" )
74+
75+ with self .assertRaises (ValueError ):
76+ cpr_util .get_birth_date ("010190xxxx" )
77+
4678
4779if __name__ == '__main__' :
4880 unittest .main ()
0 commit comments