Skip to main content

aggregate

Function aggregate 

Source
pub fn aggregate<S: Ord + Copy>(parts: &[(S, bool)], failing: S) -> Option<S>
Expand description

Several states made one: a failure outranks an absence, and otherwise the weakest part that can carry proof decides.

Each part is a state and whether it can carry proof. The result is failing when any part is failing; otherwise the weakest (the greatest, by the enum’s declared order) of the parts that can carry proof; otherwise the weakest of all parts; and None for none.

Why the first rule: the declared order ranks failing above not_run, so a plain maximum over a failing test and a test that never ran reads not_run, and hides the counter-evidence behind an absence. Why the second: a path no runner and no gate drives can never carry proof, so it counts only when it is all there is.

use majordomus_cli::evidence::freshness::aggregate;
use majordomus_cli::evidence::ProofState::{Failing, NotRun, Proven, Unrunnable};

assert_eq!(aggregate(&[(Failing, true), (NotRun, true)], Failing), Some(Failing));
assert_eq!(aggregate(&[(Proven, true), (NotRun, true)], Failing), Some(NotRun));
assert_eq!(aggregate(&[(Proven, true), (Unrunnable, false)], Failing), Some(Proven));
assert_eq!(aggregate(&[(Unrunnable, false)], Failing), Some(Unrunnable));
assert_eq!(aggregate::<majordomus_cli::evidence::ProofState>(&[], Failing), None);