def test_player_starts_at_0(self): """ Checks that the players starts in position 0 """ board = cs.Board() player = cs.Player(board) assert player.position == 0
def test_standard_board_setting(self): """ Tests the default bord chutes and ladders is correct """ board = cs.Board() assert board.ladders == ([1, 40], [9, 11], [37, 53], [44, 63], [50, 80], [66, 83], [69, 86])
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_resilient_player_moves(self): """ Check that the resilient player step counter works """ board = cs.Board() player = cs.ResilientPlayer(board) player.move() player.move() assert player.step_counter() == 2
def test_position_adjustment(self): """ Checks that the position adjustment returns the difference between the chute and ladder exit/entry """ board = cs.Board(ladders=([1, 21], [15, 25]), chutes=([40, 10], [90, 1])) assert board.position_adjustment(1) == 20 assert board.position_adjustment(90) == -89
def test_goal_reached(self): """ Tests that the goal reached method works """ board = cs.Board(goal=95) if board.goal_reached(94): assert False if board.goal_reached(95): assert True
def test_lazy_player_moves(self): """ Checks that the lazy player step counter works """ board = cs.Board() player = cs.LazyPlayer(board) player.move() player.move() assert player.step_counter() == 2
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_resilience(self): """ Checks that the resilient player moves extra steps after falling down a chute in the next move """ board = cs.Board(chutes=([6, 1], [5, 1], [4, 1], [3, 1], [2, 1])) player = cs.ResilientPlayer(board, extra_steps=20) player.move() player.move() assert player.position >= 21 player.move() assert player.position >= 27
def test_laziness(self): """ Checks that the lazy player moves shorter after going up a ladder """ board = cs.Board(ladders=([1, 10], [2, 10], [3, 10], [4, 10], [5, 10], [6, 10])) player = cs.LazyPlayer(board, dropped_steps=5) player.move() player.move() assert player.position <= 11 player.move() assert player.position >= 11
def test_move(self): """ResilientPlayer can move.""" b = cs.Board() p = cs.ResilientPlayer(b) p.move()
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)
def test_move(self): """Player has move() method.""" b = cs.Board() p = cs.Player(b) p.move()
def test_constructor(self): """Player can be constructed.""" b = cs.Board() p = cs.Player(b) assert isinstance(p, cs.Player)
def test_position_adjustment(self): """position_adjustment callable and returns number""" b = cs.Board() assert isinstance(b.position_adjustment(1), (int, float))
def test_goal_reached(self): """goal_reached() callable and returns bool""" b = cs.Board() assert isinstance(b.goal_reached(1), bool)
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)
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)
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)
def test_move(): a = cs.Player(cs.Board()) pos1 = a.position a.move() pos2 = a.position assert pos1 != pos2
def test_move(self): """LazyPlayer can move.""" b = cs.Board() p = cs.LazyPlayer(b) p.move()
def test_constructor_default(self): """Default constructor callable.""" b = cs.Board() assert isinstance(b, cs.Board)