-
-
Notifications
You must be signed in to change notification settings - Fork 811
Closed
Description
Section: Testing Assertions
def running(values):
assert len(values) > 0
result = [values[0]]
for v in values[1:]:
assert result[-1] >= 0
result.append(result[-1] + v)
assert result[-1] >= result[0]
return result
The second assertion checks that the first value in the list is positive. Input such as [-1,0,2,3] will make it fail.
The second assertion is actually checking if the last value of the 'result' list is positive on every iteration. On the first iteration it does check that the first value is positive, since result[0] == result[-1], but on subsequent iterations it does not.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels