Example #1
0
def test_flatten():
    assert flatten([]) == []
    assert flatten([1, 2, [3, 5], [[4, 3], 2]]) == [1, 2, 3, 5, 4, 3, 2]
    assert flatten([
        [1, [5], [], [[-3, 'hi']]],
        'string',
        10,
        [[[5]]],
    ]) == [1, 5, -3, 'hi', 'string', 10, 5]
    assert flatten([1, 2, {'a': 1}, [3, 5], 2]) == [1, 2, {'a': 1}, 3, 5, 2]
Example #2
0
def test():
    a = [1, 2, [3]]
    res = flatten(a)

    assert res == [1, 2, 3]

    a = [1, [2, [3]]]
    res = flatten(a)

    assert res == [1, 2, 3]
Example #3
0
	def test_flatten_unnested(self):
		d = {"a": 1,"b": 2,"c": 3}
		expected = {"a": 1, "b": 2, "c": 3}
		self.assertEqual(flatten(d), expected, "wrong output")
Example #4
0
	def test_flatten_empty(self):
		self.assertEqual(flatten({}), {}, "wrong output")
Example #5
0
	def test_flatten_nested_and_unnested(self):
		d = {"a": {"b": {"c": 1}}, "d": 2}
		expected = {"a.b.c": 1, "d": 2}
		self.assertEqual(flatten(d), expected, "wrong output")
Example #6
0
	def test_flatten_longnested_and_unnestedattheend(self):
		d = {"a": {"b": {"c": {"d": {"e": 1, "f": 2, "g": 3}}}}}
		expected = {"a.b.c.d.e": 1, "a.b.c.d.f": 2, "a.b.c.d.g": 3}
		self.assertEqual(flatten(d), expected, "wrong output")
Example #7
0
	def test_flatten_longnested(self):
		d = {"a": {"b": {"c": {"d": {"e": 1}}}}}
		expected = {"a.b.c.d.e": 1}
		self.assertEqual(flatten(d), expected, "wrong output")
Example #8
0
def test_flatten(lst, expected):
    assert flatten(lst) == expected