From 3b9b1903d1b0d1b094ec1a692d0238188d4b0920 Mon Sep 17 00:00:00 2001 From: Tom Amberson Date: Thu, 31 Oct 2024 10:32:24 -0600 Subject: [PATCH] fix: mark answer in ReviewSession.process_answer instead of Question.solve --- hebikani/hebikani.py | 7 ++----- tests/test_hebikani.py | 15 +++++++++++---- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/hebikani/hebikani.py b/hebikani/hebikani.py index bc346d2..bd0eb19 100755 --- a/hebikani/hebikani.py +++ b/hebikani/hebikani.py @@ -1064,11 +1064,6 @@ def solve(self, inputed_answer: str, hard_mode: bool = False) -> AnswerType: AnswerType.INEXACT if _answer == AnswerType.CORRECT else _answer ) - if _answer == AnswerType.INCORRECT: - self.wrong_answer_count += 1 - elif _answer == AnswerType.CORRECT: - self.solved = True - return _answer def add_wrong_answer(self): @@ -1296,6 +1291,7 @@ def process_answer(self, question: Question, answer_type: AnswerType): if answer_type == AnswerType.CORRECT: print("\nCorrect!") self.nb_correct_answers += 1 + question.solved = True # If the user is a bit off, we show the correct answer and ask # to validate his answer @@ -1343,6 +1339,7 @@ def process_answer(self, question: Question, answer_type: AnswerType): if answer_was_correct not in ["y", "Y"]: self.nb_incorrect_answers += 1 + question.add_wrong_answer() self.queue.shuffle() # Add the question at the end of the queue # So we don't have it twice in a row. diff --git a/tests/test_hebikani.py b/tests/test_hebikani.py index da73814..b429fc6 100644 --- a/tests/test_hebikani.py +++ b/tests/test_hebikani.py @@ -419,10 +419,15 @@ def test_card_is_solved(): subject = Subject(vocabulary_subject) # To avoid making a query online to get the kanji auxiliaries Cache.subjects[440] = subject + client = Client(API_KEY) + session = ReviewSession(client, [subject]) + assert subject.solved is False - subject.meaning_question.solve("one") - subject.reading_question.solve("いち") + answer_type = subject.meaning_question.solve("one") + session.process_answer(subject.meaning_question, answer_type) + answer_type = subject.reading_question.solve("いち") + session.process_answer(subject.reading_question, answer_type) assert subject.solved is True @@ -430,8 +435,10 @@ def test_card_is_solved(): assert subject.solved is False - subject.meaning_question.solve("hello") - subject.reading_question.solve("いち") + answer_type = subject.meaning_question.solve("hello") + session.process_answer(subject.meaning_question, answer_type) + answer_type = subject.reading_question.solve("いち") + session.process_answer(subject.reading_question, answer_type) assert subject.solved is False Cache.subjects = {}