diff --git a/source/treadcore-brain/src/bio.rs b/source/treadcore-brain/src/bio.rs index 8a8dac3..bd0fee1 100644 --- a/source/treadcore-brain/src/bio.rs +++ b/source/treadcore-brain/src/bio.rs @@ -65,8 +65,10 @@ mod tests { #[test] fn with_bio_off_there_is_no_wave_at_all() { - assert_eq!(rhythm(&Settings::default(), 3, 5000), [0.0; WAVES]); - assert_eq!(mood(&Settings::default(), 3, 5000), 0.0); + // Named, not the default: the fleet may turn bio on. + let off = on("off"); + assert_eq!(rhythm(&off, 3, 5000), [0.0; WAVES]); + assert_eq!(mood(&off, 3, 5000), 0.0); } #[test] diff --git a/source/treadcore-brain/src/commander.rs b/source/treadcore-brain/src/commander.rs index 6624c68..e779aba 100644 --- a/source/treadcore-brain/src/commander.rs +++ b/source/treadcore-brain/src/commander.rs @@ -3574,7 +3574,6 @@ mod tests { } let all = [true; 6]; let w = 0.25; - assert_eq!(crate::weights::W::Posture.default_value(), 0.95); // Fortify, Hunt, Expand and Guard hold; the team would expand. let holds = [false, true, false, true, true, true]; assert_eq!(Rung::pick(&all, &holds, Some(P::Expand), 0.0), Rung::Fortify); @@ -3642,6 +3641,7 @@ mod tests { c.slot = Some(1); let wedge = c.slot_point(&leader, Some(&map)).unwrap(); let mut s = crate::weights::Settings::default(); + s.w[crate::weights::W::ColumnGap] = 2.0; s.caps = s.caps.with(crate::weights::Caps::COLUMN); c.set_settings(s); assert_eq!(c.slot_point(&leader, Some(&map)).unwrap(), wedge, "on land the wedge"); @@ -3678,7 +3678,8 @@ mod tests { c.set_settings(s); assert_eq!((c.pings, c.answers_pings, c.dodges, c.inner.hop.no_bridges), (true, false, true, false), "back as the role had them"); let t = c.inner.tactics.as_ref().unwrap(); - assert_eq!((t.target, t.w.w_wounded), (Some(7), 1.4)); + assert_eq!(t.target, Some(7)); + assert!((t.w.w_wounded - (W::Wounded.default_value() + 2.0 * W::Wounded.step())).abs() < 2e-4); } /// A world of two allied bots, and a Commander in seat 1 hearing seat 0's ping. diff --git a/source/treadcore-brain/src/weights.rs b/source/treadcore-brain/src/weights.rs index 8624d2a..722b248 100644 --- a/source/treadcore-brain/src/weights.rs +++ b/source/treadcore-brain/src/weights.rs @@ -653,6 +653,9 @@ mod tests { #[test] fn smooth_is_a_weight_that_blends_and_thresholds() { let mut s = Settings::default(); + // The numbers this test was written for: the fleet moves the defaults. + s.w[W::SmoothShare] = 0.05; + s.w[W::Alpha] = 0.4; assert!((s.smooth() - 0.05).abs() < 1e-6 && !s.smooth_on()); assert!((s.smooth_alpha() - 0.97).abs() < 1e-6, "0.05 of the way from 1 to alpha 0.4"); s.w[W::SmoothShare] = 0.0; @@ -678,14 +681,20 @@ mod tests { #[test] fn a_slider_steps_and_steps_back() { - assert_eq!((W::Alpha.step(), W::NearScale.step(), W::ForgetFor.step(), W::Margin.step()), (0.05, 2.0, 10.0, 0.02)); + // A step is a tenth of the default, rounded to a nice number: the fleet moves the defaults. + for w in [W::Alpha, W::NearScale, W::ForgetFor, W::Margin] { + let (step, d) = (w.step(), w.default_value().abs()); + assert!(step >= d / 20.0 && step <= d / 5.0, "{}: {} on {}", w.name(), step, d); + } assert_eq!((W::CastleInside.step(), W::Confirm.step(), W::Kite.step()), (1.0, 1.0, 1.0), "a rounded weight steps by one"); let mut s = Settings::default(); + let (start, step) = (s.w[W::Alpha], W::Alpha.step()); s.nudge(W::Alpha, 3); - assert_eq!(s.w[W::Alpha], 0.55); + // A nudge rounds to four places, so a default from the search comes back within one. + assert!((s.w[W::Alpha] - (start + 3.0 * step)).abs() < 2e-4); s.nudge(W::Alpha, -3); - assert_eq!(s.w[W::Alpha], 0.4, "three up and three down is where it was"); - s.nudge(W::Commit, -10); + assert!((s.w[W::Alpha] - start).abs() < 2e-4, "three up and three down is where it was"); + s.nudge(W::Commit, -1000); assert_eq!(s.w[W::Commit], 0.0, "never under nothing"); for w in W::ALL { assert!(w.step() > 0.0 && w.step() <= w.default_value().max(1.0), "{}: {}", w.name(), w.step());