@@ -14,3 +14,38 @@ def test_flatten_random_types():
1414 flattened = list (flatten (l ))
1515 expected = ["hi" , - 80 , "c" , 0.0 , (3 , 3 ), dictionary , 6 , 5 , 4 , 3 , 2 , 1 , 0 ]
1616 assert flattened == expected
17+
18+
19+ def test_flatten_with_depth_0 ():
20+ # Test with depth=0 (no flattening)
21+ input_ = [1 , [2 , [3 , [4 , 5 ]]]]
22+ assert list (flatten (input_ , depth = 0 )) == input_
23+
24+
25+ def test_flatten_with_depth_2 ():
26+ # Test with depth=2
27+ input_ = [1 , [2 , [3 , [4 , 5 ]]]]
28+ expected = [1 , 2 , 3 , [4 , 5 ]]
29+ assert list (flatten (input_ , depth = 2 )) == expected
30+
31+
32+ def test_flatten_with_depth_greater_than_needed ():
33+ # Test with depth larger than needed
34+ input_ = [1 , [2 , [3 , [4 , 5 ]]]]
35+ expected = [1 , 2 , 3 , 4 , 5 ]
36+ assert list (flatten (input_ , depth = 10 )) == expected
37+
38+
39+ def test_flatten_with_empty_lists ():
40+ # Test with empty lists at different levels
41+ input_ = [[], [1 , [2 , [], [3 , []]], 4 ], []]
42+ assert list (flatten (input_ , depth = 1 )) == [1 , [2 , [], [3 , []]], 4 ]
43+ assert list (flatten (input_ , depth = 2 )) == [1 , 2 , [], [3 , []], 4 ]
44+ assert list (flatten (input_ )) == [1 , 2 , 3 , 4 ]
45+
46+
47+ def test_flatten_non_list_input ():
48+ # Test with non-list input
49+ assert list (flatten (42 )) == [42 ]
50+ assert list (flatten ("hello" )) == ["hello" ]
51+ assert list (flatten (None )) == [None ]
0 commit comments