Sha256: df44eeacfb3a0fd5b14363d5e021221a0c7fd54df8f97f43d74660212e735472

Contents?: true

Size: 1.13 KB

Versions: 127

Compression:

Stored size: 1.13 KB

Contents

import unittest

from accumulate import accumulate


class AccumulateTest(unittest.TestCase):
    def test_empty_sequence(self):
        self.assertEqual([], accumulate([], lambda x: x / 2))

    def test_pow(self):
        self.assertEqual([1, 4, 9, 16, 25], accumulate([1, 2, 3, 4, 5],
                         lambda x: x * x))

    def test_divmod(self):
        inp = [10, 17, 23]
        out = [(1, 3), (2, 3), (3, 2)]
        self.assertEqual(out, accumulate(inp, lambda x: divmod(x, 7)))

    def test_composition(self):
        inp = [10, 17, 23]
        self.assertEqual(inp, accumulate(accumulate(inp, lambda x: divmod(x, 7)),
                         lambda x: 7 * x[0] + x[1]))

    def test_capitalize(self):
        inp = ['hello', 'world']
        out = ['HELLO', 'WORLD']
        self.assertEqual(out, accumulate(inp, str.upper))

    def test_recursive(self):
        inp = list('abc')
        out = [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3'], ['c1', 'c2', 'c3']]
        self.assertEqual(out, accumulate(inp, lambda x: accumulate(list('123'),
                         lambda y: x + y)))


if __name__ == '__main__':
    unittest.main()

Version data entries

127 entries across 127 versions & 1 rubygems

Version Path
trackler-2.0.8.27 tracks/python/exercises/accumulate/accumulate_test.py
trackler-2.0.8.26 tracks/python/exercises/accumulate/accumulate_test.py
trackler-2.0.8.24 tracks/python/exercises/accumulate/accumulate_test.py
trackler-2.0.8.23 tracks/python/exercises/accumulate/accumulate_test.py
trackler-2.0.8.22 tracks/python/exercises/accumulate/accumulate_test.py
trackler-2.0.8.21 tracks/python/exercises/accumulate/accumulate_test.py
trackler-2.0.8.20 tracks/python/exercises/accumulate/accumulate_test.py
trackler-2.0.8.19 tracks/python/exercises/accumulate/accumulate_test.py
trackler-2.0.8.18 tracks/python/exercises/accumulate/accumulate_test.py
trackler-2.0.8.17 tracks/python/exercises/accumulate/accumulate_test.py
trackler-2.0.8.16 tracks/python/exercises/accumulate/accumulate_test.py
trackler-2.0.8.15 tracks/python/exercises/accumulate/accumulate_test.py
trackler-2.0.8.14 tracks/python/exercises/accumulate/accumulate_test.py
trackler-2.0.8.13 tracks/python/exercises/accumulate/accumulate_test.py
trackler-2.0.8.12 tracks/python/exercises/accumulate/accumulate_test.py
trackler-2.0.8.11 tracks/python/exercises/accumulate/accumulate_test.py
trackler-2.0.8.10 tracks/python/exercises/accumulate/accumulate_test.py
trackler-2.0.8.9 tracks/python/exercises/accumulate/accumulate_test.py
trackler-2.0.8.8 tracks/python/exercises/accumulate/accumulate_test.py
trackler-2.0.8.7 tracks/python/exercises/accumulate/accumulate_test.py