def test_copy(self): position = Position() assert position.start is True assert position.home is False position.safe = 9 position.square = 13 copy = position.copy() assert copy is not position and copy == position
def test_move_to_position_invalid_none(self): position = Position() with pytest.raises(ValueError): target = Position() target.start = False target.home = False target.safe = None target.square = None position.move_to_position(target)
def create_moves_simple() -> List[Move]: """Create a simple move for testing.""" pawn = Pawn(color=PlayerColor.RED, index=1, name="V", position=Position().move_to_safe(3)) position = Position().move_to_square(10) move = Move( id="a9fff13fbe5e46feaeda87382bf4c3b8", card=Card("card1", CardType.CARD_APOLOGIES), actions=[Action(ActionType.MOVE_TO_POSITION, pawn, position)], side_effects=[], ) return [move]
def test_constructor_with_name(self): pawn = Pawn(PlayerColor.RED, 0, name="whatever") assert pawn.color == PlayerColor.RED assert pawn.index == 0 assert pawn.name == "whatever" assert pawn.position == Position() assert "%s" % pawn == "whatever->start" # because default position is in start
def test_constructor(self): pawn = Pawn(PlayerColor.RED, 0) assert pawn.color == PlayerColor.RED assert pawn.index == 0 assert pawn.name == "Red0" assert pawn.position == Position() assert "%s" % pawn == "Red0->start" # because default position is in start
def test_constructor(self): position = Position() assert position.start is True assert position.home is False assert position.safe is None assert position.square is None assert "%s" % position == "start"
def test_move_to_position_invalid_multiple(self): position = Position() for (start, home, safe, square) in [ (True, True, None, None), (True, False, 1, None), (True, False, None, 1), (False, True, 1, None), (False, True, None, 1), (False, False, 1, 1), ]: with pytest.raises(ValueError): target = Position() target.start = start target.home = home target.safe = safe target.square = square position.move_to_position(target)
def test_move_to_position_invalid_square(self): position = Position() for square in [-1000, -2 - 1, 60, 61, 1000]: with pytest.raises(ValueError): target = Position() target.square = square position.move_to_position(target)
def create_moves_complex() -> List[Move]: """Create a complex move for testing.""" pawn1 = Pawn(color=PlayerColor.RED, index=1, name="V", position=Position().move_to_safe(3)) position1 = Position().move_to_square(10) pawn2 = Pawn(color=PlayerColor.YELLOW, index=3, name="W", position=Position().move_to_square(10)) position2 = Position().move_to_square(11) pawn3 = Pawn(color=PlayerColor.BLUE, index=2, name="X", position=Position().move_to_square(32)) pawn4 = Pawn(color=PlayerColor.RED, index=3, name="Z", position=Position().move_to_square(17)) position4 = Position().move_to_square(27) move1 = Move( id="a9fff13fbe5e46feaeda87382bf4c3b8", card=Card("card1", CardType.CARD_APOLOGIES), actions=[Action(ActionType.MOVE_TO_POSITION, pawn1, position1), Action(ActionType.MOVE_TO_POSITION, pawn2, position2)], side_effects=[Action(ActionType.MOVE_TO_START, pawn3)], ) move2 = Move( id="d05f9b511b6e439aa18c8b70cbbcc5d3", card=Card("card2", CardType.CARD_10), actions=[Action(ActionType.MOVE_TO_POSITION, pawn4, position4)], side_effects=[], ) return [move1, move2]
def test_move_to_home(self): position = Position() position.start = "x" position.home = "x" position.safe = "x" position.square = "x" result = position.move_to_home() assert result is position assert position.start is False assert position.home is True assert position.safe is None assert position.square is None assert "%s" % position == "home"
def test_move_to_square_valid(self): for square in range(BOARD_SQUARES): position = Position() position.start = "x" position.home = "x" position.safe = "x" position.square = "x" result = position.move_to_square(square) assert result is position assert position.start is False assert position.home is False assert position.safe is None assert position.square is square assert "%s" % position == "square %d" % square
def test_move_to_square_invalid(self): for square in [-1000, -2 - 1, 60, 61, 1000]: with pytest.raises(ValueError): position = Position() position.move_to_square(square)
def test_move_to_position_valid_square(self): target = Position() target.start = False target.home = False target.safe = None target.square = 3 position = Position() position.start = "x" position.home = "x" position.safe = "x" position.square = "x" result = position.move_to_position(target) assert result is position assert position == target assert "%s" % position == "square 3"