clamp interval before fuzz_bounds (#3024)

* clamp interval before fuzz_bounds

* update unit test of with_review_fuzz
This commit is contained in:
Jarrett Ye 2024-02-25 13:18:01 +08:00 committed by GitHub
parent 68b374e65f
commit 103ea6ded0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -77,6 +77,7 @@ pub(crate) fn with_review_fuzz(
/// 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 interval = interval.clamp(minimum as f32, maximum as f32);
let (mut lower, mut upper) = fuzz_bounds(interval);
// minimum <= maximum and lower <= upper are assumed
@ -164,8 +165,8 @@ mod test {
assert_lower_middle_upper!(20.1, 3, 1000, 17, 20, 23);
// respect limits and preserve uniform distribution of valid intervals
assert_lower_middle_upper!(100.0, 101, 1000, 101, 104, 107);
assert_lower_middle_upper!(100.0, 1, 99, 93, 96, 99);
assert_lower_middle_upper!(100.0, 101, 1000, 101, 105, 108);
assert_lower_middle_upper!(100.0, 1, 99, 92, 96, 99);
assert_lower_middle_upper!(100.0, 97, 103, 97, 100, 103);
}