Sha256: bc7a64b32e635123e45dca6e670777bbf8b8197ab447cd7f1f26239863d206af

Contents?: true

Size: 1.57 KB

Versions: 41

Compression:

Stored size: 1.57 KB

Contents

"""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.assertRaisesWithMessage(ValueError):
            slices("012", 4)

    def test_overly_short_slice(self):
        with self.assertRaisesWithMessage(ValueError):
            slices("01234", 0)

    # 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()

Version data entries

41 entries across 41 versions & 1 rubygems

Version Path
trackler-2.2.1.137 tracks/python/exercises/series/series_test.py
trackler-2.2.1.136 tracks/python/exercises/series/series_test.py
trackler-2.2.1.135 tracks/python/exercises/series/series_test.py
trackler-2.2.1.134 tracks/python/exercises/series/series_test.py
trackler-2.2.1.133 tracks/python/exercises/series/series_test.py
trackler-2.2.1.132 tracks/python/exercises/series/series_test.py
trackler-2.2.1.131 tracks/python/exercises/series/series_test.py
trackler-2.2.1.130 tracks/python/exercises/series/series_test.py
trackler-2.2.1.129 tracks/python/exercises/series/series_test.py
trackler-2.2.1.128 tracks/python/exercises/series/series_test.py
trackler-2.2.1.127 tracks/python/exercises/series/series_test.py
trackler-2.2.1.126 tracks/python/exercises/series/series_test.py
trackler-2.2.1.125 tracks/python/exercises/series/series_test.py
trackler-2.2.1.124 tracks/python/exercises/series/series_test.py
trackler-2.2.1.123 tracks/python/exercises/series/series_test.py
trackler-2.2.1.122 tracks/python/exercises/series/series_test.py
trackler-2.2.1.121 tracks/python/exercises/series/series_test.py
trackler-2.2.1.120 tracks/python/exercises/series/series_test.py
trackler-2.2.1.119 tracks/python/exercises/series/series_test.py
trackler-2.2.1.118 tracks/python/exercises/series/series_test.py