Moddy the Tube test
This commit is contained in:
parent
e8551f5d02
commit
0a27fc1f9b
|
|
@ -49,29 +49,36 @@ impl Metric for Tube {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[cfg(test)]
|
||||||
fn test_tube_metric_derivs() {
|
mod test {
|
||||||
struct Approx(Tube);
|
use glam::{Vec2, vec2};
|
||||||
impl Metric for Approx {
|
use crate::riemann::{Decomp2, Metric};
|
||||||
fn sqrt_at(&self, pos: Vec2) -> Decomp2 { self.0.sqrt_at(pos) }
|
use super::Tube;
|
||||||
}
|
|
||||||
let testee = Tube {
|
#[test]
|
||||||
inner_radius: 30.0,
|
fn test_tube_metric_derivs() {
|
||||||
outer_radius: 50.0,
|
struct Approx(Tube);
|
||||||
internal_halflength: 100.0,
|
impl Metric for Approx {
|
||||||
external_halflength: 300.0,
|
fn sqrt_at(&self, pos: Vec2) -> Decomp2 { self.0.sqrt_at(pos) }
|
||||||
};
|
}
|
||||||
let approx = Approx(testee);
|
let testee = Tube {
|
||||||
let epsilon = 1.0e-3;
|
inner_radius: 30.0,
|
||||||
let margin = 1.0 / 16.0;
|
outer_radius: 50.0,
|
||||||
let mul = 1.0 + margin;
|
internal_halflength: 100.0,
|
||||||
for x in itertools_num::linspace(-mul * testee.outer_radius, mul * testee.outer_radius, 100) {
|
external_halflength: 300.0,
|
||||||
for y in itertools_num::linspace(-mul * testee.external_halflength, mul * testee.external_halflength, 100) {
|
};
|
||||||
let pos = vec2(x, y);
|
let approx = Approx(testee);
|
||||||
let computed = testee.part_derivs_at(pos);
|
let epsilon = 1.0e-3;
|
||||||
let reference = approx.part_derivs_at(pos);
|
let margin = 1.0 / 16.0;
|
||||||
let eq = (0..2).all(|coord| computed[coord].abs_diff_eq(reference[coord], epsilon));
|
let mul = 1.0 + margin;
|
||||||
assert!(eq, "Bad derivative computation at {pos}:\n explicit: {computed:?}\n numerical: {reference:?}\n");
|
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");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user