use super::*; /// RULE: A run's stopping fact — answered and nothing are no fact, each /// ceiling, no key and a refusal are their own, and a word the server adds /// later is carried as itself. #[test] fn a_stopping_reason_is_a_fact_and_an_unknown_one_is_kept() { let cases: [(Option<&str>, Option); 9] = [ (None, None), (Some(""), None), (Some(" "), None), (Some("answered"), None), (Some("turn_ceiling"), Some(Stopped::TurnCeiling)), (Some("time_ceiling"), Some(Stopped::TimeCeiling)), (Some("no_key"), Some(Stopped::NoKey)), (Some("model_refused"), Some(Stopped::ModelRefused)), (Some("paused_for_tea"), Some(Stopped::Unnamed("paused_for_tea".into()))), ]; for (reason, fact) in cases { assert_eq!(Stopped::of(reason), fact, "{reason:?}"); } } /// RULE: every stopping fact this build names has a line in the kit, so no /// run stops on silence. #[test] fn every_stopping_fact_has_a_kit_line() { for fact in [Stopped::TurnCeiling, Stopped::TimeCeiling, Stopped::NoKey, Stopped::ModelRefused] { assert!(!fact.say(&[]).is_empty(), "{fact:?} has no line"); } } /// RULE: A cost reads as money — four decimals under a cent, two from a cent up — and a null, zero, negative or non-finite cost says nothing. #[test] fn a_cost_reads_as_money_and_nothing_costed_says_nothing() { let cases: [(Option, Option<&str>); 9] = [ (None, None), (Some(0.0), None), (Some(-0.5), None), (Some(f64::NAN), None), (Some(f64::INFINITY), None), (Some(0.0042), Some("$0.0042")), (Some(0.0176), Some("$0.02")), (Some(0.01), Some("$0.01")), (Some(12.5), Some("$12.50")), ]; for (cost, words) in cases { assert_eq!(cost_words(cost).as_deref(), words, "{cost:?}"); } } /// RULE: the spent line is the database's row — a rewording is a row, never /// a build — and says nothing when neither fact does. #[test] fn the_spent_line_is_the_databases_row() { assert_eq!(spent_line(None, None, &[]), None); let row = LineRow { set: SET.into(), line: "spent.stopped_and_cost".into(), words: "{stopped}; {cost}".into() }; assert_eq!(spent_line(Some("no_key"), Some(12.5), &[row]).as_deref(), Some("Stopped: no key stored; $12.50")); let kit = spent_line(Some("turn_ceiling"), None, &[]).unwrap(); assert_eq!(kit, Stopped::TurnCeiling.say(&[])); } /// RULE: A call's outcome is refused only when its row says it failed; an absent flag reads as succeeded and never accuses a connection. #[test] fn a_calls_outcome_is_refused_only_when_its_row_says_so() { assert_eq!(call_outcome(Some(0)), CALL_REFUSED); assert_eq!(call_outcome(Some(1)), CALL_OK); assert_eq!(call_outcome(None), CALL_OK); }