-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_running_sum.py
67 lines (51 loc) · 2.04 KB
/
test_running_sum.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
import unittest
class TestRunningSum(unittest.TestCase):
"""Tests for sums.running_sum."""
def test_running_sum_empty(self):
"""Test an empty list."""
argument = []
expected = []
sums.running_sum(argument)
self.assertEqual(expected, argument, "The list is empty.")
def test_running_sum_one_item(self):
"""Test a one-item list."""
argument = [5]
expected = [5]
sums.running_sum(argument)
self.assertEqual(expected, argument, "The list contains one item.")
def test_running_sum_two_items(self):
"""Test a two-item list."""
argument = [2, 5]
expected = [2, 7]
sums.running_sum(argument)
self.assertEqual(expected, argument, "The list contains two items.")
def test_running_sum_multi_negative(self):
"""Test a list of negative values."""
argument = [-1, -5, -3, -4]
expected = [-1, -6, -9, -13]
sums.running_sum(argument)
self.assertEqual(expected, argument,
"The list contains only negative values.")
def test_running_sum_multi_zeros(self):
"""Test a list of zeros."""
argument = [0, 0, 0, 0]
expected = [0, 0, 0, 0]
sums.running_sum(argument)
self.assertEqual(expected, argument, "The list contains only zeros.")
def test_running_sum_multi_positive(self):
"""Test a list of positive values."""
argument = [4, 2, 3, 6]
expected = [4, 6, 9, 15]
sums.running_sum(argument)
self.assertEqual(expected, argument,
"The list contains only positive values.")
def test_running_sum_multi_mix(self):
"""Test a list containing mixture of negative values, zeros and
positive values."""
argument = [4, 0, 2, -5, 0]
expected = [4, 4, 6, 1, 1]
sums.running_sum(argument)
self.assertEqual(expected, argument,
"The list contains a mixture of negative values, zeros and"
+ "positive values.")
unittest.main()