Fix constrained_fuzz_bounds()
(#1490)
... for cases where the entire fuzz range is above `maximum`. Also improve hanling if the entire range is below `minimum` and readability.
This commit is contained in:
parent
311e70822d
commit
b1142c12d9
@ -151,12 +151,18 @@ impl<'a> StateContext<'a> {
|
|||||||
/// Ensure the upper bound is larger than the lower bound, if `maximum` allows
|
/// Ensure the upper bound is larger than the lower bound, if `maximum` allows
|
||||||
/// it and it is larger than 1.
|
/// it and it is larger than 1.
|
||||||
fn constrained_fuzz_bounds(interval: f32, minimum: u32, maximum: u32) -> (u32, u32) {
|
fn constrained_fuzz_bounds(interval: f32, minimum: u32, maximum: u32) -> (u32, u32) {
|
||||||
let (lower, mut upper) = fuzz_bounds(interval);
|
let (mut lower, mut upper) = fuzz_bounds(interval);
|
||||||
let lower = lower.max(minimum);
|
|
||||||
if upper == lower && upper != 1 {
|
// minimum <= maximum and lower <= upper are assumed
|
||||||
|
// now ensure minimum <= lower <= upper <= maximum
|
||||||
|
lower = lower.max(minimum).min(maximum);
|
||||||
|
upper = upper.max(minimum).min(maximum);
|
||||||
|
|
||||||
|
if upper == lower && upper > 1 && upper < maximum {
|
||||||
upper = lower + 1;
|
upper = lower + 1;
|
||||||
};
|
};
|
||||||
(lower, upper.min(maximum).max(lower))
|
|
||||||
|
(lower, upper)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fuzz_bounds(interval: f32) -> (u32, u32) {
|
fn fuzz_bounds(interval: f32) -> (u32, u32) {
|
||||||
|
@ -255,7 +255,7 @@ mod test {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn low_multiplier_fuzz() {
|
fn extreme_multiplier_fuzz() {
|
||||||
let mut ctx = StateContext::defaults_for_testing();
|
let mut ctx = StateContext::defaults_for_testing();
|
||||||
// our calculations should work correctly with a low ease or non-default multiplier
|
// our calculations should work correctly with a low ease or non-default multiplier
|
||||||
let state = ReviewState {
|
let state = ReviewState {
|
||||||
@ -272,6 +272,11 @@ mod test {
|
|||||||
ctx.interval_multiplier = 0.1;
|
ctx.interval_multiplier = 0.1;
|
||||||
assert_eq!(state.passing_review_intervals(&ctx), (2, 3, 4));
|
assert_eq!(state.passing_review_intervals(&ctx), (2, 3, 4));
|
||||||
ctx.fuzz_factor = Some(0.99);
|
ctx.fuzz_factor = Some(0.99);
|
||||||
assert_eq!(state.passing_review_intervals(&ctx), (2, 3, 4));
|
assert_eq!(state.passing_review_intervals(&ctx), (3, 5, 7));
|
||||||
|
|
||||||
|
// maximum must be respected no matter what
|
||||||
|
ctx.interval_multiplier = 10.0;
|
||||||
|
ctx.maximum_review_interval = 5;
|
||||||
|
assert_eq!(state.passing_review_intervals(&ctx), (5, 5, 5));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user