Case Study: Testing running_sum
In Case Study: Testing above_freezing , we tested a program that involved only immutable types. In this section, you’ll learn how to test functions involving mutable types, like lists and dictionaries.
Suppose we need to write a function that modifies a list so that it contains a running sum of the values in it. For example, if the list is [1, 2, 3], the list should be mutated so that the first value is 1, the second value is the sum of the first two numbers, 1 + 2, and the third value is the sum of the first three numbers, 1 + 2 + 3, so we expect that the list [1, 2, 3] will be modified to be [1, 3, 6].
Following the function design recipe (see Designing New Functions: A Recipe), here is a file named ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access