Skip to content

Commit

Permalink
assert_eq! in model tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ryan-williams committed Sep 16, 2023
1 parent 80d8ca9 commit b7565aa
Showing 1 changed file with 3 additions and 19 deletions.
22 changes: 3 additions & 19 deletions src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ mod tests {
/// - shape-coordinate values
/// - overall error
/// - error gradient (with respect to each shape-coordinate)
#[derive(Clone)]
#[derive(Clone, Debug, PartialEq)]
pub struct ExpectedStep {
vals: Vec<f64>,
err: f64,
Expand Down Expand Up @@ -295,25 +295,9 @@ mod tests {
info!("Read expecteds from {}", expected_path);
info!("{}", df);
assert_eq!(steps.len(), expecteds.len());
for (idx, (step, expected)) in steps.iter().zip(expecteds.iter()).enumerate() {
for (idx, (step, expected)) in steps.iter().zip(expecteds.into_iter()).enumerate() {
let actual = get_actual(step, &coord_getters);
assert_eq!(actual.vals.len(), expected.vals.len());
for (a_val, e_val) in actual.vals.iter().zip(expected.vals.iter()) {
assert_relative_eq!(a_val, e_val, epsilon = 1e-3);
}
// Scaffolding for allowing wiggle room on matching gradient and error values. I can't even simulate exact "linux" values in Docker on macOS.
let actual_dual = actual.dual();
let expected_dual = expected.dual();
let ε_abs = 1e-17;
let ε_rel = 1e-17;
if !abs_diff_eq!(actual_dual, expected_dual, epsilon = ε_abs) || !relative_eq!(actual_dual, expected_dual, epsilon = ε_abs, max_relative = ε_rel) {
warn!("{}: step {} duals:\n\t{:?}\n\t{:?}", name, idx, actual_dual, expected_dual);
assert_relative_eq!(actual_dual, expected_dual, epsilon = ε_abs, max_relative = ε_rel);
}
if !abs_diff_eq!(actual.err, expected.err, epsilon = ε_abs) || !relative_eq!(actual.err, expected.err, epsilon = ε_abs, max_relative = ε_rel) {
warn!("{}: step {} error: {:?} != {:?}", name, idx, actual.err, expected.err);
assert_relative_eq!(actual.err, expected.err, epsilon = ε_abs, max_relative = ε_rel);
}
assert_eq!(actual, expected, "Step {}", idx);
}
}
}
Expand Down

0 comments on commit b7565aa

Please sign in to comment.