/
test_exercise1.py
117 lines (84 loc) · 2.5 KB
/
test_exercise1.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/usr/bin/env python3
""" Module to test exercise1.py """
# imports one per line
import pytest
from exercise1 import grade_to_gpa
def test_letter_grade():
"""
Letter grade inputs
"""
assert grade_to_gpa("A+") == 4.0
assert grade_to_gpa("A") == 4.0
assert grade_to_gpa("A-") == 3.7
assert grade_to_gpa("B+") == 3.3
assert grade_to_gpa("B") == 3
assert grade_to_gpa("B-") == 2.7
assert grade_to_gpa("FZ") == 0
with pytest.raises(ValueError):
grade_to_gpa("q")
grade_to_gpa("aa")
grade_to_gpa("j")
grade_to_gpa("l")
grade_to_gpa("o")
grade_to_gpa("w+")
grade_to_gpa("c-")
grade_to_gpa("Z-")
def test_percentage_grade():
"""
Numeric grade inputs
"""
assert grade_to_gpa(100) == 4.0
assert grade_to_gpa(95) == 4.0
assert grade_to_gpa(90) == 4.0
assert grade_to_gpa(89) == 4.0
assert grade_to_gpa(87) == 4.0
assert grade_to_gpa(85) == 4.0
assert grade_to_gpa(84) == 3.7
assert grade_to_gpa(82) == 3.7
assert grade_to_gpa(80) == 3.7
assert grade_to_gpa(79) == 3.3
assert grade_to_gpa(78) == 3.3
assert grade_to_gpa(77) == 3.3
assert grade_to_gpa(76) == 3.0
assert grade_to_gpa(75) == 3.0
assert grade_to_gpa(74) == 3.0
assert grade_to_gpa(73) == 3.0
assert grade_to_gpa(72) == 2.7
assert grade_to_gpa(71) == 2.7
assert grade_to_gpa(70) == 2.7
assert grade_to_gpa(69) == 0.0
assert grade_to_gpa(37) == 0.0
assert grade_to_gpa(24) == 0.0
assert grade_to_gpa(0) == 0.0
with pytest.raises(ValueError):
grade_to_gpa(101)
with pytest.raises(ValueError):
grade_to_gpa(-1)
with pytest.raises(TypeError):
grade_to_gpa(0.5)
with pytest.raises(ValueError):
grade_to_gpa(300)
with pytest.raises(ValueError):
grade_to_gpa(-50)
with pytest.raises(TypeError):
grade_to_gpa(-0.75)
def test_float_input():
"""
Float inputs
"""
with pytest.raises(TypeError):
grade_to_gpa(82.5)
with pytest.raises(TypeError):
grade_to_gpa(79.9)
with pytest.raises(TypeError):
grade_to_gpa(0.4)
with pytest.raises(TypeError):
grade_to_gpa(99.9)
with pytest.raises(TypeError):
grade_to_gpa(59.9)
def test_cornercase_input():
"""
Check Corner Testcases - Checking the cases that are right on the boundary.
"""
assert grade_to_gpa(90) == 4.0
assert grade_to_gpa(70) == 2.7