Skip to content

Commit 56e414d

Browse files
SerAceropre-commit-ci[bot]edoardob90
authored
Fix solution to exercise 3 of Functional Programming (#313)
* fix solution of exercise 3 * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fix type hints --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Edoardo Baldi <edoardo.baldi@empa.ch>
1 parent 410228a commit 56e414d

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

tutorial/tests/test_11_functional_programming.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def reference_multiples_of_n(my_list: list[int], k: int) -> list[int]:
142142
],
143143
)
144144
def test_multiples_of_n(
145-
function_to_test: Callable[[list[int]], int],
145+
function_to_test: Callable[[list[int], int], int],
146146
my_list: list[int],
147147
k: int,
148148
):
@@ -163,7 +163,8 @@ def reference_exercise1(matrix: list[list[int]]) -> list[list[int]]:
163163
[(np.eye(3)), (np.random.randint(0, 100, size=(4, 4)))],
164164
)
165165
def test_exercise1(
166-
function_to_test: Callable[[list[list[int]]], list[list[int]]], my_input: NDArray
166+
function_to_test: Callable[[list[list[int]]], list[list[int]]],
167+
my_input: NDArray,
167168
):
168169
res = function_to_test(my_input.tolist())
169170
assert (
@@ -210,12 +211,14 @@ def reference_exercise3(words: list[str]) -> list[tuple[str, int]]:
210211
return [
211212
(k, len(list(v)))
212213
for k, v in itertools.groupby(
213-
sorted(words, key=lambda x: x[0]), key=lambda x: x[0]
214+
sorted(words, key=lambda x: x.lower()[0]), key=lambda x: x.lower()[0]
214215
)
215216
]
216217

217218

218-
def test_exercise3(function_to_test: Callable[[list[str]], list[tuple[str, int]]]):
219+
def test_exercise3(
220+
function_to_test: Callable[[list[str]], list[tuple[str, int]]],
221+
):
219222
data = get_data_exercise3()
220223
assert function_to_test(data) == reference_exercise3(data)
221224

@@ -225,7 +228,9 @@ def test_exercise3(function_to_test: Callable[[list[str]], list[tuple[str, int]]
225228
#
226229

227230

228-
def reference_exercise4(my_list: list[tuple[str, int]]) -> list[tuple[str, float]]:
231+
def reference_exercise4(
232+
my_list: list[tuple[str, int]],
233+
) -> list[tuple[str, float]]:
229234
total = sum(map(lambda x: x[1], my_list)) # noqa: C417
230235
return [(letter, freq / total) for letter, freq in my_list]
231236

0 commit comments

Comments
 (0)