diff --git a/crates/aura-registry/src/lib.rs b/crates/aura-registry/src/lib.rs index 5d812b6..f067806 100644 --- a/crates/aura-registry/src/lib.rs +++ b/crates/aura-registry/src/lib.rs @@ -118,8 +118,8 @@ impl From for RegistryError { #[cfg(test)] mod tests { use super::*; - use aura_core::Timestamp; - use aura_engine::{RunManifest, RunMetrics, RunReport}; + use aura_core::{Scalar, Timestamp}; + use aura_engine::{RunManifest, RunMetrics, RunReport, SweepFamily, SweepPoint}; fn report_with(total_pips: f64, max_drawdown: f64, flips: u64) -> RunReport { RunReport { @@ -199,4 +199,39 @@ mod tests { other => panic!("expected UnknownMetric, got {other:?}"), } } + + /// `optimize` is `rank_by`'s argmax: over a `SweepFamily` it returns the + /// single winning `SweepPoint` — its `params` coordinate AND its `RunReport` + /// — chosen by the metric's *fixed* sense of best (`total_pips` + /// higher-is-better), and a tie on that metric resolves to the **earliest + /// enumeration-order** point, never a later one. The point carried, not just + /// its metric, is the property: the caller needs the params that won. + #[test] + fn optimize_picks_the_max_metric_point_ties_to_earliest() { + // A hand-built family in odometer order. Two points tie at the maximal + // total_pips (3.0); the EARLIER of the two (index 1, params p=10) must + // win, not the later (index 3, params p=30) — that pins the tie rule. + let point = |p: f64, pips: f64| SweepPoint { + params: vec![Scalar::F64(p)], + report: report_with(pips, 0.5, 0), + }; + let family = SweepFamily { + points: vec![ + point(0.0, 1.0), // 0: also-ran + point(10.0, 3.0), // 1: tied max, earliest -> the winner + point(20.0, 2.0), // 2: also-ran + point(30.0, 3.0), // 3: tied max, but later -> must lose the tie + ], + }; + + let winner = super::optimize(&family, "total_pips").expect("optimize total_pips"); + + // the maximal-metric point wins... + assert_eq!(winner.report.metrics.total_pips, 3.0); + // ...and ties resolve to the earliest enumeration-order point: its params + // identify point 1, not point 3. + assert_eq!(winner.params, vec![Scalar::F64(10.0)]); + // the whole winning point is returned, params AND report together. + assert_eq!(winner, family.points[1]); + } }