1111from numpy .typing import NDArray
1212
1313
14- def reference_solution_exercise2 (my_list : List [int ], k : int ):
14+ def reference_exercise2 (my_list : List [int ], k : int ) -> List [ int ] :
1515 return [i for i in my_list if i % k == 0 ]
1616
1717
@@ -24,7 +24,7 @@ def check_for_loop_in_body(fun: Callable) -> bool:
2424 return False
2525
2626
27- def reference_solution_filter_even (my_list : "list [int]" ) -> "list [int]" :
27+ def reference_filter_even (my_list : List [int ]) -> List [int ]:
2828 return list (filter (lambda x : x % 2 == 0 , my_list ))
2929
3030
@@ -39,15 +39,15 @@ def reference_solution_filter_even(my_list: "list[int]") -> "list[int]":
3939def test_filter_even (function_to_test : Callable , my_list : List [int ]):
4040 res = function_to_test (my_list )
4141 assert type (res ) == list , "The function you wrote does not return a list"
42- assert res == reference_solution_filter_even (
42+ assert res == reference_filter_even (
4343 my_list
4444 ), "The list you return is not equal to the expected solution"
4545 assert not check_for_loop_in_body (
4646 function_to_test
4747 ), "You are not allowed to use a for loop in this exercise"
4848
4949
50- def reference_solution_add_one (my_list : List [int ]) -> List [int ]:
50+ def reference_add_one (my_list : List [int ]) -> List [int ]:
5151 return list (map (lambda x : x + 1 , my_list )) # noqa: C417
5252
5353
@@ -60,7 +60,7 @@ def reference_solution_add_one(my_list: List[int]) -> List[int]:
6060 ],
6161)
6262def test_add_one (function_to_test : Callable , my_list : List [int ]):
63- assert function_to_test (my_list ) == reference_solution_add_one (
63+ assert function_to_test (my_list ) == reference_add_one (
6464 my_list
6565 ), "The list you return is not equal to the expected solution"
6666 assert not check_for_loop_in_body (
@@ -76,14 +76,14 @@ def test_add_one(function_to_test: Callable, my_list: List[int]):
7676 ],
7777)
7878def test_exercise2 (
79- function_to_test : Callable [[int , int ], int ],
79+ function_to_test : Callable [[List [ int ] ], int ],
8080 my_list : List [int ],
8181 k : int ,
8282):
83- assert function_to_test (my_list , k ) == reference_solution_exercise2 (my_list , k )
83+ assert function_to_test (my_list , k ) == reference_exercise2 (my_list , k )
8484
8585
86- def reference_solution_exercise3 (x : List [List [int ]]) -> List [List [int ]]:
86+ def reference_exercise3 (x : List [List [int ]]) -> List [List [int ]]:
8787 return [list (i ) for i in zip (* x )]
8888
8989
@@ -96,28 +96,27 @@ def test_exercise3(
9696):
9797 res = function_to_test (my_input .tolist ())
9898 assert (
99- res == reference_solution_exercise3 (my_input .tolist ())
99+ res == reference_exercise3 (my_input .tolist ())
100100 and res == my_input .transpose ().tolist ()
101101 )
102102
103103
104- def reference_solution_exercise4 (my_list : List [List [Any ]]) -> List [Any ]:
104+ def reference_exercise4 (my_list : List [List [Any ]]) -> List [Any ]:
105105 return functools .reduce (lambda x , y : x + y , my_list )
106106
107107
108108@pytest .mark .parametrize (
109- "my_input, reference_func " ,
109+ "my_input" ,
110110 [
111- ( [[1 , 2 , 3 , 4 ], [4 , 5 , 5 ], [4 , 5 , 6 ]], reference_solution_exercise4 ) ,
112- ( [["a" , "b" , "c" ], ["d" , "f" , "e" ], ["another" ]], reference_solution_exercise4 ) ,
111+ [[1 , 2 , 3 , 4 ], [4 , 5 , 5 ], [4 , 5 , 6 ]],
112+ [["a" , "b" , "c" ], ["d" , "f" , "e" ], ["another" ]],
113113 ],
114114)
115115def test_exercise4 (
116- function_to_test : Callable [[List [List [any ]]], List [Any ]],
116+ function_to_test : Callable [[List [List [Any ]]], List [Any ]],
117117 my_input : List [List [Any ]],
118- reference_func : Callable ,
119118):
120- assert function_to_test (my_input ) == reference_func (my_input )
119+ assert function_to_test (my_input ) == reference_exercise4 (my_input )
121120
122121
123122@functools .lru_cache
@@ -126,7 +125,7 @@ def get_data_exercise5() -> List[str]:
126125 return words .splitlines ()
127126
128127
129- def reference_solution_exercise5 (w : List [str ]) -> List [Tuple [str , int ]]:
128+ def reference_exercise5 (w : List [str ]) -> List [Tuple [str , int ]]:
130129 return [
131130 (k , len (list (v )))
132131 for k , v in itertools .groupby (sorted (w , key = lambda x : x [0 ]), key = lambda x : x [0 ])
@@ -135,21 +134,19 @@ def reference_solution_exercise5(w: List[str]) -> List[Tuple[str, int]]:
135134
136135def test_exercise5 (function_to_test : Callable [[List [str ]], List [Tuple [str , int ]]]):
137136 data = get_data_exercise5 ()
138- assert function_to_test (data ) == reference_solution_exercise5 (data )
137+ assert function_to_test (data ) == reference_exercise5 (data )
139138
140139
141- def reference_solution_exercise6 (
142- my_list : List [Tuple [str , int ]]
143- ) -> List [Tuple [str , float ]]:
140+ def reference_exercise6 (my_list : List [Tuple [str , int ]]) -> List [Tuple [str , float ]]:
144141 total = sum (map (lambda x : x [1 ], my_list )) # noqa: C417
145142 return [(letter , freq / total ) for letter , freq in my_list ]
146143
147144
148145def test_exercise6 (
149146 function_to_test : Callable [[List [Tuple [str , int ]]], List [Tuple [str , float ]]]
150147):
151- input_data = reference_solution_exercise5 (get_data_exercise5 ())
152- assert function_to_test (input_data ) == reference_solution_exercise6 (input_data )
148+ input_data = reference_exercise5 (get_data_exercise5 ())
149+ assert function_to_test (input_data ) == reference_exercise6 (input_data )
153150
154151
155152def reference_function_exercise7 (my_list : List [str ]) -> List [str ]:
0 commit comments