Simplify the MHCurve tests
This commit is contained in:
107
src/mat.rs
107
src/mat.rs
@@ -225,110 +225,79 @@ mod test {
|
||||
])
|
||||
}
|
||||
|
||||
fn assert_step_toward_symmetric(h: f64, m: f64, target_mh: f64, target: Result<(f64, f64), (f64, f64)>) {
|
||||
let curve = mh_curve_for_test();
|
||||
let neg_target = match target {
|
||||
Ok((a, b)) => Ok((-a, -b)),
|
||||
Err((a, b)) => Err((-a, -b)),
|
||||
};
|
||||
assert_eq!(curve.step_toward(h, m, target_mh), target);
|
||||
assert_eq!(curve.step_toward(-h, -m, -target_mh), neg_target);
|
||||
}
|
||||
|
||||
fn assert_move_to_symmetric(h: f64, m: f64, target_mh: f64, target: (f64, f64)) {
|
||||
let curve = mh_curve_for_test();
|
||||
assert_eq!(curve.move_to(h, m, target_mh), target);
|
||||
assert_eq!(curve.move_to(-h, -m, -target_mh), (-target.0, -target.1));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mh_curve_move_from_inner_to_inner() {
|
||||
let curve = mh_curve_for_test();
|
||||
assert_eq!(curve.step_toward(0.0, 0.0, 5.0), Ok((5.0, 0.0)));
|
||||
assert_eq!(curve.step_toward(0.0, 5.0, 10.0), Ok((5.0, 5.0)));
|
||||
assert_step_toward_symmetric(0.0, 0.0, 5.0, Ok((5.0, 0.0)));
|
||||
assert_step_toward_symmetric(0.0, 5.0, 10.0, Ok((5.0, 5.0)));
|
||||
|
||||
assert_eq!(curve.step_toward(-5.0, 5.0, -3.0), Ok((-8.0, 5.0)));
|
||||
assert_eq!(curve.step_toward(-5.0, 5.0, 7.0), Ok((2.0, 5.0)));
|
||||
assert_step_toward_symmetric(-5.0, 5.0, -3.0, Ok((-8.0, 5.0)));
|
||||
assert_step_toward_symmetric(-5.0, 5.0, 7.0, Ok((2.0, 5.0)));
|
||||
|
||||
assert_eq!(curve.step_toward(5.0, -5.0, -3.0), Ok((2.0, -5.0)));
|
||||
assert_eq!(curve.step_toward(5.0, -5.0, 3.0), Ok((8.0, -5.0)));
|
||||
assert_step_toward_symmetric(5.0, -5.0, -3.0, Ok((2.0, -5.0)));
|
||||
assert_step_toward_symmetric(5.0, -5.0, 3.0, Ok((8.0, -5.0)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mh_curve_magnetize_along_edge() {
|
||||
let curve = mh_curve_for_test();
|
||||
// start of segment NOOP
|
||||
assert_eq!(curve.step_toward(10.0, 0.0, 10.0), Ok((10.0, 0.0)));
|
||||
assert_step_toward_symmetric(10.0, 0.0, 10.0, Ok((10.0, 0.0)));
|
||||
// start of segment to middle of segment
|
||||
assert_eq!(curve.step_toward(10.0, 0.0, 32.0), Ok((12.0, 20.0)));
|
||||
assert_step_toward_symmetric(10.0, 0.0, 32.0, Ok((12.0, 20.0)));
|
||||
// middle of segment NOOP
|
||||
assert_eq!(curve.step_toward(12.0, 20.0, 32.0), Ok((12.0, 20.0)));
|
||||
assert_step_toward_symmetric(12.0, 20.0, 32.0, Ok((12.0, 20.0)));
|
||||
// middle of segment to middle of segment
|
||||
assert_eq!(curve.step_toward(12.0, 20.0, 54.0), Ok((14.0, 40.0)));
|
||||
assert_step_toward_symmetric(12.0, 20.0, 54.0, Ok((14.0, 40.0)));
|
||||
// middle of segment to end of segment
|
||||
assert_eq!(curve.step_toward(12.0, 20.0, 120.0), Err((20.0, 100.0)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mh_curve_magnetize_along_negative_edge() {
|
||||
let curve = mh_curve_for_test();
|
||||
// start of segment NOOP
|
||||
assert_eq!(curve.step_toward(-10.0, 0.0, -10.0), Ok((-10.0, 0.0)));
|
||||
// start of segment to middle of segment
|
||||
assert_eq!(curve.step_toward(-10.0, 0.0, -32.0), Ok((-12.0, -20.0)));
|
||||
// middle of segment NOOP
|
||||
assert_eq!(curve.step_toward(-12.0, -20.0, -32.0), Ok((-12.0, -20.0)));
|
||||
// middle of segment to middle of segment
|
||||
assert_eq!(curve.step_toward(-12.0, -20.0, -54.0), Ok((-14.0, -40.0)));
|
||||
// middle of segment to end of segment
|
||||
assert_eq!(curve.step_toward(-12.0, -20.0, -120.0), Err((-20.0, -100.0)));
|
||||
assert_step_toward_symmetric(12.0, 20.0, 120.0, Err((20.0, 100.0)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mh_curve_demagnetize_along_edge() {
|
||||
let curve = mh_curve_for_test();
|
||||
// start of segment NOOP
|
||||
assert_eq!(curve.step_toward(30.0, 150.0, 180.0), Ok((30.0, 150.0)));
|
||||
assert_step_toward_symmetric(30.0, 150.0, 180.0, Ok((30.0, 150.0)));
|
||||
// start of segment to middle of segment
|
||||
assert_eq!(curve.step_toward(30.0, 150.0, 160.0), Ok((20.0, 140.0)));
|
||||
assert_step_toward_symmetric(30.0, 150.0, 160.0, Ok((20.0, 140.0)));
|
||||
// middle of segment NOOP
|
||||
assert_eq!(curve.step_toward(20.0, 140.0, 160.0), Ok((20.0, 140.0)));
|
||||
assert_step_toward_symmetric(20.0, 140.0, 160.0, Ok((20.0, 140.0)));
|
||||
// middle of segment to middle of segment
|
||||
assert_eq!(curve.step_toward(20.0, 140.0, 140.0), Ok((10.0, 130.0)));
|
||||
assert_step_toward_symmetric(20.0, 140.0, 140.0, Ok((10.0, 130.0)));
|
||||
// middle of segment to end of segment
|
||||
assert_eq!(curve.step_toward(20.0, 140.0, 120.0), Err((0.0, 120.0)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mh_curve_demagnetize_along_negative_edge() {
|
||||
let curve = mh_curve_for_test();
|
||||
// start of segment NOOP
|
||||
assert_eq!(curve.step_toward(-30.0, -150.0, -180.0), Ok((-30.0, -150.0)));
|
||||
// start of segment to middle of segment
|
||||
assert_eq!(curve.step_toward(-30.0, -150.0, -160.0), Ok((-20.0, -140.0)));
|
||||
// middle of segment NOOP
|
||||
assert_eq!(curve.step_toward(-20.0, -140.0, -160.0), Ok((-20.0, -140.0)));
|
||||
// middle of segment to middle of segment
|
||||
assert_eq!(curve.step_toward(-20.0, -140.0, -140.0), Ok((-10.0, -130.0)));
|
||||
// middle of segment to end of segment
|
||||
assert_eq!(curve.step_toward(-20.0, -140.0, -120.0), Err((-0.0, -120.0)));
|
||||
assert_step_toward_symmetric(20.0, 140.0, 120.0, Err((0.0, 120.0)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mh_curve_magnetize_across_edges() {
|
||||
let curve = mh_curve_for_test();
|
||||
// Rising from start to middle
|
||||
assert_eq!(curve.move_to(10.0, 0.0, 132.0), (22.0, 110.0));
|
||||
assert_move_to_symmetric(10.0, 0.0, 132.0, (22.0, 110.0));
|
||||
// Rising from start to saturation
|
||||
assert_eq!(curve.move_to(10.0, 0.0, 180.0), (30.0, 150.0));
|
||||
assert_move_to_symmetric(10.0, 0.0, 180.0, (30.0, 150.0));
|
||||
// Rising from start to post-saturation
|
||||
assert_eq!(curve.move_to(10.0, 0.0, 400.0), (250.0, 150.0));
|
||||
assert_move_to_symmetric(10.0, 0.0, 400.0, (250.0, 150.0));
|
||||
// Rising from negative saturation to start
|
||||
assert_eq!(curve.move_to(-30.0, -150.0, 10.0), (10.0, 0.0));
|
||||
assert_move_to_symmetric(-30.0, -150.0, 10.0, (10.0, 0.0));
|
||||
// Rising from negative post-saturation to start
|
||||
assert_eq!(curve.move_to(-250.0, -150.0, 10.0), (10.0, 0.0));
|
||||
assert_move_to_symmetric(-250.0, -150.0, 10.0, (10.0, 0.0));
|
||||
// Rising from negative middle to middle
|
||||
assert_eq!(curve.move_to(-22.0, -110.0, 132.0), (22.0, 110.0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mh_curve_magnetize_across_negative_edges() {
|
||||
let curve = mh_curve_for_test();
|
||||
// Rising from start to middle
|
||||
assert_eq!(curve.move_to(-10.0, 0.0, -132.0), (-22.0, -110.0));
|
||||
// Rising from start to saturation
|
||||
assert_eq!(curve.move_to(-10.0, 0.0, -180.0), (-30.0, -150.0));
|
||||
// Rising from start to post-saturation
|
||||
assert_eq!(curve.move_to(-10.0, 0.0, -400.0), (-250.0, -150.0));
|
||||
// Rising from negative saturation to start
|
||||
assert_eq!(curve.move_to(30.0, 150.0, -10.0), (-10.0, 0.0));
|
||||
// Rising from negative post-saturation to start
|
||||
assert_eq!(curve.move_to(250.0, 150.0, -10.0), (-10.0, 0.0));
|
||||
// Rising from negative middle to middle
|
||||
assert_eq!(curve.move_to(22.0, 110.0, -132.0), (-22.0, -110.0));
|
||||
assert_move_to_symmetric(-22.0, -110.0, 132.0, (22.0, 110.0));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user