Skip to content

Commit

Permalink
Discard test data which cause clamp to panic
Browse files Browse the repository at this point in the history
  • Loading branch information
jacg committed Oct 27, 2023
1 parent 053bb36 commit bfe70fc
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions src/tests/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,10 +373,16 @@ mod float {
}

#[allow(trivial_casts)]
fn clamp(x: A<V>, min: A<V>, max: A<V>) -> bool {
Test::eq(
&Length::new::<meter>(x.clamp(*min, *max)),
&Length::new::<meter>(*x).clamp(Length::new::<meter>(*min), Length::new::<meter>(*max)))
fn clamp(x: A<V>, min: A<V>, max: A<V>) -> TestResult {
if *min > *max || min.is_nan() || max.is_nan() {
return TestResult::discard();
}
TestResult::from_bool(
Test::eq(
&Length::new::<meter>(x.clamp(*min, *max)),
&Length::new::<meter>(*x).clamp(Length::new::<meter>(*min), Length::new::<meter>(*max))
)
)
}
}
}
Expand Down Expand Up @@ -580,13 +586,19 @@ mod fixed {
}

#[allow(trivial_casts)]
fn clamp(x: A<V>, min: A<V>, max: A<V>) -> bool {
Test::eq(&Length::new::<meter>((*x).clone().clamp((*min).clone(), (*max).clone())),
&Ord::clamp(
Length::new::<meter>((*x).clone()),
Length::new::<meter>((*min).clone()),
Length::new::<meter>((*max).clone()),
))
fn clamp(x: A<V>, min: A<V>, max: A<V>) -> TestResult {
if *min > *max {
return TestResult::discard()
}
TestResult::from_bool(
Test::eq(&Length::new::<meter>((*x).clone().clamp((*min).clone(), (*max).clone())),
&Ord::clamp(
Length::new::<meter>((*x).clone()),
Length::new::<meter>((*min).clone()),
Length::new::<meter>((*max).clone()),
)
)
)
}
}
}
Expand Down

0 comments on commit bfe70fc

Please sign in to comment.