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
+34
View File
@@ -452,4 +452,38 @@ mod tests {
);
let _ = opt.run(&SchafferN1);
}
// ---- Mutation-test pinned helpers --------------------------------------
#[test]
fn tchebycheff_is_max_weighted_deviation() {
// ideal = (0, 0), weights = (1, 1): g = max(|f0|, |f1|).
let g = tchebycheff(&[3.0, 5.0], &[1.0, 1.0], &[0.0, 0.0]);
assert!((g - 5.0).abs() < 1e-12);
// weights skew which axis dominates.
let g2 = tchebycheff(&[3.0, 5.0], &[10.0, 1.0], &[0.0, 0.0]);
assert!((g2 - 30.0).abs() < 1e-12);
}
#[test]
fn tchebycheff_uses_distance_from_ideal() {
// ideal = (2, 2): deviations are |3-2|=1, |5-2|=3 → g = 3.
let g = tchebycheff(&[3.0, 5.0], &[1.0, 1.0], &[2.0, 2.0]);
assert!((g - 3.0).abs() < 1e-12);
}
#[test]
fn tchebycheff_zero_at_ideal() {
let g = tchebycheff(&[2.0, 2.0], &[1.0, 1.0], &[2.0, 2.0]);
assert!(g.abs() < 1e-12);
}
#[test]
fn weight_distance_is_euclidean() {
// (0,0) to (3,4) = 5.
assert!((weight_distance(&[0.0, 0.0], &[3.0, 4.0]) - 5.0).abs() < 1e-12);
// symmetric and zero-to-self.
assert!((weight_distance(&[3.0, 4.0], &[0.0, 0.0]) - 5.0).abs() < 1e-12);
assert_eq!(weight_distance(&[1.0, 2.0, 3.0], &[1.0, 2.0, 3.0]), 0.0);
}
}