style: rustfmt the Phase 1 test additions
The per-file Phase 1 test commits were written without running rustfmt as I went; this pass formats the new test code (long assert_eq! lines wrapped, etc.). Formatting-only — no behavioural change.
This commit is contained in:
@@ -599,7 +599,10 @@ mod tests {
|
||||
// direction and the loss tie-breaking.
|
||||
let translated = vec![vec![1.0, 0.0], vec![0.0, 1.0]];
|
||||
let p = estimate_p(&[0, 1], &translated, 2);
|
||||
assert!((p - 0.25).abs() < 1e-12, "expected smallest candidate, got {p}");
|
||||
assert!(
|
||||
(p - 0.25).abs() < 1e-12,
|
||||
"expected smallest candidate, got {p}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -625,7 +628,11 @@ mod tests {
|
||||
mutation: PolynomialMutation::new(bounds, 20.0, 1.0),
|
||||
};
|
||||
let mut opt = AgeMoea::new(
|
||||
AgeMoeaConfig { population_size: 8, generations: 10, seed: 7 },
|
||||
AgeMoeaConfig {
|
||||
population_size: 8,
|
||||
generations: 10,
|
||||
seed: 7,
|
||||
},
|
||||
initializer,
|
||||
variation,
|
||||
);
|
||||
@@ -666,7 +673,11 @@ mod tests {
|
||||
};
|
||||
for pop in [4_usize, 12, 30] {
|
||||
let mut opt = AgeMoea::new(
|
||||
AgeMoeaConfig { population_size: pop, generations: 5, seed: 13 },
|
||||
AgeMoeaConfig {
|
||||
population_size: pop,
|
||||
generations: 5,
|
||||
seed: 13,
|
||||
},
|
||||
initializer.clone(),
|
||||
variation.clone(),
|
||||
);
|
||||
@@ -690,7 +701,11 @@ mod tests {
|
||||
let pop = 6_usize;
|
||||
let gens = 4_usize;
|
||||
let mut opt = AgeMoea::new(
|
||||
AgeMoeaConfig { population_size: pop, generations: gens, seed: 13 },
|
||||
AgeMoeaConfig {
|
||||
population_size: pop,
|
||||
generations: gens,
|
||||
seed: 13,
|
||||
},
|
||||
initializer,
|
||||
variation,
|
||||
);
|
||||
|
||||
@@ -644,7 +644,10 @@ mod tests {
|
||||
// k = exp(-0.5 * (1)^2) = exp(-0.5) ≈ 0.6065
|
||||
let got = rbf_kernel(&[0.0], &[1.0], &[1.0], 1.0);
|
||||
let expected = (-0.5_f64).exp();
|
||||
assert!((got - expected).abs() < 1e-12, "got {got}, expected {expected}");
|
||||
assert!(
|
||||
(got - expected).abs() < 1e-12,
|
||||
"got {got}, expected {expected}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -766,19 +766,37 @@ mod tests {
|
||||
a.constraint_violation = 0.0;
|
||||
let mut b = Evaluation::new(vec![1.0]);
|
||||
b.constraint_violation = 1.0;
|
||||
assert_eq!(compare_so(&a, &b, Direction::Minimize), std::cmp::Ordering::Less);
|
||||
assert_eq!(compare_so(&b, &a, Direction::Minimize), std::cmp::Ordering::Greater);
|
||||
assert_eq!(
|
||||
compare_so(&a, &b, Direction::Minimize),
|
||||
std::cmp::Ordering::Less
|
||||
);
|
||||
assert_eq!(
|
||||
compare_so(&b, &a, Direction::Minimize),
|
||||
std::cmp::Ordering::Greater
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn compare_so_two_feasible_under_min_and_max() {
|
||||
let a = Evaluation::new(vec![1.0]);
|
||||
let b = Evaluation::new(vec![2.0]);
|
||||
assert_eq!(compare_so(&a, &b, Direction::Minimize), std::cmp::Ordering::Less);
|
||||
assert_eq!(compare_so(&b, &a, Direction::Minimize), std::cmp::Ordering::Greater);
|
||||
assert_eq!(
|
||||
compare_so(&a, &b, Direction::Minimize),
|
||||
std::cmp::Ordering::Less
|
||||
);
|
||||
assert_eq!(
|
||||
compare_so(&b, &a, Direction::Minimize),
|
||||
std::cmp::Ordering::Greater
|
||||
);
|
||||
// Maximize inverts.
|
||||
assert_eq!(compare_so(&a, &b, Direction::Maximize), std::cmp::Ordering::Greater);
|
||||
assert_eq!(compare_so(&b, &a, Direction::Maximize), std::cmp::Ordering::Less);
|
||||
assert_eq!(
|
||||
compare_so(&a, &b, Direction::Maximize),
|
||||
std::cmp::Ordering::Greater
|
||||
);
|
||||
assert_eq!(
|
||||
compare_so(&b, &a, Direction::Maximize),
|
||||
std::cmp::Ordering::Less
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -787,8 +805,14 @@ mod tests {
|
||||
a.constraint_violation = 0.5;
|
||||
let mut b = Evaluation::new(vec![0.0]);
|
||||
b.constraint_violation = 1.0;
|
||||
assert_eq!(compare_so(&a, &b, Direction::Minimize), std::cmp::Ordering::Less);
|
||||
assert_eq!(compare_so(&b, &a, Direction::Minimize), std::cmp::Ordering::Greater);
|
||||
assert_eq!(
|
||||
compare_so(&a, &b, Direction::Minimize),
|
||||
std::cmp::Ordering::Less
|
||||
);
|
||||
assert_eq!(
|
||||
compare_so(&b, &a, Direction::Minimize),
|
||||
std::cmp::Ordering::Greater
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -446,15 +446,24 @@ mod tests {
|
||||
fn compare_for_fitness_two_feasible_min_and_max() {
|
||||
let lo = fc(1.0);
|
||||
let hi = fc(2.0);
|
||||
assert_eq!(compare_for_fitness(&lo, &hi, Direction::Minimize), std::cmp::Ordering::Less);
|
||||
assert_eq!(compare_for_fitness(&lo, &hi, Direction::Maximize), std::cmp::Ordering::Greater);
|
||||
assert_eq!(
|
||||
compare_for_fitness(&lo, &hi, Direction::Minimize),
|
||||
std::cmp::Ordering::Less
|
||||
);
|
||||
assert_eq!(
|
||||
compare_for_fitness(&lo, &hi, Direction::Maximize),
|
||||
std::cmp::Ordering::Greater
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn compare_for_fitness_two_infeasible_lower_violation_wins() {
|
||||
let low = fc_cv(0.0, 0.3);
|
||||
let high = fc_cv(0.0, 0.9);
|
||||
assert_eq!(compare_for_fitness(&low, &high, Direction::Minimize), std::cmp::Ordering::Less);
|
||||
assert_eq!(
|
||||
compare_for_fitness(&low, &high, Direction::Minimize),
|
||||
std::cmp::Ordering::Less
|
||||
);
|
||||
}
|
||||
|
||||
/// `survival_selection` carries `elitism` parents and `n - elitism`
|
||||
|
||||
@@ -415,7 +415,12 @@ mod tests {
|
||||
mutation: PolynomialMutation::new(bounds, 20.0, 1.0),
|
||||
};
|
||||
let mut opt = Grea::new(
|
||||
GreaConfig { population_size: pop, generations: 5, grid_divisions: 8, seed: 3 },
|
||||
GreaConfig {
|
||||
population_size: pop,
|
||||
generations: 5,
|
||||
grid_divisions: 8,
|
||||
seed: 3,
|
||||
},
|
||||
initializer,
|
||||
variation,
|
||||
);
|
||||
|
||||
@@ -290,7 +290,10 @@ mod tests {
|
||||
#[test]
|
||||
fn hill_climber_never_worsens_objective() {
|
||||
let mut opt = HillClimber::new(
|
||||
HillClimberConfig { iterations: 200, seed: 5 },
|
||||
HillClimberConfig {
|
||||
iterations: 200,
|
||||
seed: 5,
|
||||
},
|
||||
RealBounds::new(vec![(-3.0, 3.0); 2]),
|
||||
GaussianMutation { sigma: 0.3 },
|
||||
);
|
||||
@@ -306,7 +309,10 @@ mod tests {
|
||||
#[test]
|
||||
fn hill_climber_decreases_sphere() {
|
||||
let mut opt = HillClimber::new(
|
||||
HillClimberConfig { iterations: 500, seed: 11 },
|
||||
HillClimberConfig {
|
||||
iterations: 500,
|
||||
seed: 11,
|
||||
},
|
||||
RealBounds::new(vec![(-3.0, 3.0)]),
|
||||
GaussianMutation { sigma: 0.2 },
|
||||
);
|
||||
|
||||
@@ -595,6 +595,9 @@ mod tests {
|
||||
wins0 += 1;
|
||||
}
|
||||
}
|
||||
assert!(wins0 > 130, "index 0 won only {wins0}/200 — comparison likely flipped");
|
||||
assert!(
|
||||
wins0 > 130,
|
||||
"index 0 won only {wins0}/200 — comparison likely flipped"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -451,16 +451,31 @@ mod tests {
|
||||
fn compare_feasibility_first_and_direction() {
|
||||
let feasible = Evaluation::new(vec![10.0]);
|
||||
let infeasible = Evaluation::constrained(vec![0.0], 1.0);
|
||||
assert_eq!(compare(&feasible, &infeasible, Direction::Minimize), std::cmp::Ordering::Less);
|
||||
assert_eq!(compare(&infeasible, &feasible, Direction::Minimize), std::cmp::Ordering::Greater);
|
||||
assert_eq!(
|
||||
compare(&feasible, &infeasible, Direction::Minimize),
|
||||
std::cmp::Ordering::Less
|
||||
);
|
||||
assert_eq!(
|
||||
compare(&infeasible, &feasible, Direction::Minimize),
|
||||
std::cmp::Ordering::Greater
|
||||
);
|
||||
let lo = Evaluation::new(vec![1.0]);
|
||||
let hi = Evaluation::new(vec![2.0]);
|
||||
assert_eq!(compare(&lo, &hi, Direction::Minimize), std::cmp::Ordering::Less);
|
||||
assert_eq!(compare(&lo, &hi, Direction::Maximize), std::cmp::Ordering::Greater);
|
||||
assert_eq!(
|
||||
compare(&lo, &hi, Direction::Minimize),
|
||||
std::cmp::Ordering::Less
|
||||
);
|
||||
assert_eq!(
|
||||
compare(&lo, &hi, Direction::Maximize),
|
||||
std::cmp::Ordering::Greater
|
||||
);
|
||||
// two infeasible: smaller violation is "Less" (better).
|
||||
let v_lo = Evaluation::constrained(vec![0.0], 0.2);
|
||||
let v_hi = Evaluation::constrained(vec![0.0], 0.8);
|
||||
assert_eq!(compare(&v_lo, &v_hi, Direction::Minimize), std::cmp::Ordering::Less);
|
||||
assert_eq!(
|
||||
compare(&v_lo, &v_hi, Direction::Minimize),
|
||||
std::cmp::Ordering::Less
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -501,7 +501,10 @@ mod tests {
|
||||
let pool = vec![ibea_cand(vec![1.0, 1.0]), ibea_cand(vec![2.0, 2.0])];
|
||||
let fit = compute_fitness(&pool, &ibea_space(), 0.05);
|
||||
assert_eq!(fit.len(), 2);
|
||||
assert!(fit[0] > fit[1], "dominating point should score higher: {fit:?}");
|
||||
assert!(
|
||||
fit[0] > fit[1],
|
||||
"dominating point should score higher: {fit:?}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
+10
-2
@@ -408,8 +408,16 @@ mod tests {
|
||||
// Determinism cross-check.
|
||||
let mut opt2 = make_optimizer(7);
|
||||
let r2 = opt2.run(&SchafferN1);
|
||||
let f1: Vec<Vec<f64>> = r.pareto_front.iter().map(|c| c.evaluation.objectives.clone()).collect();
|
||||
let f2: Vec<Vec<f64>> = r2.pareto_front.iter().map(|c| c.evaluation.objectives.clone()).collect();
|
||||
let f1: Vec<Vec<f64>> = r
|
||||
.pareto_front
|
||||
.iter()
|
||||
.map(|c| c.evaluation.objectives.clone())
|
||||
.collect();
|
||||
let f2: Vec<Vec<f64>> = r2
|
||||
.pareto_front
|
||||
.iter()
|
||||
.map(|c| c.evaluation.objectives.clone())
|
||||
.collect();
|
||||
assert_eq!(f1, f2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -560,14 +560,26 @@ mod tests {
|
||||
fn compare_feasibility_first_and_direction() {
|
||||
let feasible = Evaluation::new(vec![10.0]);
|
||||
let infeasible = Evaluation::constrained(vec![0.0], 1.0);
|
||||
assert_eq!(compare(&feasible, &infeasible, Direction::Minimize), std::cmp::Ordering::Less);
|
||||
assert_eq!(
|
||||
compare(&feasible, &infeasible, Direction::Minimize),
|
||||
std::cmp::Ordering::Less
|
||||
);
|
||||
let lo = Evaluation::new(vec![1.0]);
|
||||
let hi = Evaluation::new(vec![2.0]);
|
||||
assert_eq!(compare(&lo, &hi, Direction::Minimize), std::cmp::Ordering::Less);
|
||||
assert_eq!(compare(&lo, &hi, Direction::Maximize), std::cmp::Ordering::Greater);
|
||||
assert_eq!(
|
||||
compare(&lo, &hi, Direction::Minimize),
|
||||
std::cmp::Ordering::Less
|
||||
);
|
||||
assert_eq!(
|
||||
compare(&lo, &hi, Direction::Maximize),
|
||||
std::cmp::Ordering::Greater
|
||||
);
|
||||
let v_lo = Evaluation::constrained(vec![0.0], 0.2);
|
||||
let v_hi = Evaluation::constrained(vec![0.0], 0.8);
|
||||
assert_eq!(compare(&v_lo, &v_hi, Direction::Minimize), std::cmp::Ordering::Less);
|
||||
assert_eq!(
|
||||
compare(&v_lo, &v_hi, Direction::Minimize),
|
||||
std::cmp::Ordering::Less
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
+15
-3
@@ -313,7 +313,11 @@ mod tests {
|
||||
fn produces_deterministic_nonempty_front() {
|
||||
let make = || {
|
||||
Paes::new(
|
||||
PaesConfig { iterations: 40, archive_size: 10, seed: 5 },
|
||||
PaesConfig {
|
||||
iterations: 40,
|
||||
archive_size: 10,
|
||||
seed: 5,
|
||||
},
|
||||
RealBounds::new(vec![(-5.0, 5.0)]),
|
||||
GaussianMutation { sigma: 0.3 },
|
||||
)
|
||||
@@ -321,8 +325,16 @@ mod tests {
|
||||
let r1 = make().run(&SchafferN1);
|
||||
let r2 = make().run(&SchafferN1);
|
||||
assert!(!r1.pareto_front.is_empty());
|
||||
let f1: Vec<Vec<f64>> = r1.pareto_front.iter().map(|c| c.evaluation.objectives.clone()).collect();
|
||||
let f2: Vec<Vec<f64>> = r2.pareto_front.iter().map(|c| c.evaluation.objectives.clone()).collect();
|
||||
let f1: Vec<Vec<f64>> = r1
|
||||
.pareto_front
|
||||
.iter()
|
||||
.map(|c| c.evaluation.objectives.clone())
|
||||
.collect();
|
||||
let f2: Vec<Vec<f64>> = r2
|
||||
.pareto_front
|
||||
.iter()
|
||||
.map(|c| c.evaluation.objectives.clone())
|
||||
.collect();
|
||||
assert_eq!(f1, f2);
|
||||
// Archive never exceeds its configured cap.
|
||||
assert!(r1.pareto_front.len() <= 10);
|
||||
|
||||
@@ -560,6 +560,9 @@ mod tests {
|
||||
}
|
||||
// Index 2 wins whenever it's drawn against 0 or 1, plus half its
|
||||
// self-draws — clear majority.
|
||||
assert!(picked_uncrowded > 150, "uncrowded picked {picked_uncrowded}/300");
|
||||
assert!(
|
||||
picked_uncrowded > 150,
|
||||
"uncrowded picked {picked_uncrowded}/300"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -224,7 +224,11 @@ mod tests {
|
||||
#[test]
|
||||
fn best_is_no_worse_than_any_sample() {
|
||||
let mut opt = RandomSearch::new(
|
||||
RandomSearchConfig { iterations: 50, batch_size: 2, seed: 9 },
|
||||
RandomSearchConfig {
|
||||
iterations: 50,
|
||||
batch_size: 2,
|
||||
seed: 9,
|
||||
},
|
||||
RealBounds::new(vec![(-3.0, 3.0)]),
|
||||
);
|
||||
let r = opt.run(&Sphere1D);
|
||||
|
||||
@@ -591,6 +591,9 @@ mod tests {
|
||||
fn smallest_neighbor_angle_of_orthogonal_refs_is_pi_over_2() {
|
||||
let refs = vec![vec![1.0, 0.0], vec![0.0, 1.0]];
|
||||
let a = smallest_neighbor_angle(&refs);
|
||||
assert!((a - std::f64::consts::FRAC_PI_2).abs() < 1e-9, "angle = {a}");
|
||||
assert!(
|
||||
(a - std::f64::consts::FRAC_PI_2).abs() < 1e-9,
|
||||
"angle = {a}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
+12
-3
@@ -483,11 +483,20 @@ mod tests {
|
||||
fn compare_feasibility_first_and_direction() {
|
||||
let feasible = Evaluation::new(vec![100.0]);
|
||||
let infeasible = Evaluation::constrained(vec![0.0], 1.0);
|
||||
assert_eq!(compare(&feasible, &infeasible, Direction::Minimize), std::cmp::Ordering::Less);
|
||||
assert_eq!(
|
||||
compare(&feasible, &infeasible, Direction::Minimize),
|
||||
std::cmp::Ordering::Less
|
||||
);
|
||||
let lo = Evaluation::new(vec![1.0]);
|
||||
let hi = Evaluation::new(vec![2.0]);
|
||||
assert_eq!(compare(&lo, &hi, Direction::Minimize), std::cmp::Ordering::Less);
|
||||
assert_eq!(compare(&lo, &hi, Direction::Maximize), std::cmp::Ordering::Greater);
|
||||
assert_eq!(
|
||||
compare(&lo, &hi, Direction::Minimize),
|
||||
std::cmp::Ordering::Less
|
||||
);
|
||||
assert_eq!(
|
||||
compare(&lo, &hi, Direction::Maximize),
|
||||
std::cmp::Ordering::Greater
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
+16
-4
@@ -456,14 +456,26 @@ mod tests {
|
||||
fn compare_so_feasibility_first_and_direction() {
|
||||
let feasible = Evaluation::new(vec![100.0]);
|
||||
let infeasible = Evaluation::constrained(vec![0.0], 1.0);
|
||||
assert_eq!(compare_so(&feasible, &infeasible, Direction::Minimize), std::cmp::Ordering::Less);
|
||||
assert_eq!(
|
||||
compare_so(&feasible, &infeasible, Direction::Minimize),
|
||||
std::cmp::Ordering::Less
|
||||
);
|
||||
let lo = Evaluation::new(vec![1.0]);
|
||||
let hi = Evaluation::new(vec![2.0]);
|
||||
assert_eq!(compare_so(&lo, &hi, Direction::Minimize), std::cmp::Ordering::Less);
|
||||
assert_eq!(compare_so(&lo, &hi, Direction::Maximize), std::cmp::Ordering::Greater);
|
||||
assert_eq!(
|
||||
compare_so(&lo, &hi, Direction::Minimize),
|
||||
std::cmp::Ordering::Less
|
||||
);
|
||||
assert_eq!(
|
||||
compare_so(&lo, &hi, Direction::Maximize),
|
||||
std::cmp::Ordering::Greater
|
||||
);
|
||||
let v_lo = Evaluation::constrained(vec![0.0], 0.2);
|
||||
let v_hi = Evaluation::constrained(vec![0.0], 0.8);
|
||||
assert_eq!(compare_so(&v_lo, &v_hi, Direction::Minimize), std::cmp::Ordering::Less);
|
||||
assert_eq!(
|
||||
compare_so(&v_lo, &v_hi, Direction::Minimize),
|
||||
std::cmp::Ordering::Less
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user