示例#1
0
    def test_team_should_set_notsettream_at_constructor(self):
        # Arrange & Act
        game = FootballGame()

        # Assert
        self.assertFalse(game.get_team1().is_set())
        self.assertFalse(game.get_team1().is_set())
示例#2
0
    def test_running_game_should_declare_winner_at_end(self):
        # Arrange & Act
        game_result = FootballGame() \
                        .team1(FootballTeam(name='team1')) \
                        .team2(FootballTeam(name='team2')) \
                        .run()

        # Assert
        winner = game_result.get_winner()
        self.assertTrue(winner.get_name() == 'team1' or winner.get_name() == 'team2')
示例#3
0
    def test_should_set_players_of_game(self):
        # Arrange & Act
        game = FootballGame() \
                .team1(FootballTeam(name='team356')) \
                .team2(FootballTeam(name='team861'))

        # Assert
        self.assertTrue(game.get_team1().is_set())
        self.assertTrue(game.get_team2().is_set())
        self.assertEqual(game.get_team1().get_name(), 'team356')
        self.assertEqual(game.get_team2().get_name(), 'team861')
示例#4
0
    def test_add_client_should_return_client_when_get_clients(self):
        # Arrange
        mock_client = Mock(spec=FootballGameClient)

        # Act
        game = FootballGame() \
                .team1(FootballTeam(name='team1')) \
                .team2(FootballTeam(name='team2')) \
                .add_client(mock_client)

        # Assert
        self.assertTrue(mock_client in game.get_clients())
示例#5
0
def main():
    console = ConsoleClient()

    teama = FootballTeam() \
                .name('teama')
    teamb = FootballTeam().name('teamb')

    game = FootballGame() \
            .gameid(1) \
            .team1(teama) \
            .team2(teamb) \
            .add_client(console)

    game.run()
示例#6
0
    def test_running_game_should_call_and_return_simulation_rungame(self):
        # Arrange & Act
        mock_simulation = Mock(spec=type(football_simulation))
        team1 = FootballTeam(name='team1')
        team2 = FootballTeam(name='team2')

        # Act
        game = FootballGame() \
                .team1(team1) \
                .team2(team2) \
                .simulation(mock_simulation)
        game_result = game.run()

        # Assert
        mock_simulation.run_game.assert_called_once_with(game)
示例#7
0
    def test_add_client_should_get_events_from_simulation(self):
        # Arrange
        event = Event('my event')
        def mock_run_game(game):
            for client in game.get_clients():
                client.on_event(event=event)

        mock_client = Mock(spec=FootballGameClient)
        mock_simulation = Mock(spec=type(football_simulation))
        mock_simulation.run_game = mock_run_game

        # Act
        game = FootballGame() \
                .team1(FootballTeam(name='team1')) \
                .team2(FootballTeam(name='team2')) \
                .simulation(mock_simulation) \
                .add_client(mock_client)
        game.run()

        # Assert
        mock_client.on_event.assert_called_once_with(event=event)
示例#8
0
    def test_simulation_should_be_set_to_football(self):
        # Arrange
        game = FootballGame()

        # Assert
        self.assertEqual(game.get_simulation(), football_simulation)
示例#9
0
    def test_name_should_set_name(self):
        # Arrange & Act
        game = FootballGame().gameid(40)

        # Assert
        self.assertEqual(game.get_gameid(), 40)