Skip to content

flatten-array: update tests to v1.1.0 #1046

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 30, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 18 additions & 11 deletions exercises/flatten-array/flatten_array_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,42 @@
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_one_level_nesting(self):
self.assertEqual(flatten([0, [1], 2]), [0, 1, 2])

def test_two_level_nesting(self):
self.assertEqual(flatten([0, [1, [2, 3]], [4]]), [0, 1, 2, 3, 4])

def test_empty_nested_lists(self):
self.assertEqual(flatten([[()]]), [])
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_with_none_values(self):
inputs = [0, 2, [[2, 3], 8, [[100]], None, [[None]]], -2]
expected = [0, 2, 2, 3, 8, 100, -2]
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'])

Expand Down