-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseries_test.py
49 lines (37 loc) · 1.27 KB
/
series_test.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
"""Tests for the series exercise
Implementation note:
The slices function should raise a ValueError with a meaningful error
message if its length argument doesn't fit the series.
"""
import unittest
from series import slices
class SeriesTest(unittest.TestCase):
def test_slices_of_one(self):
self.assertEqual(
slices("01234", 1),
[[0], [1], [2], [3], [4]], )
def test_slices_of_two(self):
self.assertEqual(
slices("97867564", 2),
[[9, 7], [7, 8], [8, 6], [6, 7], [7, 5], [5, 6], [6, 4]], )
def test_slices_of_three(self):
self.assertEqual(
slices("97867564", 3),
[[9, 7, 8], [7, 8, 6], [8, 6, 7], [6, 7, 5], [7, 5, 6], [5, 6, 4]],
)
def test_slices_of_four(self):
self.assertEqual(
slices("01234", 4),
[[0, 1, 2, 3], [1, 2, 3, 4]], )
def test_slices_of_five(self):
self.assertEqual(
slices("01234", 5),
[[0, 1, 2, 3, 4]], )
def test_overly_long_slice(self):
with self.assertRaises(ValueError):
slices("012", 4)
def test_overly_short_slice(self):
with self.assertRaises(ValueError):
slices("01234", 0)
if __name__ == '__main__':
unittest.main()