From f8513c1bec319812e4c00634187e2b2de9145eb1 Mon Sep 17 00:00:00 2001 From: Evan Slack Date: Mon, 9 Dec 2024 00:42:08 -0500 Subject: [PATCH] test the joker --- src/core/game.rs | 3 +++ src/core/joker.rs | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/src/core/game.rs b/src/core/game.rs index bb52acd..2691af6 100644 --- a/src/core/game.rs +++ b/src/core/game.rs @@ -228,6 +228,9 @@ impl Game { } pub fn buy_joker(&mut self, joker: Jokers) -> Result<(), GameError> { + if self.stage != Stage::Shop { + return Err(GameError::InvalidStage); + } self.jokers.push(joker); self.effect_registry .register_jokers(self.jokers.clone(), &self.clone()); diff --git a/src/core/joker.rs b/src/core/joker.rs index 6a8ae07..246bb90 100644 --- a/src/core/joker.rs +++ b/src/core/joker.rs @@ -122,3 +122,41 @@ impl Joker for LustyJoker { vec![Effects::OnScore(Arc::new(apply))] } } + +#[cfg(test)] +mod tests { + use crate::core::card::{Card, Suit, Value}; + use crate::core::hand::SelectHand; + use crate::core::stage::{Blind, Stage}; + + use super::*; + + #[test] + fn test_the_joker() { + let mut g = Game::new(); + g.stage = Stage::Blind(Blind::Small); + let j = Jokers::TheJoker(TheJoker {}); + + let ace = Card::new(Value::Ace, Suit::Heart); + let hand = SelectHand::new(vec![ace]); + + // Score Ace high without joker + // High card (level 1) -> 5 chips, 1 mult + // Played cards (1 ace) -> 11 chips + // (5 + 11) * (1) = 16 + let score = g.calc_score(hand.best_hand().unwrap()); + assert_eq!(score, 16); + + // buy (and apply) the joker + g.stage = Stage::Shop; + g.buy_joker(j).unwrap(); + g.stage = Stage::Blind(Blind::Small); + // Score Ace high with the Joker + // High card (level 1) -> 5 chips, 1 mult + // Played cards (1 ace) -> 11 chips + // Joker (The Joker) -> 4 mult + // (5 + 11) * (1 + 4) = 80 + let score = g.calc_score(hand.best_hand().unwrap()); + assert_eq!(score, 80); + } +}