Exemple #1
0
 def test_players_per_type(self):
     """player_per_type() returns dict mapping names to non-neg numbers."""
     s = cs.Simulation([cs.Player, cs.LazyPlayer, cs.ResilientPlayer])
     p = s.players_per_type()
     assert all(k in ['Player', 'LazyPlayer', 'ResilientPlayer']
                for k in p.keys())
     assert all(v >= 0 for v in p.values())
Exemple #2
0
 def test_winners_per_type(self):
     """winners_per_type() returns dict mapping names to non-neg numbers."""
     s = cs.Simulation([cs.Player, cs.LazyPlayer, cs.ResilientPlayer])
     s.run_simulation(10)
     w = s.winners_per_type()
     assert all(k in ['Player', 'LazyPlayer', 'ResilientPlayer']
                for k in w.keys())
     assert all(v >= 0 for v in w.values())
Exemple #3
0
 def test_constructor_named(self):
     """Constructor with kw args works."""
     b = cs.Board()
     s = cs.Simulation(player_field=[cs.Player, cs.Player],
                       board=b,
                       seed=123,
                       randomize_players=True)
     assert isinstance(s, cs.Simulation)
 def test_run_simulation(self):
     """
     Checks that the length of the list for the run simulation method is
     5 after running 5 games
     """
     game_board = cs.Board()
     sim = cs.Simulation(board=game_board)
     sim.run_simulation(5)
     assert len(sim.game_list) == 5
 def test_winners_per_type(self):
     """
     Checks that the winners per type method counts the right amout of
     winners
     """
     sim = cs.Simulation(player_field=[cs.Player, cs.Player, cs.Player])
     sim.run_simulation(3)
     the_dictionary = sim.winners_per_type()
     assert the_dictionary['Player'] == 3
     assert the_dictionary['ResilientPlayer'] == 0
     assert the_dictionary['LazyPlayer'] == 0
Exemple #6
0
 def test_durations_per_type(self):
     """
     durations_per_type() returns dict mapping names to list of
     non-neg numbers.
     """
     s = cs.Simulation([cs.Player, cs.LazyPlayer, cs.ResilientPlayer])
     s.run_simulation(10)
     w = s.durations_per_type()
     assert all(k in ['Player', 'LazyPlayer', 'ResilientPlayer']
                for k in w.keys())
     assert all(len(v) >= 0 for v in w.values())
     assert all(n >= 0 for v in w.values() for n in v)
Exemple #7
0
 def test_simulation_results(self):
     """
     - Multiple calls to run_simulation() aggregate results
     - get_results() returns list of result tuples
     """
     s = cs.Simulation([cs.Player, cs.Player])
     s.run_simulation(2)
     r = s.get_results()
     assert len(r) == 2
     s.run_simulation(1)
     r = s.get_results()
     assert len(r) == 3
     assert all(s > 0 and t == 'Player' for s, t in r)
 def test_players_per_type(self):
     """
     Checks that the players per type method correctly counts the amount
     of each player
     """
     sim = cs.Simulation(player_field=[
         cs.Player, cs.LazyPlayer, cs.ResilientPlayer, cs.LazyPlayer,
         cs.ResilientPlayer, cs.LazyPlayer
     ])
     the_dict = sim.players_per_type()
     assert the_dict['Player'] == 1
     assert the_dict['ResilientPlayer'] == 2
     assert the_dict['LazyPlayer'] == 3
 def test_durations_per_type(self):
     """
     Checks that no players win in less than 4 moves, which shouldn't be
     possible
     """
     sim = cs.Simulation(
         player_field=[cs.Player, cs.LazyPlayer, cs.ResilientPlayer])
     sim.run_simulation(5)
     the_dict = sim.durations_per_type()
     values = the_dict.values()
     for lists in values:
         for numbers in lists:
             assert numbers >= 4
Exemple #10
0
 def test_constructor_default(self):
     """Default constructor works."""
     s = cs.Simulation([cs.Player, cs.Player])
     assert isinstance(s, cs.Simulation)
Exemple #11
0
 def test_run_simulation(self):
     """run_simulation() can be called"""
     s = cs.Simulation([cs.Player, cs.Player])
     s.run_simulation(2)
Exemple #12
0
 def test_single_game(self):
     """single_game() returns non-negative number and class name"""
     s = cs.Simulation([cs.Player, cs.Player])
     nos, wc = s.single_game()
     assert nos > 0
     assert wc == 'Player'
Exemple #13
0
def test_winning_numbers():
    s = cs.Simulation([cs.Player, cs.LazyPlayer, cs.ResilientPlayer])
    s.run_simulation(15)
    assert sum(s.winners_per_type().values()) == 15