Ejemplo n.º 1
0
def test_random_order():
    """Adds test to see if elements in a list is same sorted as unsorted"""
    list_of_players = [cs.Player, cs.LazyPlayer, cs.ResilientPlayer]
    b = cs.Board()
    s1 = cs.Simulation(list_of_players, b, 999)
    s2 = cs.Simulation(list_of_players, b, 999, False)
    dict1 = s1.players_per_type()
    dict2 = s2.players_per_type()
    assert dict1 == dict2
Ejemplo n.º 2
0
def test_winners_per_type():
    """Checking if winners_per_type works"""
    s1 = cs.Simulation([cs.Player, cs.LazyPlayer, cs.ResilientPlayer,
                       cs.ResilientPlayer])
    s2 = cs.Simulation([cs.LazyPlayer, cs.LazyPlayer, cs.LazyPlayer])
    s1.run_simulation(30)
    s2.run_simulation(30)
    dict1 = s1.winners_per_type()
    dict2 = s2.winners_per_type()
    assert len(dict1) == 3
    assert len(dict2) == 1
    assert 'LazyPlayer' in dict2
Ejemplo n.º 3
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())
Ejemplo n.º 4
0
def test_durations_per_type():
    """Checking if durations_per_type returns dictionary of correct length"""
    s = cs.Simulation([cs.Player, cs.LazyPlayer, cs.ResilientPlayer,
                       cs.ResilientPlayer])
    s.run_simulation(30)
    durations_dict = s.durations_per_type()
    assert len(durations_dict) == 3
Ejemplo n.º 5
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)
Ejemplo n.º 6
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())
Ejemplo n.º 7
0
def test_single_game():
    """Checking if single_game behaves correctly"""
    s = cs.Simulation(player_field=[cs.Player, cs.ResilientPlayer,
                                    cs.LazyPlayer], seed=999)
    n, winner_type = s.single_game()
    assert type(n) == int
    assert (winner_type == 'Player' or winner_type == 'ResilientPlayer' or
            winner_type == 'LazyPlayer')
Ejemplo n.º 8
0
def test_run_simulation():
    """Checking that results list changes after run_simulation is called"""
    s = cs.Simulation(player_field=[cs.Player, cs.ResilientPlayer,
                                    cs.LazyPlayer], seed=999)
    s.run_simulation(2)
    first_results = s.results.copy()
    s.run_simulation()
    later_results = s.results
    assert first_results != later_results
Ejemplo n.º 9
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)
Ejemplo n.º 10
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)
Ejemplo n.º 11
0
 def test_constructor_default(self):
     """Default constructor works."""
     s = cs.Simulation([cs.Player, cs.Player])
     assert isinstance(s, cs.Simulation)
Ejemplo n.º 12
0
 def test_run_simulation(self):
     """run_simulation() can be called"""
     s = cs.Simulation([cs.Player, cs.Player])
     s.run_simulation(2)
Ejemplo n.º 13
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'
Ejemplo n.º 14
0
def test_players_per_type():
    """Checking if players_per_type returns right result for example"""
    s = cs.Simulation([cs.Player, cs.LazyPlayer, cs.ResilientPlayer,
                       cs.ResilientPlayer])
    types_dict = s.players_per_type()
    assert types_dict == {'Player': 1, 'ResilientPlayer': 2, 'LazyPlayer': 1}
Ejemplo n.º 15
0
def test_get_results():
    """Checking if get_results works"""
    s = cs.Simulation(player_field=[cs.Player, cs.ResilientPlayer,
                                    cs.LazyPlayer], seed=999)
    s.run_simulation(2)
    assert s.get_results() == s.results