Skip to content
This repository was archived by the owner on Apr 24, 2025. It is now read-only.

Commit 9675b1f

Browse files
committed
Add test-code in each test module
1 parent f6ca789 commit 9675b1f

2 files changed

Lines changed: 43 additions & 0 deletions

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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

0 commit comments

Comments
 (0)