use super::harness::{LEAVES, explore, ordinal};
use crate::sandbox::ComputerState;
use crate::sandbox::record::PersistPhase;
#[test]
fn every_leaf_is_reachable_by_driving_events() {
let mut seen = [false; LEAVES];
for node in explore() {
seen[ordinal(node.state)] = true;
}
assert!(
seen.iter().all(|reached| *reached),
"unreachable leaves: {:?}",
seen.iter()
.enumerate()
.filter(|(_, reached)| !**reached)
.map(|(index, _)| index)
.collect::<Vec<_>>()
);
}
#[test]
fn every_leaf_projects_onto_a_public_state() {
let expected: [&[ComputerState]; LEAVES] = [
&[ComputerState::Starting], &[ComputerState::Starting], &[ComputerState::Starting], &[ComputerState::Starting], &[ComputerState::Starting, ComputerState::Running], &[ComputerState::Ready], &[ComputerState::Running], &[ComputerState::Ready], &[ComputerState::Pausing], &[ComputerState::Pausing], &[ComputerState::Paused], &[ComputerState::Starting], &[ComputerState::Stopping], &[ComputerState::Stopped], &[ComputerState::Failed], &[ComputerState::Stopping], &[ComputerState::Stopped], &[ComputerState::Ready], ];
for node in explore() {
let public = node.state.to_public();
assert!(
expected[ordinal(node.state)].contains(&public),
"{:?} projects {public}",
node.state
);
}
}
#[test]
fn every_leaf_projects_onto_a_durable_phase() {
use PersistPhase as P;
let expected: [&[Option<P>]; LEAVES] = [
&[Some(P::Creating)], &[Some(P::Starting)], &[Some(P::Starting)], &[Some(P::Creating)], &[Some(P::Starting), Some(P::Ready)], &[Some(P::Ready)], &[Some(P::Ready)], &[Some(P::Ready)], &[Some(P::Pausing)], &[Some(P::Pausing)], &[Some(P::Paused)], &[Some(P::Resuming)], &[Some(P::Stopping)], &[Some(P::Stopped)], &[Some(P::Failed)], &[Some(P::Removing)], &[None], &[Some(P::Ready)], ];
for node in explore() {
let durable = node.state.durable();
assert!(
expected[ordinal(node.state)].contains(&durable),
"{:?} projects {durable:?}",
node.state
);
}
}
#[test]
fn the_durable_projection_is_the_phase_actually_in_effect() {
for node in explore() {
assert_eq!(
node.state.durable(),
node.phase,
"{:?} reached via {:?}",
node.state,
node.path
);
}
}