Skip to content

Commit

Permalink
Add some unit tests (#3678)
Browse files Browse the repository at this point in the history
* Add some unit tests

Covers most of the cases encountered in #3639

* Format

* Update params.rs

Makes the test more robust.

* 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 <[email protected]>

* Improve naming

* Fix typo

---------

Co-authored-by: Jarrett Ye <[email protected]>
  • Loading branch information
user1823 and L-M-Sherlock authored Jan 4, 2025
1 parent 9d1be9a commit 7fa544d
Showing 1 changed file with 70 additions and 1 deletion.
71 changes: 70 additions & 1 deletion rslib/src/scheduler/fsrs/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -545,11 +545,12 @@ 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 +562,58 @@ 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)
},
],
false,
),
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(0), review(1)])
);
}

#[test]
Expand Down Expand Up @@ -636,4 +689,20 @@ pub(crate) mod tests {
convert(revlogs, false)
);
}

#[test]
fn handle_ignore_before_when_no_learning_steps() {
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 7fa544d

Please sign in to comment.