本文整理汇总了Python中exercise1.grade_to_gpa函数的典型用法代码示例。如果您正苦于以下问题:Python grade_to_gpa函数的具体用法?Python grade_to_gpa怎么用?Python grade_to_gpa使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了grade_to_gpa函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_bool_input
def test_bool_input():
"""
Boolean inputs
"""
with pytest.raises(TypeError):
grade_to_gpa(True)
grade_to_gpa(False)
示例2: test_float_input
def test_float_input():
"""
Float inputs
"""
with pytest.raises(TypeError):
grade_to_gpa(82.5)
grade_to_gpa(-20.5)
示例3: test_array_input
def test_array_input():
"""
Array inputs
"""
with pytest.raises(TypeError):
grade_to_gpa([1, 2, 3])
with pytest.raises(TypeError):
grade_to_gpa(['A', 'A+', 'B-'])
示例4: test_float_input
def test_float_input():
"""
Float inputs
"""
with pytest.raises(TypeError):
grade_to_gpa(82.5)
# add functions for any other tests
示例5: test_wrong_input_type
def test_wrong_input_type():
# Float Inputs
with pytest.raises(TypeError):
grade_to_gpa(82.5)
# Boolean Inputs
with pytest.raises(TypeError):
grade_to_gpa(True)
示例6: test_letter_input
def test_letter_input():
"""
Grade inputs
"""
with pytest.raises(ValueError):
grade_to_gpa("a+")
with pytest.raises(ValueError):
grade_to_gpa("v")
示例7: test_gpa_consistency
def test_gpa_consistency():
"""
Makes sure that the letters and numbers return the same values
"""
assert grade_to_gpa(100) == grade_to_gpa("A+")
assert grade_to_gpa(80) == grade_to_gpa("A-")
assert grade_to_gpa(70) == grade_to_gpa("B-")
assert grade_to_gpa(50) == grade_to_gpa("FZ")
示例8: test_letter_grade
def test_letter_grade():
"""
Letter grade inputs
"""
assert grade_to_gpa("A+") == 4.0, "test letter: Case 1"
assert grade_to_gpa("A") == 4.0, "test letter: Case 2"
assert grade_to_gpa("A-") == 3.7, "test letter: Case 3"
assert grade_to_gpa("B+") == 3.3, "test letter: Case 4"
assert grade_to_gpa("B") == 3.0, "test letter: Case 5"
assert grade_to_gpa("B-") == 2.7, "test letter: Case 6"
assert grade_to_gpa("FZ") == 0.0, "test letter: Case 7"
with pytest.raises(ValueError):
grade_to_gpa("q")
示例9: test_letter_grade
def test_letter_grade():
"""
Letter grade inputs
"""
assert grade_to_gpa("A+") == 4.3
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.0
assert grade_to_gpa("B-") == 2.7
assert grade_to_gpa("FZ") == 0
with pytest.raises(ValueError):
grade_to_gpa("q")
示例10: test_float_input
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)
示例11: test_float_input
def test_float_input():
"""
Float inputs
"""
#Tests if there are errors in the input format
with pytest.raises(TypeError):
grade_to_gpa(82.5)
with pytest.raises(TypeError):
grade_to_gpa(0.0)
with pytest.raises(TypeError):
grade_to_gpa(-100.0)
with pytest.raises(TypeError):
grade_to_gpa(74.4)
示例12: test_invalid_input
def test_invalid_input():
"""
Float, tuple and list inputs
"""
with pytest.raises(TypeError):
grade_to_gpa(82.5)
with pytest.raises(TypeError):
grade_to_gpa(['A+', 100])
with pytest.raises(TypeError):
grade_to_gpa(('B+', 79))
示例13: test_string_input
def test_string_input():
"""
String inputs
"""
with exercise1.raises(ValueError):
grade_to_gpa("Sentences")
with exercise1.raises(ValueError):
grade_to_gpa("This is")
with exercise1.raises(ValueError):
grade_to_gpa("Invalid")
示例14: test_float_input
def test_float_input():
"""
Float inputs
"""
with exercise1.raises(TypeError):
grade_to_gpa(82.5)
with exercise1.raises(TypeError):
grade_to_gpa(-30.07)
with exercise1.raises(TypeError):
grade_to_gpa(50600)
示例15: test_letter_grade
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.0
assert grade_to_gpa("B-") == 2.7
assert grade_to_gpa("FZ") == 0.0
# Test for invalid letter grade input
with pytest.raises(ValueError):
grade_to_gpa("Q")
# Test for invalid input - special characters
with pytest.raises(ValueError):
grade_to_gpa("+")
with pytest.raises(ValueError):
grade_to_gpa("A*")
# Test for invalid input - numeric input
with pytest.raises(ValueError):
grade_to_gpa("88")
with pytest.raises(ValueError):
grade_to_gpa("9+")