test(aura-registry): RED executable-spec for optimize argmax — refs #67
The RED half of a RED-first iteration for the optimize/argmax orchestration axis (C12 axis 2). Pins the headline behaviour before the feature exists: optimize(&SweepFamily, metric) returns the single winning SweepPoint — its params coordinate AND its RunReport — chosen by the metric's fixed per-metric sense of best (reusing rank_by's direction semantics), with ties resolving to the earliest enumeration-order point. No caller-supplied direction: that would contradict the shipped rank_by invariant that "best" is fixed by each metric's meaning, and would admit incoherent asks (e.g. the worst max_drawdown). One definition of best per metric. RED for the right reason — optimize is absent (E0425), the sole error; cargo build --workspace stays green (test-only module). GREEN lands in the following commit, which closes #67.
This commit is contained in:
@@ -118,8 +118,8 @@ impl From<std::io::Error> 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]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user