From 082f0bba38b24474f7a4bd20dfd224d3571b2fc1 Mon Sep 17 00:00:00 2001 From: emilis Date: Fri, 7 Nov 2025 20:33:04 +0000 Subject: [PATCH] update tests in line with new changes --- werewolves-proto/src/game/village.rs | 5 ++- werewolves-proto/src/game_test/mod.rs | 42 ++++++++++++------- werewolves-proto/src/game_test/revert.rs | 14 +------ werewolves-proto/src/game_test/role/elder.rs | 26 ++++-------- .../src/game_test/role/scapegoat.rs | 29 ++++++------- werewolves-proto/src/role.rs | 7 +++- werewolves/src/clients/host/story_test.rs | 38 ++++++++++------- 7 files changed, 83 insertions(+), 78 deletions(-) diff --git a/werewolves-proto/src/game/village.rs b/werewolves-proto/src/game/village.rs index daddc8b..fd9efc4 100644 --- a/werewolves-proto/src/game/village.rs +++ b/werewolves-proto/src/game/village.rs @@ -71,7 +71,10 @@ impl Village { pub fn wolf_revert_prompt(&self) -> Option { self.killing_wolf() - .filter(|killing_wolf| RoleTitle::Werewolf != killing_wolf.role_title()) + .filter(|killing_wolf| { + RoleTitle::Werewolf != killing_wolf.role_title() + && !killing_wolf.role_title().killing_wolf() + }) .map(|killing_wolf| ActionPrompt::RoleChange { character_id: killing_wolf.identity(), new_role: RoleTitle::Werewolf, diff --git a/werewolves-proto/src/game_test/mod.rs b/werewolves-proto/src/game_test/mod.rs index edc5206..ed88f24 100644 --- a/werewolves-proto/src/game_test/mod.rs +++ b/werewolves-proto/src/game_test/mod.rs @@ -83,9 +83,13 @@ pub trait ActionPromptTitleExt { fn insomniac(&self); fn power_seer(&self); fn mortician(&self); + fn elder_reveal(&self); } impl ActionPromptTitleExt for ActionPromptTitle { + fn elder_reveal(&self) { + assert_eq!(*self, ActionPromptTitle::ElderReveal); + } fn mortician(&self) { assert_eq!(*self, ActionPromptTitle::Mortician); } @@ -1065,21 +1069,29 @@ fn big_game_test_based_on_story_test() { game.living_villager_excl(protect.player_id()) .character_id(), ); - assert_eq!( - game.execute(), - ActionPrompt::RoleChange { - character_id: game.character_by_player_id(shapeshifter).identity(), - new_role: RoleTitle::Werewolf - } - ); - game.r#continue().sleep(); - game.next().title().vindicator(); + game.execute().title().vindicator(); game.mark(game.character_by_player_id(shapeshifter).character_id()); game.r#continue().sleep(); game.next().title().wolf_pack_kill(); game.mark(game.character_by_player_id(empath).character_id()); + game.r#continue().r#continue(); + + game.next().title().shapeshifter(); + game.process(HostGameMessage::Night(HostNightMessage::ActionResponse( + ActionResponse::Shapeshift, + ))) + .expect("shapeshift"); + // game.r#continue().r#continue(); + + assert_eq!( + game.next(), + ActionPrompt::RoleChange { + character_id: game.character_by_player_id(empath).identity(), + new_role: RoleTitle::Werewolf + } + ); game.r#continue().sleep(); game.next().title().seer(); @@ -1142,23 +1154,23 @@ fn big_game_test_based_on_story_test() { game.next().title().arcanist(); game.mark(game.character_by_player_id(insomniac).character_id()); - game.mark(game.character_by_player_id(shapeshifter).character_id()); + game.mark(game.character_by_player_id(empath).character_id()); game.r#continue().arcanist(); game.r#continue().sleep(); game.next().title().adjudicator(); - game.mark(game.character_by_player_id(shapeshifter).character_id()); + game.mark(game.character_by_player_id(empath).character_id()); game.r#continue().adjudicator(); game.r#continue().sleep(); game.next().title().power_seer(); - game.mark(game.character_by_player_id(shapeshifter).character_id()); + game.mark(game.character_by_player_id(empath).character_id()); game.r#continue().power_seer(); game.r#continue().sleep(); game.next().title().gravedigger(); - game.mark(game.character_by_player_id(empath).character_id()); - assert_eq!(game.r#continue().gravedigger(), Some(RoleTitle::Empath)); + game.mark(game.character_by_player_id(shapeshifter).character_id()); + assert_eq!(game.r#continue().gravedigger(), None); game.r#continue().sleep(); game.next().title().mortician(); @@ -1174,7 +1186,7 @@ fn big_game_test_based_on_story_test() { game.r#continue().sleep(); game.next().title().hunter(); - game.mark(game.character_by_player_id(shapeshifter).character_id()); + game.mark(game.character_by_player_id(empath).character_id()); game.r#continue().sleep(); game.next().title().insomniac(); diff --git a/werewolves-proto/src/game_test/revert.rs b/werewolves-proto/src/game_test/revert.rs index 8021af4..5722fb0 100644 --- a/werewolves-proto/src/game_test/revert.rs +++ b/werewolves-proto/src/game_test/revert.rs @@ -23,12 +23,7 @@ use crate::{ #[test] fn sole_non_werewolf_wolves_revert() { - const REVERTING_WOLVES: &[SetupRole] = &[ - SetupRole::DireWolf, - SetupRole::LoneWolf, - SetupRole::AlphaWolf, - SetupRole::Shapeshifter, - ]; + const REVERTING_WOLVES: &[SetupRole] = &[SetupRole::DireWolf]; init_log(); for wolf_role in REVERTING_WOLVES { let role_title = Into::::into(wolf_role.clone()); @@ -72,12 +67,7 @@ fn sole_non_werewolf_wolves_revert() { #[test] fn wolves_revert_on_werewolf_death() { - const REVERTING_WOLVES: &[SetupRole] = &[ - SetupRole::DireWolf, - SetupRole::LoneWolf, - SetupRole::AlphaWolf, - SetupRole::Shapeshifter, - ]; + const REVERTING_WOLVES: &[SetupRole] = &[SetupRole::DireWolf]; init_log(); for wolf_role in REVERTING_WOLVES { let role_title = Into::::into(wolf_role.clone()); diff --git a/werewolves-proto/src/game_test/role/elder.rs b/werewolves-proto/src/game_test/role/elder.rs index 1c82c79..3d1ec4e 100644 --- a/werewolves-proto/src/game_test/role/elder.rs +++ b/werewolves-proto/src/game_test/role/elder.rs @@ -99,20 +99,15 @@ fn doesnt_die_first_try_night_knows() { game.r#continue().sleep(); game.next_expect_day(); - game.execute().title().wolf_pack_kill(); + game.execute().title().elder_reveal(); + game.r#continue().sleep(); + + game.next().title().wolf_pack_kill(); let elder = game.character_by_player_id(elder_player_id); game.mark_and_check(elder.character_id()); game.r#continue().sleep(); - assert_eq!( - game.next(), - ActionPrompt::ElderReveal { - character_id: elder.identity() - }, - ); - game.r#continue().sleep(); - game.next_expect_day(); let elder = game.character_by_player_id(elder_player_id); @@ -236,7 +231,10 @@ fn elder_executed_knows_no_powers_incl_hunter_activation() { game.next_expect_day(); - game.execute().title().wolf_pack_kill(); + game.execute().title().elder_reveal(); + game.r#continue().sleep(); + + game.next().title().wolf_pack_kill(); game.mark(villagers.next().unwrap()); game.r#continue().sleep(); @@ -249,14 +247,6 @@ fn elder_executed_knows_no_powers_incl_hunter_activation() { game.mark(game.character_by_player_id(wolf_player_id).character_id()); game.r#continue().sleep(); - assert_eq!( - game.next(), - ActionPrompt::ElderReveal { - character_id: game.character_by_player_id(elder_player_id).identity() - } - ); - game.r#continue().sleep(); - game.next_expect_day(); assert_eq!( diff --git a/werewolves-proto/src/game_test/role/scapegoat.rs b/werewolves-proto/src/game_test/role/scapegoat.rs index eb21766..ca1a616 100644 --- a/werewolves-proto/src/game_test/role/scapegoat.rs +++ b/werewolves-proto/src/game_test/role/scapegoat.rs @@ -118,8 +118,20 @@ fn redeemed_scapegoat_role_changes() { night: NonZero::new(1).unwrap() } ); + assert_eq!( + game.execute(), + ActionPrompt::RoleChange { + character_id: game.character_by_player_id(scapegoat_player_id).identity(), + new_role: RoleTitle::Seer + } + ); + game.r#continue().r#continue(); + game.next().title().seer(); + game.mark(game.character_by_player_id(wolf_player_id).character_id()); + assert_eq!(game.r#continue().seer(), Alignment::Wolves); + game.r#continue().sleep(); - assert_eq!(game.execute().title(), ActionPromptTitle::WolfPackKill); + assert_eq!(game.next().title(), ActionPromptTitle::WolfPackKill); let wolf_target_2 = game .village() .characters() @@ -129,21 +141,6 @@ fn redeemed_scapegoat_role_changes() { .character_id(); game.mark_and_check(wolf_target_2); game.r#continue().sleep(); - let scapegoat = game - .village() - .characters() - .into_iter() - .find(|c| c.player_id() == scapegoat_player_id) - .unwrap() - .clone(); - assert_eq!( - game.next(), - ActionPrompt::RoleChange { - character_id: scapegoat.identity(), - new_role: RoleTitle::Seer - } - ); - game.r#continue().sleep(); game.next_expect_day(); diff --git a/werewolves-proto/src/role.rs b/werewolves-proto/src/role.rs index 91edbf7..4d576dd 100644 --- a/werewolves-proto/src/role.rs +++ b/werewolves-proto/src/role.rs @@ -247,11 +247,13 @@ pub enum Role { #[checks(Killer::Killer)] #[checks(Powerful::Powerful)] #[checks("wolf")] + #[checks("killing_wolf")] Werewolf, #[checks(Alignment::Wolves)] #[checks(Killer::Killer)] #[checks(Powerful::Powerful)] #[checks("wolf")] + #[checks("killing_wolf")] AlphaWolf { killed: Option }, #[checks(Alignment::Village)] #[checks(Killer::Killer)] @@ -262,6 +264,7 @@ pub enum Role { #[checks(Killer::Killer)] #[checks(Powerful::Powerful)] #[checks("wolf")] + #[checks("killing_wolf")] Shapeshifter { shifted_into: Option }, #[checks(Alignment::Wolves)] #[checks(Killer::Killer)] @@ -274,7 +277,9 @@ impl Role { /// [RoleTitle] as shown to the player on role assignment pub const fn initial_shown_role(&self) -> RoleTitle { match self { - Role::Apprentice(_) | Role::Elder { .. } | Role::Insomniac => RoleTitle::Villager, + Role::Scapegoat { .. } | Role::Apprentice(_) | Role::Elder { .. } | Role::Insomniac => { + RoleTitle::Villager + } _ => self.title(), } } diff --git a/werewolves/src/clients/host/story_test.rs b/werewolves/src/clients/host/story_test.rs index a77496d..ddef57f 100644 --- a/werewolves/src/clients/host/story_test.rs +++ b/werewolves/src/clients/host/story_test.rs @@ -350,21 +350,29 @@ pub fn test_story() -> GameStory { game.living_villager_excl(protect.player_id()) .character_id(), ); - assert_eq!( - game.execute(), - ActionPrompt::RoleChange { - character_id: game.character_by_player_id(shapeshifter).identity(), - new_role: RoleTitle::Werewolf - } - ); - game.r#continue().sleep(); - game.next().title().vindicator(); + game.execute().title().vindicator(); game.mark(game.character_by_player_id(shapeshifter).character_id()); game.r#continue().sleep(); game.next().title().wolf_pack_kill(); game.mark(game.character_by_player_id(empath).character_id()); + game.r#continue().r#continue(); + + game.next().title().shapeshifter(); + game.process(HostGameMessage::Night(HostNightMessage::ActionResponse( + ActionResponse::Shapeshift, + ))) + .expect("shapeshift"); + // game.r#continue().r#continue(); + + assert_eq!( + game.next(), + ActionPrompt::RoleChange { + character_id: game.character_by_player_id(empath).identity(), + new_role: RoleTitle::Werewolf + } + ); game.r#continue().sleep(); game.next().title().seer(); @@ -427,23 +435,23 @@ pub fn test_story() -> GameStory { game.next().title().arcanist(); game.mark(game.character_by_player_id(insomniac).character_id()); - game.mark(game.character_by_player_id(shapeshifter).character_id()); + game.mark(game.character_by_player_id(empath).character_id()); game.r#continue().arcanist(); game.r#continue().sleep(); game.next().title().adjudicator(); - game.mark(game.character_by_player_id(shapeshifter).character_id()); + game.mark(game.character_by_player_id(empath).character_id()); game.r#continue().adjudicator(); game.r#continue().sleep(); game.next().title().power_seer(); - game.mark(game.character_by_player_id(shapeshifter).character_id()); + game.mark(game.character_by_player_id(empath).character_id()); game.r#continue().power_seer(); game.r#continue().sleep(); game.next().title().gravedigger(); - game.mark(game.character_by_player_id(empath).character_id()); - assert_eq!(game.r#continue().gravedigger(), Some(RoleTitle::Empath)); + game.mark(game.character_by_player_id(shapeshifter).character_id()); + assert_eq!(game.r#continue().gravedigger(), None); game.r#continue().sleep(); game.next().title().mortician(); @@ -459,7 +467,7 @@ pub fn test_story() -> GameStory { game.r#continue().sleep(); game.next().title().hunter(); - game.mark(game.character_by_player_id(shapeshifter).character_id()); + game.mark(game.character_by_player_id(empath).character_id()); game.r#continue().sleep(); game.next().title().insomniac();