Esempio n. 1
0
 def test_only_one_input(self):
     """
     Tests if we get get standard board if we only have one input
     """
     b_std = cs.Board()
     b = cs.Board([(1, 4), (5, 16)])
     assert b.board == b_std.board
Esempio n. 2
0
 def test_only_goal_input(self):
     """
     Tests if we get get standard board and goal, if we only have one
     input
     """
     b_std = cs.Board()
     b = cs.Board(goal=89)
     assert b.board == b_std.board
Esempio n. 3
0
 def test_position_adjustment(self):
     """Tests if position_adjustment returns the correct adjustment for
     different positions"""
     b = cs.Board()
     assert b.position_adjustment(2) == 0
     assert b.position_adjustment(49) == 79 - 49
     assert b.position_adjustment(33) == 3 - 33
Esempio n. 4
0
    def test_default_board(self):
        """
        Testing if the default board is right
        """
        b = cs.Board()

        assert b.ladders == {
            1: 40,
            8: 10,
            36: 52,
            43: 62,
            49: 79,
            65: 82,
            68: 85
        }
        assert b.chutes == {
            24: 5,
            33: 3,
            42: 30,
            56: 37,
            64: 27,
            74: 12,
            87: 70
        }
        assert b.goal == 90
Esempio n. 5
0
 def test_goal_reached(self):
     """
     Checking if the goal is reached, we get True.
     """
     b = cs.Board()
     goal = b.goal_reached(90)
     assert goal
Esempio n. 6
0
    def test_std_goal_is_not_same_as_30(self):
        """
        Tests that standard goal is not 30

        """
        goal = 30
        b = cs.Board(goal=goal)
        assert b.goal != goal
Esempio n. 7
0
    def test_goal_is_same_as_given(self):
        """
        Tests that goal position is the same as the given input goal.

        """
        goal = 30
        b = cs.Board(ladders=[(1, 4)], chutes=[(9, 2)], goal=goal)
        assert b.goal == goal
 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)
Esempio n. 9
0
    def test_move(self):

        board = cs.Board()
        player = cs.LazyPlayer(board)
        for _ in range(10):
            player.move()

        assert player.number_of_moves == 10
Esempio n. 10
0
    def test_start_of_chute(self):

        board = cs.Board()
        player = cs.ResilientPlayer(board)

        for step in range(50):
            player.move()
            assert player.position not in board.snakes_and_ladders.keys()
Esempio n. 11
0
 def test_position_adjustment(self):
     """
     Testing if the number of positions the player must move forward
     (in case of a ladder) is correct.
     """
     b = cs.Board()
     pos = b.position_adjustment(1)
     assert pos == 39
Esempio n. 12
0
    def test_position_not_equal_one(self):

        board = cs.Board()
        player = cs.LazyPlayer(board)

        for _ in range(50):
            player.move()
            assert 1 <= player.position
Esempio n. 13
0
 def test_position_adjustment_returns_0_on_regular_spot(self):
     """
     Tests that position_adjustment returns 0 when player doesn't land on a
     chute or ladder
     """
     b = cs.Board()
     position = 2
     zero = b.position_adjustment(position)
     assert zero == 0
Esempio n. 14
0
def test_move():
    """
    Tests whether the player has moved a position
    """
    player = sa.Player(sa.Board())
    first_pos = player.position
    player.move()
    second_pos = player.position
    assert first_pos != second_pos
Esempio n. 15
0
    def test_position(self):

        board = cs.Board()
        player = cs.LazyPlayer(board)
        start_pos = player.position
        player.move()
        end_pos = player.position

        assert start_pos is not end_pos
Esempio n. 16
0
 def test_move(self):
     b = cs.Board()
     lazy_player = cs.LazyPlayer(b, dropped_steps=1)
     lazy_player.position = 34
     random.seed(1)
     lazy_player.move()
     random.seed(1)
     lazy_player.move()
     assert lazy_player.position == 53
Esempio n. 17
0
    def test_move(self):
        """Tests if the players in Player Class takes the right amounts of
        moves"""

        board = cs.Board()
        player = cs.Player(board)
        for _ in range(10):
            player.move()

        assert player.number_of_moves == 10
Esempio n. 18
0
    def test_position_not_equal_one(self):
        """Test that the players position is not less than 1 after moving,
        since this is not possible"""

        board = cs.Board()
        player = cs.Player(board)

        for _ in range(50):
            player.move()
            assert 1 <= player.position
