diff --git a/entscheiden/motor/src/flop_exakt.rs b/entscheiden/motor/src/flop_exakt.rs index c66dd956..e0ce6185 100644 --- a/entscheiden/motor/src/flop_exakt.rs +++ b/entscheiden/motor/src/flop_exakt.rs @@ -213,6 +213,16 @@ mod spec { use std::collections::HashMap; use std::time::Duration; + /// Solve "with time to spare" on the deterministic test clock (uhr::setze_takt): the deadline lies far beyond any number of clock + /// reads the solver makes, so the result never depends on the load of the machine. + fn reichlich_zeit(f: impl FnOnce(Instant) -> T) -> T { + let start = Instant::now(); + crate::uhr::setze_takt(Some((start, Duration::from_millis(1)))); + let r = f(start + Duration::from_secs(24 * 3600)); + crate::uhr::setze_takt(None); + r + } + fn umgebung(paare: &[(&str, &str)]) -> impl Fn(&str) -> Option { let m: HashMap = paare.iter().map(|(a, b)| (a.to_string(), b.to_string())).collect(); move |n| m.get(n).cloned() @@ -337,7 +347,7 @@ mod spec { #[test] fn loesen_mit_frist_erreicht_das_ziel_wenn_zeit_ist() { let g = river(); - let r = loese_bis(&g, 600, 0.01, Instant::now() + Duration::from_secs(60)); + let r = reichlich_zeit(|frist| loese_bis(&g, 600, 0.01, frist)); assert!(r.fertig, "{r:?}"); assert!(r.ausbeutung <= 0.01, "{r:?}"); assert!(r.iterationen > 0 && r.iterationen % 10 == 0, "{r:?}"); diff --git a/entscheiden/motor/src/flopbib.rs b/entscheiden/motor/src/flopbib.rs index 36a9c2e8..2600d68b 100644 --- a/entscheiden/motor/src/flopbib.rs +++ b/entscheiden/motor/src/flopbib.rs @@ -573,6 +573,16 @@ pub fn lauf(a: &[String]) { mod spec { use super::*; + /// Solve "with time to spare" on the deterministic test clock (uhr::setze_takt): the deadline lies far beyond any number of clock + /// reads the solver makes, so the result never depends on the load of the machine. + fn reichlich_zeit(f: impl FnOnce(Instant) -> T) -> T { + let start = Instant::now(); + crate::uhr::setze_takt(Some((start, Duration::from_millis(1)))); + let r = f(start + Duration::from_secs(24 * 3600)); + crate::uhr::setze_takt(None); + r + } + #[test] fn es_gibt_1755_iso_flops_mit_gesamtgewicht_22100() { let v = iso_flops(); @@ -659,7 +669,7 @@ mod spec { } let a = Aufgabe { ranges: [oop, ip], brett: flop.to_vec(), pot: 550, stack: 2000, rake: (0.05, 1000.0) }; let g = nachrechnen::bau_mit(&a, &[vec![]], false).unwrap(); - crate::flop_exakt::loese_bis(&g, a.pot, 0.005, Instant::now() + Duration::from_secs(60)); + reichlich_zeit(|frist| crate::flop_exakt::loese_bis(&g, a.pot, 0.005, frist)); (a, g) } @@ -830,7 +840,7 @@ mod spec { assert!(w[0] + w[1] <= a.pot as f64 / 100.0 + 1e-3 && w[0] + w[1] > 0.8 * a.pot as f64 / 100.0, "{w:?}"); // OOP mit breitem Menue ist (bis auf die Konvergenz) nicht schlechter als mit engem let mut b = nachrechnen::bau_mit_flopmenue(&a, &[vec![]], false, Menue::BreitOop.groessen()).unwrap(); - crate::flop_exakt::loese_bis(&b, a.pot, 0.005, Instant::now() + Duration::from_secs(60)); + reichlich_zeit(|frist| crate::flop_exakt::loese_bis(&b, a.pot, 0.005, frist)); postflop_solver::finalize(&mut b); let wb = wurzelwerte(&mut b); assert!(wb[0] >= w[0] - 2.0 * 0.005 * a.pot as f64 / 100.0, "breit {} eng {}", wb[0], w[0]);