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())
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_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())
def test_single_game(self): player_list = [cs.Player, cs.Player, cs.Player] b = cs.Board() play = cs.Simulation(board=b, player_field=player_list) res = play.single_game() assert not res[1] == 'LazyPlayer' assert not res[1] == 'ResilientPlayer' assert res[1] == 'Player' assert isinstance(res[0], int)
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)
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_durations_per_type(self): player_list = [ cs.Player, cs.Player, cs.Player, cs.LazyPlayer, cs.LazyPlayer, cs.ResilientPlayer ] b = cs.Board() pl = cs.Simulation(board=b, player_field=player_list) pl.run_simulation(10) pl.get_results() res = pl.durations_per_type() for i in range(3): assert list( res.keys())[i] in ['Player', 'ResilientPlayer', 'LazyPlayer'] for value in res.values(): assert isinstance(value, list)
def test_players_per_type(self): player_list = [ cs.Player, cs.Player, cs.Player, cs.LazyPlayer, cs.LazyPlayer, cs.ResilientPlayer ] b = cs.Board() pl = cs.Simulation(board=b, player_field=player_list, randomize_players=False) pl.run_simulation(10) pl.get_results() res = pl.players_per_type() for i in range(3): assert list( res.keys())[i] in ['Player', 'ResilientPlayer', 'LazyPlayer'] assert list(res.values())[0] == 3 assert list(res.values())[1] == 2 assert list(res.values())[2] == 1
def test_constructor_default(self): """Default constructor works.""" s = cs.Simulation([cs.Player, cs.Player]) assert isinstance(s, cs.Simulation)
def test_run_simulation(self): """run_simulation() can be called""" s = cs.Simulation([cs.Player, cs.Player]) s.run_simulation(2)
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'