From bc91f31b796f577e0b7aa4603ef6d03945090044 Mon Sep 17 00:00:00 2001 From: user1823 <92206575+user1823@users.noreply.github.com> Date: Sat, 28 Dec 2024 17:50:41 +0530 Subject: [PATCH 1/6] Add some unit tests Covers most of the cases encountered in https://github.com/ankitects/anki/pull/3639 --- rslib/src/scheduler/fsrs/params.rs | 69 +++++++++++++++++++++++++++++- 1 file changed, 68 insertions(+), 1 deletion(-) diff --git a/rslib/src/scheduler/fsrs/params.rs b/rslib/src/scheduler/fsrs/params.rs index 1b282b0fb0..2ea499666d 100644 --- a/rslib/src/scheduler/fsrs/params.rs +++ b/rslib/src/scheduler/fsrs/params.rs @@ -545,11 +545,11 @@ pub(crate) mod tests { #[test] fn card_reset_drops_all_previous_history() { + // If Reset comes in between two Learn entries, only the ones after the Reset are used. assert_eq!( convert( &[ revlog(RevlogReviewKind::Learning, 10), - revlog(RevlogReviewKind::Review, 9), RevlogEntry { ease_factor: 0, ..revlog(RevlogReviewKind::Manual, 7) @@ -561,6 +561,57 @@ pub(crate) mod tests { ), fsrs_items!([review(0), review(4)]) ); + // Return None if Reset is the last entry or is followed by only manual entries. + assert_eq!( + convert( + &[ + revlog(RevlogReviewKind::Learning, 10), + revlog(RevlogReviewKind::Review, 9), + RevlogEntry { + ease_factor: 0, + ..revlog(RevlogReviewKind::Manual, 7) + }, + RevlogEntry { + ease_factor: 100, + ..revlog(RevlogReviewKind::Manual, 7) + }, + ], + true, + ), + None, + ); + // If non-learning user-graded entries are found after Reset, return None during training but return the remaining entries during memory state calculation. + assert_eq!( + convert( + &[ + revlog(RevlogReviewKind::Learning, 10), + revlog(RevlogReviewKind::Review, 9), + RevlogEntry { + ease_factor: 0, + ..revlog(RevlogReviewKind::Manual, 7) + }, + revlog(RevlogReviewKind::Review, 1), + revlog(RevlogReviewKind::Relearning, 0), + ], + true, + ), + None, + ); + assert_eq!( + convert( + &[ + revlog(RevlogReviewKind::Review, 9), + RevlogEntry { + ease_factor: 0, + ..revlog(RevlogReviewKind::Manual, 7) + }, + revlog(RevlogReviewKind::Review, 1), + revlog(RevlogReviewKind::Relearning, 0), + ], + false, + ), + fsrs_items!([review(0), review(1)]) + ); } #[test] @@ -636,4 +687,20 @@ pub(crate) mod tests { convert(revlogs, false) ); } + + #[test] + fn even_if_no_learning_steps_ignore_reviews_before_during_reviewing() { + let revlogs = &[ + revlog(RevlogReviewKind::Review, 10), + revlog(RevlogReviewKind::Review, 8), + revlog(RevlogReviewKind::Review, 6), + ]; + // R | R R + assert_eq!( + convert_ignore_before(revlogs, false, days_ago_ms(9)) + .unwrap() + .len(), + 2 + ); + } } From f2463c5d934e08d3a1a9eddfae76ce5028af11d2 Mon Sep 17 00:00:00 2001 From: user1823 <92206575+user1823@users.noreply.github.com> Date: Sat, 28 Dec 2024 17:53:47 +0530 Subject: [PATCH 2/6] Format --- rslib/src/scheduler/fsrs/params.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/rslib/src/scheduler/fsrs/params.rs b/rslib/src/scheduler/fsrs/params.rs index 2ea499666d..c92f439f74 100644 --- a/rslib/src/scheduler/fsrs/params.rs +++ b/rslib/src/scheduler/fsrs/params.rs @@ -545,7 +545,8 @@ pub(crate) mod tests { #[test] fn card_reset_drops_all_previous_history() { - // If Reset comes in between two Learn entries, only the ones after the Reset are used. + // If Reset comes in between two Learn entries, only the ones after the Reset + // are used. assert_eq!( convert( &[ @@ -580,7 +581,8 @@ pub(crate) mod tests { ), None, ); - // If non-learning user-graded entries are found after Reset, return None during training but return the remaining entries during memory state calculation. + // If non-learning user-graded entries are found after Reset, return None during + // training but return the remaining entries during memory state calculation. assert_eq!( convert( &[ From eaa8ba613f311f7c38592045475c03075d355966 Mon Sep 17 00:00:00 2001 From: user1823 <92206575+user1823@users.noreply.github.com> Date: Sat, 28 Dec 2024 18:21:48 +0530 Subject: [PATCH 3/6] Update params.rs Makes the test more robust. --- rslib/src/scheduler/fsrs/params.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rslib/src/scheduler/fsrs/params.rs b/rslib/src/scheduler/fsrs/params.rs index c92f439f74..ac5001de3b 100644 --- a/rslib/src/scheduler/fsrs/params.rs +++ b/rslib/src/scheduler/fsrs/params.rs @@ -577,7 +577,7 @@ pub(crate) mod tests { ..revlog(RevlogReviewKind::Manual, 7) }, ], - true, + false, ), None, ); From fbcba289f387093182875f45fc6389501e886df8 Mon Sep 17 00:00:00 2001 From: user1823 <92206575+user1823@users.noreply.github.com> Date: Wed, 1 Jan 2025 14:09:08 +0530 Subject: [PATCH 4/6] Update params.rs When training, the first FSRS item is removed. That's why none of the other tests includes it. Co-authored-by: Jarrett Ye --- rslib/src/scheduler/fsrs/params.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rslib/src/scheduler/fsrs/params.rs b/rslib/src/scheduler/fsrs/params.rs index ac5001de3b..9b6a5d56e4 100644 --- a/rslib/src/scheduler/fsrs/params.rs +++ b/rslib/src/scheduler/fsrs/params.rs @@ -612,7 +612,7 @@ pub(crate) mod tests { ], false, ), - fsrs_items!([review(0), review(1)]) + fsrs_items!([review(0)], [review(0), review(1)]) ); } From 0b8ef7bf74de537790406840219616effd2b3535 Mon Sep 17 00:00:00 2001 From: user1823 <92206575+user1823@users.noreply.github.com> Date: Fri, 3 Jan 2025 00:43:32 +0530 Subject: [PATCH 5/6] Improve naming --- rslib/src/scheduler/fsrs/params.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rslib/src/scheduler/fsrs/params.rs b/rslib/src/scheduler/fsrs/params.rs index 9b6a5d56e4..9022f2bd66 100644 --- a/rslib/src/scheduler/fsrs/params.rs +++ b/rslib/src/scheduler/fsrs/params.rs @@ -691,7 +691,7 @@ pub(crate) mod tests { } #[test] - fn even_if_no_learning_steps_ignore_reviews_before_during_reviewing() { + fn handle_ignore_before_when_no_learning_steps()() { let revlogs = &[ revlog(RevlogReviewKind::Review, 10), revlog(RevlogReviewKind::Review, 8), From f25029e5fb5043f128549ac6d3cd0c8106cfdd2c Mon Sep 17 00:00:00 2001 From: user1823 <92206575+user1823@users.noreply.github.com> Date: Fri, 3 Jan 2025 00:44:47 +0530 Subject: [PATCH 6/6] Fix typo --- rslib/src/scheduler/fsrs/params.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rslib/src/scheduler/fsrs/params.rs b/rslib/src/scheduler/fsrs/params.rs index 9022f2bd66..d7bff84416 100644 --- a/rslib/src/scheduler/fsrs/params.rs +++ b/rslib/src/scheduler/fsrs/params.rs @@ -691,7 +691,7 @@ pub(crate) mod tests { } #[test] - fn handle_ignore_before_when_no_learning_steps()() { + fn handle_ignore_before_when_no_learning_steps() { let revlogs = &[ revlog(RevlogReviewKind::Review, 10), revlog(RevlogReviewKind::Review, 8),