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]
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]
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")
def test_flatten_empty(self): self.assertEqual(flatten({}), {}, "wrong output")
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")
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")
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")
def test_flatten(lst, expected): assert flatten(lst) == expected