forked from PyAr/exercism
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseries_test.py
66 lines (52 loc) · 2.36 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# These tests are auto-generated with test data from:
# https://github.com/exercism/problem-specifications/tree/main/exercises/series/canonical-data.json
# File last updated on 2023-07-19
import unittest
from series import (
slices,
)
class SeriesTest(unittest.TestCase):
def test_slices_of_one_from_one(self):
self.assertEqual(slices("1", 1), ["1"])
def test_slices_of_one_from_two(self):
self.assertEqual(slices("12", 1), ["1", "2"])
def test_slices_of_two(self):
self.assertEqual(slices("35", 2), ["35"])
def test_slices_of_two_overlap(self):
self.assertEqual(slices("9142", 2), ["91", "14", "42"])
def test_slices_can_include_duplicates(self):
self.assertEqual(slices("777777", 3), ["777", "777", "777", "777"])
def test_slices_of_a_long_series(self):
self.assertEqual(
slices("918493904243", 5),
["91849", "18493", "84939", "49390", "93904", "39042", "90424", "04243"],
)
def test_slice_length_is_too_large(self):
with self.assertRaises(ValueError) as err:
slices("12345", 6)
self.assertEqual(type(err.exception), ValueError)
self.assertEqual(
err.exception.args[0], "slice length cannot be greater than series length"
)
def test_slice_length_is_way_too_large(self):
with self.assertRaises(ValueError) as err:
slices("12345", 42)
self.assertEqual(type(err.exception), ValueError)
self.assertEqual(
err.exception.args[0], "slice length cannot be greater than series length"
)
def test_slice_length_cannot_be_zero(self):
with self.assertRaises(ValueError) as err:
slices("12345", 0)
self.assertEqual(type(err.exception), ValueError)
self.assertEqual(err.exception.args[0], "slice length cannot be zero")
def test_slice_length_cannot_be_negative(self):
with self.assertRaises(ValueError) as err:
slices("123", -1)
self.assertEqual(type(err.exception), ValueError)
self.assertEqual(err.exception.args[0], "slice length cannot be negative")
def test_empty_series_is_invalid(self):
with self.assertRaises(ValueError) as err:
slices("", 1)
self.assertEqual(type(err.exception), ValueError)
self.assertEqual(err.exception.args[0], "series cannot be empty")