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 Sep 24, 2022
1 parent 3b3e990 commit f108a8b
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 @@ -375,10 +375,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 @@ -582,13 +588,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 {
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 f108a8b

Please sign in to comment.