test(hyperband,moead,knea,ibea,ipop_cma_es,mopso): pin helper functions

Phase 1 tests:
- hyperband: compare / better feasibility-first + direction branches.
- moead: tchebycheff (max weighted deviation from ideal) and
  weight_distance (Euclidean) pins.
- knea: perpendicular_distance to the simplex hyperplane, zero-on-plane,
  and the too-few-extremes degenerate fallback.
- ibea: compute_fitness empty/dominating/symmetric-tradeoff cases and
  binary_tournament fitness preference.
- ipop_cma_es: better feasibility-first + direction + equal-not-better.
- mopso: population/front sizing and determinism cross-check.
This commit is contained in:
2026-05-13 22:58:17 -06:00
parent 952d93ac85
commit c2319116b8
6 changed files with 184 additions and 0 deletions
+28
View File
@@ -393,4 +393,32 @@ mod tests {
.collect();
assert_eq!(oa, ob);
}
// ---- Mutation-test pinned helpers --------------------------------------
#[test]
fn perpendicular_distance_to_simplex_hyperplane() {
// Two extremes (1,0) and (0,1) define the line x + y = 1.
// The point (1,1) has signed distance |2 - 1| / sqrt(2) = 1/sqrt(2).
let oriented = vec![vec![1.0, 0.0], vec![0.0, 1.0], vec![1.0, 1.0]];
let d = perpendicular_distance(&oriented[2], &[0, 1], &oriented);
assert!((d - 1.0 / 2.0_f64.sqrt()).abs() < 1e-12, "d = {d}");
}
#[test]
fn perpendicular_distance_zero_on_hyperplane() {
// (0.5, 0.5) lies exactly on x + y = 1 → distance 0.
let oriented = vec![vec![1.0, 0.0], vec![0.0, 1.0], vec![0.5, 0.5]];
let d = perpendicular_distance(&oriented[2], &[0, 1], &oriented);
assert!(d.abs() < 1e-12, "d = {d}");
}
#[test]
fn perpendicular_distance_degenerate_too_few_extremes() {
// Only one extreme for a 2-D point → falls back to L2 from that
// extreme. (1,1) to (0,0) = sqrt(2).
let oriented = vec![vec![0.0, 0.0], vec![1.0, 1.0]];
let d = perpendicular_distance(&oriented[1], &[0], &oriented);
assert!((d - 2.0_f64.sqrt()).abs() < 1e-12, "d = {d}");
}
}