예제 #1
0
def test_get_players_sorted():
    """Run get_players with sorted flag to true."""
    # Set up variables
    ba1 = BaseAgent()
    ba2 = BaseAgent()
    cfe = CoinFlipEngine()
    lad = BaseLadder(game=cfe)
    lad.match_func = mock_match_func

    # Add players to the ladder
    lad.add_player(ba1)
    lad.add_player(ba2)

    # Run the game
    lad.run_game()

    # Check that the results are sorted in ascending elo
    players = lad.get_players(sort=True)

    player1 = players[0]
    player2 = players[1]

    assert player1.elo > player2.elo
    assert (player1.num_wins == 1 and player2.num_wins == 0)
    assert (player1.num_losses == 0 and player2.num_losses == 1)
예제 #2
0
def test_run_game():
    """Test run_game functions properly."""
    # Set up variables
    ba1 = BaseAgent()
    ba2 = BaseAgent()
    cfe = CoinFlipEngine()
    lad = BaseLadder(game=cfe)
    lad.match_func = mock_match_func

    # Add players to the ladder
    lad.add_player(ba1)
    lad.add_player(ba2)

    # Run the game
    lad.run_game()

    # Check that the ladder updated properly
    players = lad.get_players()

    player1 = players[0]
    player2 = players[1]

    # Only one elo value changes
    assert ((player1.elo > 1000 and player2.elo == 1000)
            or (player1.elo == 1000 and player2.elo > 1000))

    # Someone won the game
    assert ((player1.num_wins == 0 and player2.num_wins == 1)
            or (player1.num_wins == 1 and player2.num_wins == 0))

    # Someone lost the game
    assert ((player1.num_losses == 0 and player2.num_losses == 1)
            or (player1.num_losses == 1 and player2.num_losses == 0))