Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
A test run prints this.
..F.E
======================================================================
FAIL: test_edges (__main__.TestGrade)
AssertionError: 'C' != 'B'
ERROR: test_empty (__main__.TestAverage)
ZeroDivisionError: division by zero
Ran 5 tests in 0.001s
FAILED (failures=1, errors=1)How many tests passed? What is the difference between the failure and the error? For test_edges, which value is the answer of the function?
Have you tried it?
Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, compare your working with the solution.
Plan. Read the line of letters: each character is one test. A dot is a pass, F is a failure, and E is an error. The letters are ., ., F, ., E.
test_edges ran, and an assertEqual found that the answer was not the expected one.test_empty crashed with a ZeroDivisionError: the code under test, or the test, raised an error that was not expected. The function divides by zero for an empty list.AssertionError: 'C' != 'B', the first value is the answer of the function and the second is the expected one. So the function gave C, and the test expected B: a bug at an edge of the grade function.Answer: 3 passed. A failure is a wrong answer, an error is a crash. The function gave C.
Log in to join the discussion.
Loading…