From de50326b6cb287a897c107c76ad02023c550bf7e Mon Sep 17 00:00:00 2001 From: Thomas Date: Sun, 29 Dec 2024 16:05:59 +0000 Subject: [PATCH] Fixes type bug where difficulty became an int if it exceeded the thresholds. --- pyproject.toml | 2 +- src/fsrs/fsrs.py | 4 ++-- tests/test_fsrs.py | 15 +++++++++++++++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 8470b69..ffe80f8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "fsrs" -version = "4.1.1" +version = "4.1.2" description = "Free Spaced Repetition Scheduler" readme = "README.md" authors = [{ name = "Jarrett Ye", email = "jarrett.ye@outlook.com" }] diff --git a/src/fsrs/fsrs.py b/src/fsrs/fsrs.py index 02fdd2c..4b9ffe3 100644 --- a/src/fsrs/fsrs.py +++ b/src/fsrs/fsrs.py @@ -663,7 +663,7 @@ def _initial_difficulty(self, rating: Rating) -> float: ) # bound initial_difficulty between 1 and 10 - initial_difficulty = min(max(initial_difficulty, 1), 10) + initial_difficulty = min(max(initial_difficulty, 1.0), 10.0) return initial_difficulty @@ -704,7 +704,7 @@ def _mean_reversion(arg_1: float, arg_2: float) -> float: next_difficulty = _mean_reversion(arg_1=arg_1, arg_2=arg_2) # bound next_difficulty between 1 and 10 - next_difficulty = min(max(next_difficulty, 1), 10) + next_difficulty = min(max(next_difficulty, 1.0), 10.0) return next_difficulty diff --git a/tests/test_fsrs.py b/tests/test_fsrs.py index 1fa133c..6c1838e 100644 --- a/tests/test_fsrs.py +++ b/tests/test_fsrs.py @@ -55,6 +55,21 @@ def test_review_card(self): 142, ] + def test_repeated_correct_reviews(self): + scheduler = Scheduler(enable_fuzzing=False) + + card = Card() + review_datetimes = [ + datetime(2022, 11, 29, 12, 30, 0, i, timezone.utc) for i in range(10) + ] + + for review_datetime in review_datetimes: + card, _ = scheduler.review_card( + card=card, rating=Rating.Easy, review_datetime=review_datetime + ) + + assert card.difficulty == 1.0 + def test_memo_state(self): scheduler = Scheduler()