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