Fix new limit being decremented unduly (#2447)

This commit is contained in:
RumovZ 2023-03-18 02:48:50 +01:00 committed by GitHub
parent 146bed12d9
commit 662dbbd4ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 5 deletions

View File

@ -155,11 +155,14 @@ impl RemainingLimits {
/// True if some limit was decremented to 0.
fn decrement(&mut self, kind: LimitKind) -> DecrementResult {
let before = *self;
if matches!(kind, LimitKind::Review) {
self.review = self.review.saturating_sub(1);
}
if self.cap_new_to_review || matches!(kind, LimitKind::New) {
self.new = self.new.saturating_sub(1);
match kind {
LimitKind::Review => {
self.review = self.review.saturating_sub(1);
if self.cap_new_to_review {
self.new = self.new.min(self.review);
}
}
LimitKind::New => self.new = self.new.saturating_sub(1),
}
DecrementResult::new(&before, self)
}

View File

@ -490,4 +490,14 @@ mod test {
// review limit doesn't apply to new card
assert_eq!(col.card_queue_len(), 1);
}
#[test]
fn reviews_dont_affect_new_limit_before_review_limit_is_reached() {
let mut col = Collection::new_v3();
col.update_default_deck_config(|config| {
config.new_per_day = 1;
});
CardAdder::new().siblings(2).due_dates(["0"]).add(&mut col);
assert_eq!(col.card_queue_len(), 2);
}
}