Sha256: ded9385fefefa4336c187428bf0863ef9a5305b8dfc0cbc9f0a7066e1c51af06

Contents?: true

Size: 1.46 KB

Versions: 50

Compression:

Stored size: 1.46 KB

Contents

import unittest

from flatten_array import flatten


# Tests adapted from `problem-specifications//canonical-data.json` @ v1.1.0

class FlattenArrayTests(unittest.TestCase):

    def test_no_nesting(self):
        self.assertEqual(flatten([0, 1, 2]), [0, 1, 2])

    def test_flatten_integers(self):
        inputs = [1, [2, 3, 4, 5, 6, 7], 8]
        expected = [1, 2, 3, 4, 5, 6, 7, 8]
        self.assertEqual(flatten(inputs), expected)

    def test_five_level_nesting(self):
        inputs = [0, 2, [[2, 3], 8, 100, 4, [[[50]]]], -2]
        expected = [0, 2, 2, 3, 8, 100, 4, 50, -2]
        self.assertEqual(flatten(inputs), expected)

    def test_six_level_nesting(self):
        inputs = [1, [2, [[3]], [4, [[5]]], 6, 7], 8]
        expected = [1, 2, 3, 4, 5, 6, 7, 8]
        self.assertEqual(flatten(inputs), expected)

    def test_with_none_values(self):
        inputs = [0, 2, [[2, 3], 8, [[100]], None, [[None]]], -2]
        expected = [0, 2, 2, 3, 8, 100, -2]
        self.assertEqual(flatten(inputs), expected)

    def test_all_values_are_none(self):
        inputs = [None, [[[None]]], None, None, [[None, None], None], None]
        expected = []
        self.assertEqual(flatten(inputs), expected)

    # Additional tests for this track
    def test_empty_nested_lists(self):
        self.assertEqual(flatten([[()]]), [])

    def test_strings(self):
        self.assertEqual(flatten(['0', ['1', '2']]), ['0', '1', '2'])


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

Version data entries

50 entries across 50 versions & 1 rubygems

Version Path
trackler-2.2.1.105 tracks/python/exercises/flatten-array/flatten_array_test.py
trackler-2.2.1.104 tracks/python/exercises/flatten-array/flatten_array_test.py
trackler-2.2.1.103 tracks/python/exercises/flatten-array/flatten_array_test.py
trackler-2.2.1.102 tracks/python/exercises/flatten-array/flatten_array_test.py
trackler-2.2.1.101 tracks/python/exercises/flatten-array/flatten_array_test.py
trackler-2.2.1.100 tracks/python/exercises/flatten-array/flatten_array_test.py
trackler-2.2.1.99 tracks/python/exercises/flatten-array/flatten_array_test.py
trackler-2.2.1.98 tracks/python/exercises/flatten-array/flatten_array_test.py
trackler-2.2.1.97 tracks/python/exercises/flatten-array/flatten_array_test.py
trackler-2.2.1.96 tracks/python/exercises/flatten-array/flatten_array_test.py
trackler-2.2.1.95 tracks/python/exercises/flatten-array/flatten_array_test.py
trackler-2.2.1.94 tracks/python/exercises/flatten-array/flatten_array_test.py
trackler-2.2.1.93 tracks/python/exercises/flatten-array/flatten_array_test.py
trackler-2.2.1.92 tracks/python/exercises/flatten-array/flatten_array_test.py
trackler-2.2.1.91 tracks/python/exercises/flatten-array/flatten_array_test.py
trackler-2.2.1.90 tracks/python/exercises/flatten-array/flatten_array_test.py
trackler-2.2.1.89 tracks/python/exercises/flatten-array/flatten_array_test.py
trackler-2.2.1.88 tracks/python/exercises/flatten-array/flatten_array_test.py
trackler-2.2.1.87 tracks/python/exercises/flatten-array/flatten_array_test.py
trackler-2.2.1.86 tracks/python/exercises/flatten-array/flatten_array_test.py