def test_jump_actions(): player1 = Player("player1") player2 = Player("player2") players = [player1, player2] card1 = NumberedCard(color="BLUE", number="1") card2 = NumberedCard(color="RED", number="1") card3 = JumpCard(color="BLUE") assert card3.actions(card1, 0, players, Deck()) == 1 assert card3.actions(card1, 1, players, Deck()) == 0 with pytest.raises(UnoRuleException): card3.actions(card2, 1, players, Deck())
def test_joker_actions(): player1 = Player("player1") player2 = Player("player2") players = [player1, player2] card1 = JokerCard() card2 = JokerCard() card3 = NumberedCard(color="BLUE", number="1") card2.setColor("BLUE") assert card2.actions(card1, 0, players, Deck()) == 0 assert card3.actions(card2, 0, players, Deck()) == 0 with pytest.raises(UnoRuleException): card3.actions(card1, 1, players, Deck())
def test_play_player2(): global game player2 = game.players[1] player2.playCard(player2.cards[0].id) blue = NumberedCard(color="BLUE", number="1") player2.addCard(blue) assert game.register_play(player2.id, blue.id)
def test_play_player2_remember_uno(): global game player2 = game.players[1] blue = NumberedCard(color="BLUE", number="1") player2.cards = player2.cards[:1] player2.addCard(blue) assert game.register_play(player2.id, blue.id, unoFlag=True)
def test_numbered_actions(): player1 = Player("player1") player2 = Player("player2") players = [player1, player2] card1 = NumberedCard(color="BLUE", number="1") card2 = NumberedCard(color="BLUE", number="2") card3 = NumberedCard(color="RED", number="2") # positive cases assert card2.actions(card1, 0, players, Deck()) == 0 assert card3.actions(card2, 1, players, Deck()) == 1 # negative case with pytest.raises(UnoRuleException): card3.actions(card1, 1, players, Deck())
def test_play_first_card(): global game player1 = game.players[0] # pick a card and assert player1.playCard(player1.cards[0].id) assert len(player1.cards) == 4 # player1 play random card blue = NumberedCard(color="BLUE", number="1") player1.addCard(blue) assert game.register_play(player1.id, blue.id)
def test_play_player1_winner(): global game player1 = game.players[0] blue = NumberedCard(color="BLUE", number="1") player1.cards = [blue] with pytest.raises(UnoWinnerException): game.register_play(player1.id, blue.id) # check penalty assert len(player1.cards) == 0
def test_play_player1_forget_uno(): global game player1 = game.players[0] blue = NumberedCard(color="BLUE", number="1") player1.cards = player1.cards[:1] player1.addCard(blue) game.register_play(player1.id, blue.id) # check penalty assert len(player1.cards) == 3 assert game.playerToPlay == 1
def test_play_wrong_player(): global game player1 = game.players[0] # add card to player player1.playCard(player1.cards[0].id) blue = NumberedCard(color="BLUE", number="1") player1.addCard(blue) # play card with pytest.raises(UnoRuleException): game.register_play(player1.id, blue.id) assert len(game._Game__play_history) == 1 assert game.playerToPlay == 1
def test_inverted_actions(): player1 = Player("player1") player2 = Player("player2") players = [player1, player2] card1 = InvertedCard(color="BLUE") card2 = InvertedCard(color="BLUE") card3 = InvertedCard(color="RED") card4 = NumberedCard(color="BLUE", number="2") assert card2.actions(card1, 0, players, Deck()) == 1 assert players == [player2, player1] assert card3.actions(card1, 1, players, Deck()) == 0 assert players == [player1, player2] with pytest.raises(UnoRuleException): card3.actions(card4, 1, players, Deck())
def test_jokerplusfour_actions(): player1 = Player("player1") player2 = Player("player2") players = [player1, player2] card1 = JokerPlusFourCard() card2 = JokerPlusFourCard() card3 = NumberedCard(color="RED", number="1") card4 = NumberedCard(color="BLUE", number="1") card1.setColor(color="BLUE") assert card2.actions(card1, 0, players, Deck()) == 0 assert len(player2.cards) == 4 with pytest.raises(UnoRuleException): card3.actions(card1, 1, players, Deck()) assert card4.actions(card1, 0, players, Deck()) == 0