def test_match_error(): """Ensure RuntimeError is thrown when no players available to match.""" lad = BaseLadder() ba1 = BaseAgent(id_in="Ba1") lad.match_func = mock_match_func # Error thrown when no players available try: lad.match_players() assert False except RuntimeError: pass # Error thrown when only one player available lad.add_player(ba1) try: lad.match_players() assert False except RuntimeError: pass # Originally enough players, but not enough afterwards for _ in range(2): lad.add_player(BaseAgent()) try: lad.match_players() # 3 players in pool lad.match_players() # Only 1 player in pool assert False except RuntimeError: pass
def test_available_players(): """Test that available players picks out players not in games.""" lad = BaseLadder() ba1 = BaseAgent() ba2 = BaseAgent() ba3 = BaseAgent() lad.match_func = mock_match_func # No players are in games, so all available lad.add_player(ba1) lad.add_player(ba2) lad.add_player(ba3) assert len(lad.available_players) == 3 # One player is taken _, _ = lad.match_players() assert len(lad.available_players) == 1 assert lad.available_players[0] in [(ba2, 0), (ba3, 0), (ba1, 0)]
def test_match_basic(): """Test that match functions properly.""" # Set up variables lad = BaseLadder() ba1 = BaseAgent() ba2 = BaseAgent() # Use fake match function lad.match_func = mock_match_func # Add the players to the ladder lad.add_player(ba1) lad.add_player(ba2) # Generate a match (should be ba1 and ba2) _ = lad.match_players() # Assert that players get removed from player pool assert not lad.available_players assert lad.num_turns == 1 for player, _ in lad.player_pool: assert player.in_game