diff --git a/src/bin/flat/tube/metric.rs b/src/bin/flat/tube/metric.rs index b64603b..8bd5724 100644 --- a/src/bin/flat/tube/metric.rs +++ b/src/bin/flat/tube/metric.rs @@ -49,29 +49,36 @@ impl Metric for Tube { } } -#[test] -fn test_tube_metric_derivs() { - struct Approx(Tube); - impl Metric for Approx { - fn sqrt_at(&self, pos: Vec2) -> Decomp2 { self.0.sqrt_at(pos) } - } - let testee = Tube { - inner_radius: 30.0, - outer_radius: 50.0, - internal_halflength: 100.0, - external_halflength: 300.0, - }; - let approx = Approx(testee); - let epsilon = 1.0e-3; - let margin = 1.0 / 16.0; - let mul = 1.0 + margin; - for x in itertools_num::linspace(-mul * testee.outer_radius, mul * testee.outer_radius, 100) { - for y in itertools_num::linspace(-mul * testee.external_halflength, mul * testee.external_halflength, 100) { - let pos = vec2(x, y); - let computed = testee.part_derivs_at(pos); - let reference = approx.part_derivs_at(pos); - let eq = (0..2).all(|coord| computed[coord].abs_diff_eq(reference[coord], epsilon)); - assert!(eq, "Bad derivative computation at {pos}:\n explicit: {computed:?}\n numerical: {reference:?}\n"); +#[cfg(test)] +mod test { + use glam::{Vec2, vec2}; + use crate::riemann::{Decomp2, Metric}; + use super::Tube; + + #[test] + fn test_tube_metric_derivs() { + struct Approx(Tube); + impl Metric for Approx { + fn sqrt_at(&self, pos: Vec2) -> Decomp2 { self.0.sqrt_at(pos) } + } + let testee = Tube { + inner_radius: 30.0, + outer_radius: 50.0, + internal_halflength: 100.0, + external_halflength: 300.0, + }; + let approx = Approx(testee); + let epsilon = 1.0e-3; + let margin = 1.0 / 16.0; + let mul = 1.0 + margin; + for x in itertools_num::linspace(-mul * testee.outer_radius, mul * testee.outer_radius, 100) { + for y in itertools_num::linspace(-mul * testee.external_halflength, mul * testee.external_halflength, 100) { + let pos = vec2(x, y); + let computed = testee.part_derivs_at(pos); + let reference = approx.part_derivs_at(pos); + let eq = (0..2).all(|coord| computed[coord].abs_diff_eq(reference[coord], epsilon)); + assert!(eq, "Bad derivative computation at {pos}:\n explicit: {computed:?}\n numerical: {reference:?}\n"); + } } } }