def test_join_game(self): ''' Join to a existing game ''' player0 = Player(u"player 0") player1 = Player(u"player 1") game = BasicGame(player0) game.join(player1)
def setUp(self): self.player0 = Player(u"player 0") self.player1 = Player(u"player 1") self.game = BasicGame(self.player0) self.game.join(self.player1)
class TestBasicGame(unittest.TestCase): ''' Test a Game class - is the implementation of the rules of the game (will be a server and need to validate every coup. ''' def setUp(self): self.player0 = Player(u"player 0") self.player1 = Player(u"player 1") self.game = BasicGame(self.player0) self.game.join(self.player1) def test_pieces(self): ''' Pieces on the board ''' game = self.game self.assertEqual(game._pieces[(0,0)]._player, self.player0) self.assertEqual(game._pieces[(2,2)]._player, self.player1) def test_turn(self): ''' After moving, it changes the player turn (not when runs "playerTurn()") ''' game = self.game self.assertEqual(game.playerTurn(), self.player0) self.assertEqual(game.playerTurn(), self.player0) game.move((0,0), (0,1)) self.assertEqual(game.playerTurn(), self.player1) game.move((2,2), (2,1)) self.assertEqual(game.playerTurn(), self.player0) def test_move(self): ''' Move pieces on the board ''' game = self.game self.assertTrue(game.move(initial=(0,0), final=(0,1))) self.assertEqual(game._pieces[(0,1)]._player, self.player0) def test_move_without_piece(self): ''' Raises exception when no piece in initial place ''' game = self.game self.assertRaises(InvalidAction, game.move, (1,1), (2,1)) def test_move_wrong_player(self): ''' Raises exception when wrong player try a movement (2,2) is a player1 piece, but player0 starts ''' game = self.game self.assertRaises(InvalidAction, game.move, (2,2), (2,1)) def test_move_wrong_destination(self): ''' Game not allow go 2 squares long ''' game = self.game self.assertRaises(InvalidAction, game.move, (0,0), (0,2)) self.assertRaises(InvalidAction, game.move, (0,0), (2,0)) self.assertRaises(InvalidAction, game.move, (0,0), (2,2)) def test_win(self): ''' Test when some player win the game ''' game = self.game self.assertEqual(game.win(), None) game.move( (0,0), (0,1) ) self.assertEqual(game.win(), None) game.move( (2,2), (2,1) ) self.assertEqual(game.win(), None) game.move( (0,1), (1,1) ) self.assertEqual(game.win(), None) game.move( (2,1), (1,1) ) # eat and win! self.assertEqual(game.win(), self.player1)
test_friendly_ship1 = MyUSV(uid=1, x=4, y=5, env=test_map) test_friendly_ship1.set_as_friendly() test_map.add_ship(test_friendly_ship1) test_friendly_ship2 = MyUSV(uid=2, x=5, y=4, env=test_map) test_friendly_ship2.set_as_friendly() test_map.add_ship(test_friendly_ship2) test_friendly_ship3 = MyUSV(uid=3, x=6, y=4, env=test_map) test_friendly_ship3.set_as_friendly() test_map.add_ship(test_friendly_ship3) test_friendly_ship4 = MyUSV(uid=4, x=5, y=6, env=test_map) test_friendly_ship4.set_as_friendly() test_map.add_ship(test_friendly_ship4) test_friendly_ship5 = MyUSV(uid=5, x=7, y=4, env=test_map) test_friendly_ship5.set_as_friendly() test_map.add_ship(test_friendly_ship5) test_friendly_ship6 = MyUSV(uid=6, x=7, y=5, env=test_map) test_friendly_ship6.set_as_friendly() test_map.add_ship(test_friendly_ship6) test_friendly_ship7 = MyUSV(uid=7, x=7, y=6, env=test_map) test_friendly_ship7.set_as_friendly() test_map.add_ship(test_friendly_ship7) test_enemy_ship = MyUSV(uid=8, x=10, y=10, env=test_map) test_enemy_ship.set_as_enemy() test_map.add_ship(test_enemy_ship) # print test_map game = BasicGame() game.set_map(test_map) game.start()