From fbaca9de950c73a61599cd90d698677135c91afb Mon Sep 17 00:00:00 2001 From: Natalie Date: Tue, 5 May 2026 14:00:56 -0400 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20test(@projects/@magic-civilization)?= =?UTF-8?q?:=20=F0=9F=A7=AA=20add=20serde=20round-trip=20and=20default=20m?= =?UTF-8?q?ode=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Lilith Autocommit --- src/simulator/crates/mc-core/src/lair.rs | 75 ++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/src/simulator/crates/mc-core/src/lair.rs b/src/simulator/crates/mc-core/src/lair.rs index f93edfda..7b85931b 100644 --- a/src/simulator/crates/mc-core/src/lair.rs +++ b/src/simulator/crates/mc-core/src/lair.rs @@ -112,6 +112,81 @@ mod tests { assert_eq!(LairCombatMode::default(), LairCombatMode::Assault); } + // ── p3-10a acceptance-named tests ────────────────────────────────── + // Aliases that match the names cited in the objective brief so a + // grep for the canonical test names resolves directly. Bodies are + // deliberately distinct (round-trip via Vec, default-as-existing- + // callers contract, total-Ord consistency over the full variant + // set) to give independent coverage rather than duplicating the + // older tests above. + + #[test] + fn test_lair_mode_serde_round_trip() { + // Round-trip every variant through a Vec to exercise the derived + // Serialize/Deserialize end-to-end (not just one variant at a time). + let all = vec![ + LairCombatMode::Assault, + LairCombatMode::Siege, + LairCombatMode::Raid, + ]; + let json = serde_json::to_string(&all).expect("serialise vec of modes"); + assert_eq!(json, "[\"assault\",\"siege\",\"raid\"]"); + let back: Vec = + serde_json::from_str(&json).expect("deserialise vec of modes"); + assert_eq!(back, all); + } + + #[test] + fn test_assault_is_default_mode_for_existing_callers() { + // Existing callers in `mc-turn` and `api-gdext` rely on `Default` + // returning `Assault` so wiring `mode: LairCombatMode` defaults to + // unchanged behaviour. Pin that contract. + let m: LairCombatMode = Default::default(); + assert_eq!(m, LairCombatMode::Assault); + // And: a freshly Default-constructed mode must be the only variant + // for which `resolve_lair_combat` (in mc-combat) returns Ok — the + // siege/raid stubs deliberately error. We only check the local + // contract here; the dispatcher contract lives in mc-combat. + assert!(matches!(m, LairCombatMode::Assault)); + } + + #[test] + fn test_lair_mode_ord_consistent_with_all_variants() { + // `Ord` is derived; lock in the declared order + // (Assault < Siege < Raid) so JSON-config code that sorts modes + // by enum order keeps a stable shape across crate refactors. + let mut all = vec![ + LairCombatMode::Raid, + LairCombatMode::Assault, + LairCombatMode::Siege, + ]; + all.sort(); + assert_eq!( + all, + vec![ + LairCombatMode::Assault, + LairCombatMode::Siege, + LairCombatMode::Raid, + ] + ); + + // Total-order consistency: comparing every pair must agree with + // PartialOrd and be antisymmetric. + let variants = [ + LairCombatMode::Assault, + LairCombatMode::Siege, + LairCombatMode::Raid, + ]; + for a in &variants { + for b in &variants { + assert_eq!(a.cmp(b), a.partial_cmp(b).unwrap()); + if a != b { + assert_ne!(a.cmp(b), std::cmp::Ordering::Equal); + } + } + } + } + #[test] fn lair_id_round_trips_as_bare_string() { let id = LairId::new("frostfang_den_01");