mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 22:42:25 -04:00
fix underflow in fuzz code, leading to large intervals
https://forums.ankiweb.net/t/buried-cards-in-ankimobile-beta-20081-3/14753
This commit is contained in:
parent
0efa3f944f
commit
044d253306
2 changed files with 22 additions and 1 deletions
|
@ -156,7 +156,7 @@ fn constrained_fuzz_bounds(interval: f32, minimum: u32, maximum: u32) -> (u32, u
|
||||||
if upper == lower && upper != 1 {
|
if upper == lower && upper != 1 {
|
||||||
upper = lower + 1;
|
upper = lower + 1;
|
||||||
};
|
};
|
||||||
(lower, upper.min(maximum))
|
(lower, upper.min(maximum).max(lower))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fuzz_bounds(interval: f32) -> (u32, u32) {
|
fn fuzz_bounds(interval: f32) -> (u32, u32) {
|
||||||
|
|
|
@ -253,4 +253,25 @@ mod test {
|
||||||
assert!(leech_threshold_met(2, 1));
|
assert!(leech_threshold_met(2, 1));
|
||||||
assert!(leech_threshold_met(3, 1));
|
assert!(leech_threshold_met(3, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn low_multiplier_fuzz() {
|
||||||
|
let mut ctx = StateContext::defaults_for_testing();
|
||||||
|
// our calculations should work correctly with a low ease or non-default multiplier
|
||||||
|
let state = ReviewState {
|
||||||
|
scheduled_days: 1,
|
||||||
|
elapsed_days: 1,
|
||||||
|
ease_factor: 1.3,
|
||||||
|
lapses: 0,
|
||||||
|
leeched: false,
|
||||||
|
};
|
||||||
|
ctx.fuzz_factor = Some(0.0);
|
||||||
|
assert_eq!(state.passing_review_intervals(&ctx), (2, 3, 4));
|
||||||
|
|
||||||
|
// this is a silly multiplier, but it shouldn't underflow
|
||||||
|
ctx.interval_multiplier = 0.1;
|
||||||
|
assert_eq!(state.passing_review_intervals(&ctx), (2, 3, 4));
|
||||||
|
ctx.fuzz_factor = Some(0.99);
|
||||||
|
assert_eq!(state.passing_review_intervals(&ctx), (2, 3, 4));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue