This repository was archived by the owner on Apr 24, 2025. It is now read-only.
File tree Expand file tree Collapse file tree
projects/Calculate Age/tests Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import time
2+ from unittest .mock import patch
3+ from calculate_age import age_calculator
4+
5+ @patch ('time.time' , return_value = 1621848668.0 )
6+ def test_age_calculator (mock_time ):
7+ name = "Chloe"
8+ age = 30
9+ expect_output = "Chloe's age is 30 years or 365 months or 11102 days"
10+ assert age_calculator (name , age ) == expect_output
11+
12+ def test_age_calculator_negative_age ():
13+ name = "Emma"
14+ age = - 5
15+ try :
16+ age_calculator (name , age )
17+ except ValueError as e :
18+ assert str (e ) == "Please input a positive number."
19+
20+
21+ def test_age_calculator_leap_year ():
22+ name = "David"
23+ age = 30
24+ expect_output_leap_year = "David's age is 30 years or 365 months or 11100 days"
25+ assert age_calculator (name , age ) == expect_output_leap_year
Original file line number Diff line number Diff line change 1+ import pytest
2+ from utilize_date import judge_leap_year , month_days
3+
4+ def test_judge_leap_year ():
5+ assert judge_leap_year (2000 ) == True
6+ assert judge_leap_year (2008 ) == True
7+ assert judge_leap_year (2023 ) == False
8+ assert judge_leap_year (1900 ) == False
9+ assert judge_leap_year (2400 ) == True
10+ assert judge_leap_year (2100 ) == False
11+
12+ def test_month_days ():
13+ assert month_days (7 , False ) == 31
14+ assert month_days (4 , True ) == 30
15+ assert month_days (2 , True ) == 29
16+ assert month_days (2 , False ) == 28
17+ assert month_days (1 , False ) == 31
18+ assert month_days (11 , True ) == 30
You can’t perform that action at this time.
0 commit comments