Skip to content

Commit

Permalink
fix flaky test
Browse files Browse the repository at this point in the history
AI in test would sometimes unexpectedly play a draw two, which affected
the number of cards in the player's hand and make the test assertion
fail.
  • Loading branch information
dyllandry committed May 31, 2023
1 parent a5404a9 commit 3e0d8ce
Showing 1 changed file with 1 addition and 5 deletions.
6 changes: 1 addition & 5 deletions src/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ fn draw_cards(
}

// -1 because you have to leave the top card in the discard pile and cant put it in the deck
if deck.len() + discard.len() - 1 < num_to_draw as usize {
if deck.len() + discard.len() < num_to_draw as usize {
panic!(
"There are not enough cards left for the player to draw. {} cards in deck + discard but player wants to draw {}.",
deck.len() + discard.len(),
Expand Down Expand Up @@ -970,12 +970,8 @@ mod tests {
ai_player.hand.insert(0, valid_next_card);
};

// It's technically necessary for a human to go first to start the game, so providing this input gets the human player to go.
uno.input(Input::Number(1));

let human_player_num_cards_before = {
let human_player = uno.players.iter_mut().find(|player| !player.ai).unwrap();
human_player.hand.insert(0, valid_next_card);
human_player.hand.len()
};

Expand Down

0 comments on commit 3e0d8ce

Please sign in to comment.