コード例 #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())
コード例 #2
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)
コード例 #3
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())
コード例 #4
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)
コード例 #5
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)
コード例 #6
0
 def test_constructor_default(self):
     """Default constructor works."""
     s = cs.Simulation([cs.Player, cs.Player])
     assert isinstance(s, cs.Simulation)
コード例 #7
0
 def test_run_simulation(self):
     """run_simulation() can be called"""
     s = cs.Simulation([cs.Player, cs.Player])
     s.run_simulation(2)
コード例 #8
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'