Esempio n. 19
0
 def test_move(self):
     """Tests that resilient player moves as it should."""
     b = cs.Board()
     resilient_player = cs.ResilientPlayer(b, extra_steps=5)
     resilient_player.position = 22
     random.seed(1)
     resilient_player.move()
     random.seed(1)
     resilient_player.move()
     assert resilient_player.position == 12
Esempio n. 20
0
    def test_position(self):
        """Tests that the player actually moves, when function move is
        called upon. So start position can not be equal to end position  """

        board = cs.Board()
        player = cs.Player(board)
        start_pos = player.position
        player.move()
        end_pos = player.position

        assert start_pos is not end_pos
Esempio n. 21
0
    def test_start_of_chute(self):
        """Test that the players position can´t be the start point of a
        snake or a ladder, since the player is supposed to interact with
        these. """

        board = cs.Board()
        player = cs.ResilientPlayer(board)

        for step in range(50):
            player.move()
            assert player.position not in board.snakes_and_ladders.keys()
Esempio n. 22
0
 def test_lazy_player_not_stepped_back(self):
     """We test here if the lazy player ever step back,
     except when take a chute"""
     chute = [5, 3, 30, 37, 27, 12, 70]
     game_ended, prev_position, stepped_back = False, 0, False
     p = cs.LazyPlayer(cs.Board())
     while not game_ended:
         prev_position = p.position
         p.move()
         if p.position not in chute and p.position < prev_position:
             stepped_back, game_ended = True, True
         game_ended = p.board.goal_reached(p.position)
     assert not stepped_back
Esempio n. 23
0
    def test_move_resilientplayer(self):
        """
        Resilient player can move.
        """
        b = cs.Board()
        p = cs.ResilientPlayer(b)
        p.move()

        assert p.player_position > 0
        assert p.player_position not in b.chutes.keys() and b.ladders.keys()

        position1 = p.player_position
        p.move()
        assert p.player_position != position1
Esempio n. 24
0
    def test_move_lazyplayer(self):
        """
        Lazy player can move.
        """
        b = cs.Board()
        p = cs.LazyPlayer(b)
        p.move()

        assert p.player_position > 0
        assert p.player_position not in b.chutes.keys() and b.ladders.keys()

        position1 = p.player_position
        p.move()
        assert p.player_position != position1
Esempio n. 25
0
 def test_move(self):
     """Tests if turns is increased by one, and position is changed after
     move."""
     b = cs.Board()
     p = cs.Player(b)
     turns_before = p.turns
     position_before = p.position
     p.move()
     assert p.turns == turns_before + 1
     assert p.position != position_before
     p.position = 22
     random.seed(1)
     p.move()
     random.seed(1)
     p.move()
     assert p.position == 7
Esempio n. 26
0
 def test_resilient_player_got_chute(self):
     """We test here if the chute and slided in
     ResilientPlayer(Board()) are functioning"""
     chute = [5, 3, 30, 37, 27, 12, 70]
     got_chute, game_ended, position, slided = False, False, 0, False
     while not got_chute:
         p = cs.ResilientPlayer(cs.Board())
         while not game_ended:
             if position in chute and slided:
                 got_chute, game_ended = True, True
             else:
                 p.move()
                 position, slided = p.position, p.slided
                 game_ended = p.board.goal_reached(position)
         game_ended = False if not got_chute else True
     assert position in chute
     assert slided
Esempio n. 27
0
 def test_lazy_player_got_ladder(self):
     """We test here if the ladder and climbed in
     LazyPlayer(Board()) are functioning"""
     ladder = [40, 10, 52, 62, 79, 82, 85]
     got_ladder, game_ended, position, climbed = \
         False, False, 0, False
     while not got_ladder:
         p = cs.LazyPlayer(cs.Board())
         while not game_ended:
             if position in ladder and climbed:
                 got_ladder, game_ended = True, True
             else:
                 p.move()
                 position, climbed = p.position, p.climbed
                 game_ended = p.board.goal_reached(position)
         game_ended = False if not got_ladder else True
     assert position in ladder
     assert climbed
 def test_move(self):
     """LazyPlayer can move."""
     b = cs.Board()
     p = cs.LazyPlayer(b)
     p.move()
 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(self):
     """ResilientPlayer can move."""
     b = cs.Board()
     p = cs.ResilientPlayer(b)
     p.move()