Skip to content

Commit

Permalink
Add some unit tests
Browse files Browse the repository at this point in the history
Covers most of the cases encountered in ankitects#3639
  • Loading branch information
user1823 authored Dec 28, 2024
1 parent 9d1be9a commit bc91f31
Showing 1 changed file with 68 additions and 1 deletion.
69 changes: 68 additions & 1 deletion rslib/src/scheduler/fsrs/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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]
Expand Down Expand Up @@ -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
);
}
}

0 comments on commit bc91f31

Please sign in to comment.