From ef8407df1947e359c4b3b8ce84803e0072c36b43 Mon Sep 17 00:00:00 2001 From: edoardob90 Date: Tue, 11 Jul 2023 14:06:00 +0200 Subject: [PATCH] Fix bug in test to ex. 4 --- input_output.ipynb | 6 +++--- tutorial/tests/data/{english.csv => english.txt} | 0 tutorial/tests/test_input_output.py | 14 +++++++------- 3 files changed, 10 insertions(+), 10 deletions(-) rename tutorial/tests/data/{english.csv => english.txt} (100%) diff --git a/input_output.ipynb b/input_output.ipynb index 3735a000..f0bc31c5 100644 --- a/input_output.ipynb +++ b/input_output.ipynb @@ -1216,9 +1216,9 @@ "tags": [] }, "source": [ - "Write a function which takes the words from the `english.csv` and translates them to italian using the dictionary file `dict.csv`. The output should be a **list of tuples** with the pair `italian, english` if the word is found and nothing otherwise.\n", + "Write a function which takes the words from the file `english.txt` and translates them to Italian using the dictionary file `dict.csv`. The output should be a **list of tuples** with the pair `italian, english` if the word is found and nothing otherwise.\n", "\n", - "For example, given the `english.csv` file:\n", + "For example, given the `english.txt` file:\n", "\n", "```\n", "bread\n", @@ -1244,7 +1244,7 @@ " Try to avoid loading the dictionary more than once. \"Dictionary file\" should suggest you the correct Python data structure to use to store the translations.\n", " \n", "
  • \n", - " The path to the input file english.csv is available as the argument english of the function solution_exercise4, the file dict.csv as the argument dictionary.\n", + " The path to the input file english.txt is available as the argument english of the function solution_exercise4, the file dict.csv as the argument dictionary.\n", "
  • \n", " \n", "
    \n" diff --git a/tutorial/tests/data/english.csv b/tutorial/tests/data/english.txt similarity index 100% rename from tutorial/tests/data/english.csv rename to tutorial/tests/data/english.txt diff --git a/tutorial/tests/test_input_output.py b/tutorial/tests/test_input_output.py index e6b69afb..8fd18970 100644 --- a/tutorial/tests/test_input_output.py +++ b/tutorial/tests/test_input_output.py @@ -139,20 +139,20 @@ def test_exercise3(function_to_test): def reference_solution_exercise4( english: pl.Path, dictionary: pl.Path ) -> list[tuple[str, str]]: - with english.open("r") as english_file: - english_reader = csv.reader(english_file) - english_words = [w for w, _ in english_reader] + english_words = english.read_text().splitlines() with dictionary.open("r") as dict_file: dict_reader = csv.reader(dict_file) - next(dict_reader) - translations = {en: it for _, it, en, _ in dict_reader} + next(dict_reader) # skip header + translations = {en: it for _, it, en in dict_reader} - return [(e, translations[e]) for e in english_words if e in translations.keys()] + return [ + (word, translations[word]) for word in english_words if word in translations + ] def test_exercise4(function_to_test): - words = get_data("english.csv") + words = get_data("english.txt") dictionary = get_data("dict.csv") assert function_to_test(words, dictionary) == reference_solution_exercise4( words, dictionary