Fix crash when using FSRS with a low max interval setting
This commit is contained in:
parent
91538518b3
commit
b8ec76fb66
@ -46,6 +46,7 @@ impl<'a> StateContext<'a> {
|
||||
/// Ensure the upper bound is larger than the lower bound, if `maximum` allows
|
||||
/// it and it is larger than 1.
|
||||
fn constrained_fuzz_bounds(interval: f32, minimum: u32, maximum: u32) -> (u32, u32) {
|
||||
let minimum = minimum.min(maximum);
|
||||
let (mut lower, mut upper) = fuzz_bounds(interval);
|
||||
|
||||
// minimum <= maximum and lower <= upper are assumed
|
||||
@ -137,4 +138,9 @@ mod test {
|
||||
assert_lower_middle_upper!(100.0, 1, 99, 93, 96, 99);
|
||||
assert_lower_middle_upper!(100.0, 97, 103, 97, 100, 103);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn invalid_values_will_not_panic() {
|
||||
constrained_fuzz_bounds(1.0, 3, 2);
|
||||
}
|
||||
}
|
||||
|
@ -84,7 +84,8 @@ impl LearnState {
|
||||
fn answer_easy(self, ctx: &StateContext) -> ReviewState {
|
||||
let (mut minimum, maximum) = ctx.min_and_max_review_intervals(1);
|
||||
let interval = if let Some(states) = &ctx.fsrs_next_states {
|
||||
minimum = states.good.interval + 1;
|
||||
let good = ctx.with_review_fuzz(states.good.interval as f32, minimum, maximum);
|
||||
minimum = good + 1;
|
||||
states.easy.interval
|
||||
} else {
|
||||
ctx.graduating_interval_easy
|
||||
|
Loading…
Reference in New Issue
Block a user