Skip to content

Commit b988ba5

Browse files
alexpjohnsoncmccandless
authored andcommitted
flatten-array: add test template (exercism#2089)
1 parent 8fb0ae9 commit b988ba5

2 files changed

Lines changed: 23 additions & 16 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{%- import "generator_macros.j2" as macros with context -%}
2+
{{ macros.header() }}
3+
4+
class {{ exercise | camel_case }}Test(unittest.TestCase):
5+
{% for case in cases -%}
6+
def test_{{ case["description"] | to_snake }}(self):
7+
inputs = {{ case["input"]["array"] }}
8+
expected = {{ case["expected"] }}
9+
self.assertEqual({{ case["property"] }}(inputs), expected)
10+
11+
{% endfor %}
12+
13+
{{ macros.footer() }}

exercises/flatten-array/flatten_array_test.py

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,46 +2,40 @@
22

33
from flatten_array import flatten
44

5-
65
# Tests adapted from `problem-specifications//canonical-data.json` @ v1.2.0
76

8-
class FlattenArrayTest(unittest.TestCase):
97

8+
class FlattenArrayTest(unittest.TestCase):
109
def test_no_nesting(self):
11-
self.assertEqual(flatten([0, 1, 2]), [0, 1, 2])
10+
inputs = [0, 1, 2]
11+
expected = [0, 1, 2]
12+
self.assertEqual(flatten(inputs), expected)
1213

13-
def test_flatten_integers(self):
14+
def test_flattens_array_with_just_integers_present(self):
1415
inputs = [1, [2, 3, 4, 5, 6, 7], 8]
1516
expected = [1, 2, 3, 4, 5, 6, 7, 8]
1617
self.assertEqual(flatten(inputs), expected)
1718

18-
def test_five_level_nesting(self):
19+
def test_5_level_nesting(self):
1920
inputs = [0, 2, [[2, 3], 8, 100, 4, [[[50]]]], -2]
2021
expected = [0, 2, 2, 3, 8, 100, 4, 50, -2]
2122
self.assertEqual(flatten(inputs), expected)
2223

23-
def test_six_level_nesting(self):
24+
def test_6_level_nesting(self):
2425
inputs = [1, [2, [[3]], [4, [[5]]], 6, 7], 8]
2526
expected = [1, 2, 3, 4, 5, 6, 7, 8]
2627
self.assertEqual(flatten(inputs), expected)
2728

28-
def test_with_none_values(self):
29+
def test_6_level_nest_list_with_null_values(self):
2930
inputs = [0, 2, [[2, 3], 8, [[100]], None, [[None]]], -2]
3031
expected = [0, 2, 2, 3, 8, 100, -2]
3132
self.assertEqual(flatten(inputs), expected)
3233

33-
def test_all_values_are_none(self):
34+
def test_all_values_in_nested_list_are_null(self):
3435
inputs = [None, [[[None]]], None, None, [[None, None], None], None]
3536
expected = []
3637
self.assertEqual(flatten(inputs), expected)
3738

38-
# Additional tests for this track
39-
def test_empty_nested_lists(self):
40-
self.assertEqual(flatten([[()]]), [])
41-
42-
def test_strings(self):
43-
self.assertEqual(flatten(['0', ['1', '2']]), ['0', '1', '2'])
44-
4539

46-
if __name__ == '__main__':
40+
if __name__ == "__main__":
4741
unittest.main()

0 commit comments

Comments
 (0)