def test_store_played_game_known_player(self): tournament = Tournament() tournament.register_player("player1") tournament.store_played_game(PlayedGame("player1", 17)) self.assertEqual(tournament.played_games, [PlayedGame("player1", 17)])
def test_leaderboard_games_played_ordered_by_points(self): tournament = Tournament() tournament.register_player("player1") tournament.register_player("player2") tournament.store_played_game(PlayedGame("player1", 15)) tournament.store_played_game(PlayedGame("player2", 18)) self.assertEqual(tournament.leaderboard(), [Rank("player2", 18), Rank("player1", 15)])
def test_finish(self): tournament = Tournament() tournament.register_player("player1") tournament.prepare_game("player1") tournament.start_game() tournament.finish_game() self.assertIsNone(tournament.current_game) self.assertEqual(tournament.played_games, [PlayedGame("player1", 0)])
def test_store_json(self): tournament = Tournament() tournament.register_player("player1") tournament.prepare_game( "player1") tournament.start_game() tournament.finish_game() tournament.register_player("player2") tournament.prepare_game( "player2") tournament.start_game() tournament.finish_game() storage = JsonTournamentStorage() storage.store_tournament(tournament) tournament = storage.load_tournament() self.assertIsNotNone(tournament) self.assertIsNone(tournament.current_game) self.assertEqual(tournament.played_games, [PlayedGame("player1", 0),PlayedGame("player2", 0)])
def test_update_robot_state(self): tournament = Tournament() tournament.register_player("player1") tournament.prepare_game("player1") tournament.start_game() first_point = tournament.current_game.game.points()[0] tournament.update_robot_position({'x': first_point.x, 'y': first_point.y, 'r': 5}) tournament.finish_game() self.assertIsNone(tournament.current_game) self.assertEqual(tournament.played_games, [PlayedGame("player1", first_point.score)])