def test_on_playing_draw_4_next_player_takes_4_card(self): players = [ Player(name="Naruto", cards=[]), Player(name="Sasuke", cards=[]), Player(name="Sakura", cards=[]) ] game = Game(players, deck, disable_output=True) # Overwriting variables for mocking game.top_card = Card("BLUE", action="REVERSE") game.discard_pile = [Card("BLUE", action="REVERSE")] players[1].cards = [ Card("RED", 5), Card("YELLOW", 4), Card("RED", 2), Card("GREEN", action="SKIP"), Card(wild="WILD_DRAW_FOUR") ] # Here the draw 4 card is the only valid play game.play_turn() self.assertTrue(game.top_card.is_d4) self.assertEqual(game.last_player_decision, "PLAY") game.current_player = 2 # Need to manually set it here for the tests # Next turn. This player should pick two cards game.play_turn() self.assertEqual(len(players[2].cards), 11) # 7+4
def test_player_should_play_draw_four_only_if_no_other_valid_cards(self): players = [ Player(name="Naruto", cards=[]), Player(name="Sasuke", cards=[]), Player(name="Sakura", cards=[]) ] game = Game(players, deck, disable_output=True) # Overwriting variables for mocking game.top_card = Card("BLUE", action="REVERSE") game.discard_pile = [Card("BLUE", action="REVERSE")] players[1].cards = [ Card("YELLOW", action="REVERSE"), Card("RED", 2), Card("GREEN", action="SKIP"), Card(wild="WILD_DRAW_FOUR"), Card("BLUE", action="DRAW_TWO") ] # Blue Draw two -> value = 20 # Yellow Reverse -> Value = 20 # Wild Draw Four -> value = 50 game.play_turn() # ALtghough Draw four is the card with the highest value but since we # can still play yellow reverse or blue draw two, draw four shouldn't be # played self.assertFalse(game.top_card.is_wild_card) self.assertFalse(game.top_card.is_d4)
def test_player_plays_the_card_with_the_highest_value(self): players = [ Player(name="Naruto", cards=[]), Player(name="Sasuke", cards=[]), Player(name="Sakura", cards=[]) ] game = Game(players, deck, disable_output=True) # Overwriting variables for mocking game.top_card = Card("BLUE", action="REVERSE") game.discard_pile = [Card("BLUE", action="REVERSE")] players[1].cards = [ Card("YELLOW", action="REVERSE"), Card("RED", 2), Card("GREEN", action="SKIP"), Card(wild="WILD"), Card("BLUE", action="DRAW_TWO") ] # Blue Draw two -> value = 20 # Yellow Reverse -> Value = 20 # Wild Draw Four -> value = 50l game.play_turn() self.assertTrue(game.top_card.is_wild_card) self.assertTrue(game.top_card.wild == "WILD")
def test_reverse_should_flip_direction_and_change_next_player(self): players = [ Player(name="Naruto", cards=[]), Player(name="Sasuke", cards=[]), Player(name="Sakura", cards=[]) ] game = Game(players, deck, disable_output=True) # Overwriting variables for mocking game.top_card = Card("BLUE", action="REVERSE") game.discard_pile = [Card("BLUE", action="REVERSE")] players[1].cards = [ Card("RED", action="REVERSE"), Card("YELLOW", 4), Card("RED", 2), Card("GREEN", action="SKIP") ] # Here the reverse card is the only valid play game.play_turn() self.assertFalse(game.is_clockwise) self.assertEqual(game.next_player, 0)
def test_wild_cards_played_should_have_a_color_associated_with_them(self): players = [ Player(name="Naruto", cards=[]), Player(name="Sasuke", cards=[]), Player(name="Sakura", cards=[]) ] game = Game(players, deck, disable_output=True) # Overwriting variables for mocking game.top_card = Card("BLUE", action="REVERSE") game.discard_pile = [Card("BLUE", action="REVERSE")] players[1].cards = [ Card("RED", 5), Card("YELLOW", 4), Card("RED", 2), Card("GREEN", action="SKIP"), Card(wild="WILD") ] # Here the wild card is the only valid play game.play_turn() self.assertTrue(game.top_card.is_wild_card) self.assertTrue(game.top_card.color) # Shouldn't be None
def test_player_has_an_extra_card_if_there_Are_no_valid_cards(self): players = [Player(name="DSP", cards=[]), Player(name="SPD", cards=[])] game = Game(players, deck, disable_output=True) # Overwriting variables for mocking game.top_card = Card("BLUE", 4) game.discard_pile = [Card("BLUE", 4)] players[1].cards = [Card("RED", 5)] * 7 game.start() self.assertEqual(len(players[1].cards), 8)
def test_winner_is_printed_when_a_game_ends(self): players = [ Player(name="Naruto", cards=[]), Player(name="Sasuke", cards=[]), Player(name="Sakura", cards=[]) ] game = Game(players, deck, disable_output=True) # Overwriting variables for mocking game.top_card = Card("BLUE", action="REVERSE") game.discard_pile = [Card("BLUE", action="REVERSE")] players[1].cards = [Card("BLUE", 5)] game.play_turn() self.assertEqual(game.winner, 1)
def test_pile_has_one_extra_card_after_players_turn(self): players = [Player(name="DSP", cards=[]), Player(name="SPD", cards=[])] game = Game(players, deck, disable_output=True) game.top_card = Card("BLUE", 4) game.discard_pile = [Card("BLUE", 4)] players[1].cards = [ Card("RED", action="REVERSE"), Card("YELLOW", 4), Card("RED", 2), Card("GREEN", 8), Card("BLUE", 8), Card("GREEN", action="DRAW_TWO"), Card("GREEN", action="DRAW_TWO") ] game.start() # Start the game after setup self.assertEqual(len(game.discard_pile), 2)
def test_top_card_should_be_updated_when_a_player_plays(self): players = [Player(name="DSP", cards=[]), Player(name="SPD", cards=[])] game = Game(players, deck, disable_output=True) # Overwriting variables for mocking game.top_card = Card("BLUE", 4) game.discard_pile = [Card("BLUE", 4)] players[1].cards = [ Card("RED", action="REVERSE"), Card("YELLOW", 4), Card("RED", 2), Card("GREEN", 8), Card("BLUE", 8), Card("GREEN", action="DRAW_TWO"), Card("GREEN", action="DRAW_TWO") ] game.start() self.assertEqual(game.top_card, game.discard_pile[-1])
def test_last_player_decision_is_play_if_player_plays(self): players = [Player(name="DSP", cards=[]), Player(name="SPD", cards=[])] game = Game(players, deck, disable_output=True) # Overwriting variables for mocking game.top_card = Card("BLUE", 4) game.discard_pile = [Card("BLUE", 4)] players[1].cards = [ Card("RED", action="REVERSE"), Card("YELLOW", 4), Card("RED", 2), Card("GREEN", 8), Card("BLUE", 8), Card("GREEN", action="DRAW_TWO"), Card("GREEN", action="DRAW_TWO") ] game.start() self.assertEqual(game.last_player_decision, "PLAY")
def test_player_played_a_valid_card(self): players = [Player(name="DSP", cards=[]), Player(name="SPD", cards=[])] game = Game(players, deck, disable_output=True) # Overwriting variables for mocking game.top_card = Card("BLUE", 4) game.discard_pile = [Card("BLUE", 4)] players[1].cards = [ Card("RED", action="REVERSE"), Card("YELLOW", 4), Card("RED", 2), Card("GREEN", 8), Card("BLUE", 8), Card("GREEN", action="DRAW_TWO"), Card("GREEN", action="DRAW_TWO") ] game.start() # Start the game after setup self.assertTrue( is_played_card_valid(game.discard_pile[1], game.discard_pile[0]))
def test_winner_name_is_printed(self): players = [ Player(name="Naruto", cards=[]), Player(name="Sasuke", cards=[]), Player(name="Sakura", cards=[]) ] captured_out = io.StringIO() sys.stdout = captured_out game = Game(players, deck, disable_output=False) # Overwriting variables for mocking game.top_card = Card("BLUE", action="REVERSE") game.discard_pile = [Card("BLUE", action="REVERSE")] players[1].cards = [Card("BLUE", 5)] game.play_turn() sys.stdout = sys.__stdout__ self.assertTrue("Winner: Sasuke" in captured_out.getvalue()) self.assertTrue("GAME OVER" in captured_out.getvalue())
def test_players_points_after_win(self): players = [ Player(name="Naruto", cards=[]), Player(name="Sasuke", cards=[]), Player(name="Sakura", cards=[]) ] game = Game(players, deck, disable_output=True) # Overwriting variables for mocking game.top_card = Card("BLUE", action="REVERSE") game.discard_pile = [Card("BLUE", action="REVERSE")] players[0].cards = [Card("RED", 2), Card("BLUE", action="SKIP")] players[2].cards = [ Card(wild="WILD_DRAW_FOUR"), Card("YELLOW", 8), Card("GREEN", action="REVERSE") ] players[1].cards = [Card("BLUE", 5)] game.play_turn() self.assertEqual(players[1].score, 100)
def test_skip_should_skip_the_next_player(self): players = [ Player(name="Naruto", cards=[]), Player(name="Sasuke", cards=[]), Player(name="Sakura", cards=[]) ] game = Game(players, deck, disable_output=True) # Overwriting variables for mocking game.top_card = Card("BLUE", action="SKIP") game.discard_pile = [Card("BLUE", action="SKIP")] players[1].cards = [ Card("RED", action="REVERSE"), Card("YELLOW", 4), Card("RED", 2), Card("GREEN", action="SKIP") ] # The player has to play skip here as that is the only valid card game.play_turn() self.assertEqual(game.next_player, 0)
def test_last_player_decision_is_take_if_player_takes(self): players = [Player(name="DSP", cards=[]), Player(name="SPD", cards=[])] game = Game(players, deck, disable_output=True) # Overwriting variables for mocking game.top_card = Card("BLUE", 4) game.discard_pile = [Card("BLUE", 4)] players[1].cards = [Card("RED", 5)] * 7 game.start() self.assertEqual(game.last_player_decision, "TAKE")