def test_terminar_partida_gana_humano_por_truco(self): game = Game() for i in range(8): game.hand.hidden_cards = [ [Card(SWORD, 1), Card(CUP, 3), Card(CUP, 2)], [Card(COARSE, 4), Card(COARSE, 4), Card(COARSE, 4)], ] with unittest.mock.patch("truco.player.CPUPlayer.ask_trucos", return_value='ACCEPTED'): game.play("TRUCO") with unittest.mock.patch("truco.player.CPUPlayer.cpu_play", return_value='PLAY'): game.play("0") with unittest.mock.patch("truco.player.CPUPlayer.cpu_play", return_value='PLAY'): game.play("0") self.assertEqual(game.players[0].score, 16) self.assertEqual(game.players[1].score, 0) self.assertEqual(game.is_playing, False) result = game.next_turn() self.assertEqual(result, "\nGame Over!")
def test_terminar_partida_gana_pc_por_envido(self): game = Game() for i in range(5): game.hand.hidden_cards = [ [Card(SWORD, 4), Card(SWORD, 4), Card(SWORD, 4)], [Card(CUP, 1), Card(CUP, 7), Card(CUP, 6)], ] with unittest.mock.patch("truco.player.CPUPlayer.ask_envido", return_value='ACCEPTED'): game.play("ENVIDO") with unittest.mock.patch("truco.player.CPUPlayer.cpu_play", return_value='PLAY'): game.play("0") with unittest.mock.patch("truco.player.CPUPlayer.cpu_play", return_value='PLAY'): game.play("0") self.assertEqual(game.players[1].score, 15) self.assertEqual(game.players[0].score, 0) self.assertEqual(game.is_playing, False) result = game.next_turn() self.assertEqual(result, "\nGame Over!")
def test_cantar_envido_gana_cpu(self, mock_ask_envido): game = Game() game.hand.hidden_cards = [ [Card(COARSE, 4), Card(COARSE, 3), Card(COARSE, 2)], [Card(SWORD, 1), Card(CUP, 6), Card(CUP, 7)], ] game.play("ENVIDO") # cpu accept envido... force random self.assertEqual(game.players[0].score, 0) self.assertEqual(game.players[1].score, 2)
def test_cpu_sing_envido_and_accept(self): game = Game() game.hand.hidden_cards = [ [Card(SWORD, 1), Card(CUP, 3), Card(CUP, 2)], [Card(COARSE, 4), Card(COARSE, 4), Card(COARSE, 4)], ] with unittest.mock.patch("truco.player.CPUPlayer.cpu_play", return_value='ENVIDO'): game.play('0') result = game.play('ACCEPTED') expected = 'Won the player: 0' self.assertEqual(expected, result)
def test_mensaje_next_turn_truco_accepted(self, mock_ask_envido): game = Game() game.play('TRUCO') game.hand.hidden_cards = [ [Card(SWORD, 3), Card(SWORD, 12), Card(GOLD, 10)], [Card(COARSE, 4), Card(COARSE, 4), Card(COARSE, 4)], ] expected = ('0 to play 3 espada\n' '1 to play 12 espada\n' '2 to play 10 oro\n' 'DECK: Go to the Deck \n') result = game.next_turn() self.assertEqual(expected, result)
def test_falta_de_envido_points(self, mock_ask_envido): game = Game() game.players[0].score = 22 game.players[1].score = 27 game.hand.hidden_cards[0] = [ Card(SWORD, 3), Card(SWORD, 7), Card(CUP, 2) ] game.hand.hidden_cards[1] = [ Card(CUP, 5), Card(SWORD, 3), Card(CUP, 3) ] self.assertTrue(game.hand.envido_fase) game.play("ENVIDO") game.play("ACCEPTED") self.assertEqual(game.envido_points(), 3)
def test_mensaje_next_turn_init(self): game = Game() game.hand.hidden_cards = [ [Card(CUP, 1), Card(COARSE, 7), Card(CUP, 12)], [Card(COARSE, 4), Card(COARSE, 4), Card(COARSE, 4)], ] result = game.next_turn() expected = ('0 to play 1 copa\n' '1 to play 7 basto\n' '2 to play 12 copa\n' 'ENVIDO, REAL_ENVIDO, FALTA_ENVIDO: Sing envido \n' 'DECK: Go to the Deck \n' 'TRUCO: Sing truco \n') self.assertEqual(result, expected)
def test_mensaje_next_turn_envido_accepted(self, mock_ask_envido): game = Game() game.play('ENVIDO') game.hand.hidden_cards = [ [Card(COARSE, 4), Card(COARSE, 5), Card(COARSE, 6)], [Card(COARSE, 4), Card(COARSE, 4), Card(COARSE, 4)], ] expected = ('0 to play 4 basto\n' '1 to play 5 basto\n' '2 to play 6 basto\n' 'DECK: Go to the Deck \n' 'TRUCO: Sing truco \n') result = game.next_turn() self.assertEqual(expected, result)
def test_cantar_truco_gana_humano(self): game = Game() game.board game.hand.hidden_cards = [ [Card(SWORD, 1), Card(CUP, 3), Card(CUP, 2)], [Card(COARSE, 4), Card(COARSE, 4), Card(COARSE, 4)], ] with unittest.mock.patch("truco.player.CPUPlayer.ask_trucos", return_value='ACCEPTED'): game.play("TRUCO") with unittest.mock.patch("truco.player.CPUPlayer.cpu_play", return_value='PLAY'): game.play("0") with unittest.mock.patch("truco.player.CPUPlayer.cpu_play", return_value='PLAY'): game.play("0") self.assertEqual(game.players[0].score, 2) self.assertEqual(game.players[1].score, 0)
def test_ganar_por_ser_mano_humano(self): game = Game() game.board game.hand.hidden_cards = [ [Card(COARSE, 4), Card(COARSE, 4), Card(COARSE, 4)], [Card(COARSE, 4), Card(COARSE, 4), Card(COARSE, 4)], ] with unittest.mock.patch("truco.player.CPUPlayer.cpu_play", return_value='PLAY'): game.play("0") with unittest.mock.patch("truco.player.CPUPlayer.cpu_play", return_value='PLAY'): game.play("0") with unittest.mock.patch("truco.player.CPUPlayer.cpu_play", return_value='PLAY'): game.play("0") self.assertEqual(game.players[0].score, 1) self.assertEqual(game.players[1].score, 0)