forked from benevolentprof/inf1340-2015-labs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_lab3.py
77 lines (54 loc) · 2.11 KB
/
test_lab3.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env python3
""" Module to test lab3.py """
__author__ = 'Susan Sim'
__email__ = "ses@drsusansim.org"
__copyright__ = "2015 Susan Sim"
__license__ = "MIT License"
from lab3 import days_in_month
MONTHS_WITH_31 = ["January", "March", "May", "July", "August", "October", "December"]
MONTHS_WITH_30 = ["April", "June", "September", "November"]
MONTHS_WITH_28_or_29 = ["February"]
MONTHS_WITH_31_LOWER=[month.lower() for month in MONTHS_WITH_31]
MONTHS_WITH_30_LOWER=[month.lower() for month in MONTHS_WITH_30]
MONTHS_WITH_28_or_29_LOWER=[month.lower() for month in MONTHS_WITH_28_or_29]
def test_months_with_31():
"""
Test months with 31 days
"""
# Write a test function for the months with 31 days
for item in MONTHS_WITH_31:
assert days_in_month(item) == 31
def test_months_with_30():
# Write a test function for the months with 30 days
for item in MONTHS_WITH_30:
assert days_in_month(item) == 30
def test_months_with_28_or_29():
# Write a test function for the months with 28 or 29 days
for item in MONTHS_WITH_28_or_29:
assert days_in_month("February") == "28 or 29"
# Write a test function for months that are not capitalized properly
# Hint: use the lower() string method
def test_months_with_31_lower():
# Write a test function for the months with 31 days
for item in MONTHS_WITH_31_LOWER:
assert days_in_month(item) == 31
def test_months_with_30_lower():
# Write a test function for the months with 30 days
for item in MONTHS_WITH_30_LOWER:
assert days_in_month(item) == 30
def test_months_with_28_or_29_lower():
# Write a test function for the months with 28 or 29 days
for item in MONTHS_WITH_28_or_29_LOWER:
assert days_in_month(item) == "28 or 29"
# Write a test function for unexpected input
# Hint: use a try/except block to deal with the exception
# Hint: use data types other than strings as input
def test_unexpected():
try:
days_in_month("abcde")
except ValueError:
assert True
try:
days_in_month(9)
except AttributeError:
assert True