Exemplo n.º 1
0
def test_types():
    """Checking if returned player types are correct"""
    b = cs.Board()
    rp = cs.ResilientPlayer(b)
    assert type(rp).__name__ == 'ResilientPlayer'
    lp = cs.LazyPlayer(b)
    assert type(lp).__name__ == 'LazyPlayer'
Exemplo n.º 2
0
def test_standard_board():
    """Checking if standard board created is correct"""
    b = cs.Board()
    assert b.chutes == [(24, 5), (33, 3), (42, 30), (56, 37), (64, 27),
                        (74, 12), (87, 70)]
    assert b.ladders == [(1, 40), (8, 10), (36, 52), (43, 62), (49, 79),
                         (65, 82), (68, 85)]
    assert b.goal == 90
Exemplo n.º 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)
Exemplo n.º 4
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
Exemplo n.º 5
0
def test_player_move():
    """Checking that player is initially at 0, and not in the same position
    after move is called"""
    b = cs.Board()
    p = cs.Player(b)
    assert p.position == 0
    p.position = 5
    p.move()
    assert p.position != 5
Exemplo n.º 6
0
def test_lazy_player():
    """Checking if LazyPlayer behaves as desired"""
    random.seed(999)
    b = cs.Board()
    p = cs.LazyPlayer(b)
    p.position = 2
    p.move()
    random.seed(999)
    p.move()
    assert p.position == 15
Exemplo n.º 7
0
def test_resilient_player():
    """Checking if ResilientPlayer behaves as desired"""
    random.seed(999)
    b = cs.Board()
    p = cs.ResilientPlayer(b)
    p.position = 36
    p.move()
    random.seed(999)
    p.move()
    assert p.position == 37
Exemplo n.º 8
0
 def test_constructor(self):
     """ResilientPlayer can be created."""
     b = cs.Board()
     p = cs.ResilientPlayer(b, extra_steps=4)
     assert isinstance(p, cs.ResilientPlayer)
     assert isinstance(p, cs.Player)
Exemplo n.º 9
0
 def test_move(self):
     """Player has move() method."""
     b = cs.Board()
     p = cs.Player(b)
     p.move()
Exemplo n.º 10
0
 def test_constructor(self):
     """Player can be constructed."""
     b = cs.Board()
     p = cs.Player(b)
     assert isinstance(p, cs.Player)
Exemplo n.º 11
0
 def test_position_adjustment(self):
     """position_adjustment callable and returns number"""
     b = cs.Board()
     assert isinstance(b.position_adjustment(1), (int, float))
Exemplo n.º 12
0
 def test_goal_reached(self):
     """goal_reached() callable and returns bool"""
     b = cs.Board()
     assert isinstance(b.goal_reached(1), bool)
Exemplo n.º 13
0
def test_position_adjustment():
    """Checking if position_adjustment works"""
    b = cs.Board()
    assert b.position_adjustment(24) == -19
    assert b.position_adjustment(68) == 17
    assert b.position_adjustment(7) == 0
Exemplo n.º 14
0
 def test_move(self):
     """LazyPlayer can move."""
     b = cs.Board()
     p = cs.LazyPlayer(b)
     p.move()
Exemplo n.º 15
0
 def test_constructor_default(self):
     """Default constructor callable."""
     b = cs.Board()
     assert isinstance(b, cs.Board)
Exemplo n.º 16
0
 def test_move(self):
     """ResilientPlayer can move."""
     b = cs.Board()
     p = cs.ResilientPlayer(b)
     p.move()
Exemplo n.º 17
0
 def test_constructor(self):
     """LazyPlayer can be constructed."""
     b = cs.Board()
     p = cs.LazyPlayer(b, dropped_steps=3)
     assert isinstance(p, cs.LazyPlayer)
     assert isinstance(p, cs.Player)
Exemplo n.º 18
0
 def test_constructor_args(self):
     """Constructor with unnamed arguments callable."""
     b = cs.Board([(1, 4), (5, 16)], [(9, 2), (12, 3)], 90)
     assert isinstance(b, cs.Board)
Exemplo n.º 19
0
 def test_constructor_named_args(self):
     """Constructor with kw args callable."""
     b = cs.Board(ladders=[(1, 4), (5, 16)],
                  chutes=[(9, 2), (12, 3)],
                  goal=90)
     assert isinstance(b, cs.Board)
Exemplo n.º 20
0
def test_goal_reached():
    """Checking if goal_reached works"""
    b = cs.Board()
    assert b.goal_reached(90) is True
    assert b.goal_reached(13) is False
    assert b.goal_reached(100) is True