This commit is contained in:
Xevion
2019-07-13 04:18:06 -05:00
parent d558cf2d6c
commit 266e06add5
29 changed files with 656 additions and 1 deletions
+1
View File
@@ -0,0 +1 @@
{"track":"python","exercise":"series","id":"c04eea9d5a0f478ea81039d232a66e7f","url":"https://exercism.io/my/solutions/c04eea9d5a0f478ea81039d232a66e7f","handle":"Xevion","is_requester":true,"auto_approve":false}
+58
View File
@@ -0,0 +1,58 @@
"""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
# Tests adapted from `problem-specifications//canonical-data.json` @ v1.0.0
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_slice_length_is_too_large(self):
with self.assertRaisesWithMessage(ValueError):
slices("12345", 6)
def test_slice_length_cannot_be_zero(self):
with self.assertRaisesWithMessage(ValueError):
slices("12345", 0)
def test_slice_length_cannot_be_negative(self):
with self.assertRaisesWithMessage(ValueError):
slices("123", -1)
def test_empty_series_is_invalid(self):
with self.assertRaisesWithMessage(ValueError):
slices("", 1)
# Utility functions
def setUp(self):
try:
self.assertRaisesRegex
except AttributeError:
self.assertRaisesRegex = self.assertRaisesRegexp
def assertRaisesWithMessage(self, exception):
return self.assertRaisesRegex(exception, r".+")
if __name__ == '__main__':
unittest.main()