Пример #1
0
def test_robot_and_tiles_shoot():
    """
    Robots are placed on a test_laser.json map.
    There are some walls that stop their lasers on the way.
    (In order to see the "human" version with arrows representing robots,
    check test_shoot_human_view.json),
    They should receive damages according to their and lasers' position.
    """
    board = get_board("maps/test_laser.json")

    robots = [Robot(Direction.W, (2, 2), "tester"),
              Robot(Direction.N, (1, 1), "tester"),
              Robot(Direction.E, (0, 2), "tester"),
              Robot(Direction.W, (1, 2), "tester"),
              Robot(Direction.S, (1, 3), "tester"),
              Robot(Direction.E, (0, 0), "tester"),
              Robot(Direction.N, (2, 0), "tester"),
              Robot(Direction.E, (3, 0), "tester"),
              Robot(Direction.N, (2, 1), "tester"),
              Robot(Direction.S, (3, 3), "tester"),
              ]
    for robot in robots:
        robot.damages = 0

    state = State(board, robots)
    apply_tile_effects(state, 0)
    damages_list = [0, 4, 0, 2, 0, 0, 1, 1, 1, 4]

    for robot in robots:
        assert robot.damages == damages_list[robots.index(robot)]
Пример #2
0
def test_robot_change_direction(current_direction, towards, new_direction):
    """
    Assert that robot rotates correctly according to given rotation.
    """
    robot = Robot(current_direction, None, "tester")
    robot.rotate(towards)
    assert robot.direction == new_direction
Пример #3
0
def test_robot_change_direction(current_direction, towards, new_direction):
    """
    Assert that robot rotates correctly according to given rotation.
    """
    robot = Robot(current_direction, None, "bender")
    robot.rotate(towards, State.get_start_state("maps/test_maps/test_3.json"))
    assert robot.direction == new_direction
Пример #4
0
def test_unblocked_cards_count(given_damages, cards_count):
    """
    Assert that count of unblocked cards is always computed well according to robot's damages.
    """
    robot = Robot(Direction.N, (0, 0), "bender")
    robot.damages = given_damages
    assert robot.unblocked_cards == cards_count
Пример #5
0
def test_get_blocked_cards(program_before, program_after):
    """
    Assert the blocked cards (cards which are not None) are extracted
    from robot's program.
    """
    joe = Robot(Direction.N, (0, 0), "bender")
    joe.program = program_before
    assert joe.select_blocked_cards_from_program() == program_after
Пример #6
0
def test_robot_changed_coordinates(tile):
    """
    When a robot stands on FlagTile the starting coordinates change to the tile's coordinates.
    """
    robot = Robot(None, None, None, (0, 0))
    state = State({(0, 0): [tile]}, [robot], 1)
    robot.start_coordinates = (1, 1)
    apply_tile_effects(state)
    assert robot.start_coordinates == (0, 0)
Пример #7
0
def test_move_cards(card, new_coordinates):
    """
    Give mock robot the MovementCard and check if he moved to the expected coordinates.
    """
    robot = Robot(Direction.N, None, None, (5, 5))
    robot.program = [card]
    state = get_start_state("maps/test_3.json")
    robot.apply_card_effect(state)
    assert robot.coordinates == new_coordinates
Пример #8
0
def test_rotate_cards(card, new_direction):
    """
    Give mock robot the RotationCard and check if he's heading to the expected direction.
    """
    robot = Robot(Direction.N, None, "tester")
    robot.program = [card]
    state = get_start_state("maps/test_3.json")
    card.apply_effect(robot, state)
    assert robot.direction == new_direction
Пример #9
0
def test_robot_changed_coordinates(tile):
    """
    When a robot stands on FlagTile the start coordinates change to the tile's coordinates.
    """
    robot = Robot(Direction.N, (0, 0), "tester")
    state = State({(0, 0): [tile]}, [robot])
    robot.start_coordinates = (1, 1)
    apply_tile_effects(state, 0)
    assert robot.start_coordinates == (0, 0)
Пример #10
0
def test_robot_walk(input_coordinates, input_direction, distance, output_coordinates):
    """
    Take robot's coordinates, direction and distance and assert robot walked
    to correct coordinates.
    """
    state = get_start_state("maps/test_3.json")
    robot = Robot(input_direction, input_coordinates, "tester")
    robot.walk(distance, state, input_direction)
    assert robot.coordinates == output_coordinates
Пример #11
0
def test_robot_move(input_coordinates, input_direction, distance, output_coordinates):
    """
    Take robot's coordinates, move's direction and distance and assert robot
    was moved to correct coordinates.
    """
    state = get_start_state("maps/test_3.json")
    robot = Robot(Direction.N, input_coordinates, "tester")
    robot.move(input_direction, distance, state)
    assert robot.coordinates == output_coordinates
Пример #12
0
def test_robot_is_not_repaired(damages, tile, current_register):
    """
    When robot is on RepairTile but the register phase is not 5, he is not yet repaired. His damage count doesn't change.
    """
    robot = Robot(Direction.N, (0, 0), "tester")
    state = State({(0, 0): [tile]}, [robot])
    robot.damages = damages
    apply_tile_effects(state, current_register)
    assert robot.damages == damages
Пример #13
0
def test_robot_is_not_repaired(damages, tile, current_game_round):
    """
    When robot is on RepairTile but the game round is not 5, he is not yet repaired. His damage count doesn't change.
    """
    robot = Robot(None, None, None, (0, 0))
    state = State({(0, 0): [tile]}, [robot], 1)
    robot.damages = damages
    state.game_round = current_game_round
    apply_tile_effects(state)
    assert robot.damages == damages
Пример #14
0
def test_robot_changed_start_coordinates(tile, coordinates_after):
    """
    When robot is on RepairTile with special property, he changes his start coordinates to the tile coordinates.
    On a normal RepairTile he doesn't change the start tile.
    """
    robot = Robot(Direction.N, (0, 0), "tester")
    state = State({(0, 0): [tile]}, [robot])
    robot.start_coordinates = (1, 1)
    apply_tile_effects(state, 0)
    assert robot.start_coordinates == coordinates_after
Пример #15
0
def test_robot_collected_flags(flags_before, tile, flags_after):
    """
    When a robot stands on FlagTile with appropriate number (+1 to his current flag count), he collects it.
    He doesn't collect the flags with the other number than defined. They don't have any effect on him.
    """
    robot = Robot(Direction.N, (0, 0), "tester")
    state = State({(0, 0): [tile]}, [robot])
    robot.flags = flags_before
    apply_tile_effects(state, 0)
    assert robot.flags == flags_after
Пример #16
0
def test_robot_is_repaired_after_5th_round(damages_before, tile, damages_after):
    """
    When robot is on RepairTile he is supposed to be repaired after the 5th game round.
    If he doesn't have any damages, the count remains the same as previous.
    """
    robot = Robot(None, None, None, (0, 0))
    state = State({(0, 0): [tile]}, [robot], 1)
    robot.damages = damages_before
    state.game_round = 5
    apply_tile_effects(state)
    assert robot.damages == damages_after
Пример #17
0
def test_robot_is_stopped_by_wall(input_coordinates, output_coordinates):
    """
    Take robot's coordinates, move's direction and distance and assert robot
    was moved to correct coordinates.
    A special map test_walls was created in order to test this feature.
    """
    board = get_board("maps/test_walls.json")
    robot = Robot(Direction.N, input_coordinates, "tester")
    state = State(board, [robot])
    robot.move(Direction.N, 2, state)
    assert robot.coordinates == output_coordinates
Пример #18
0
def test_robot_is_repaired_after_5th_round(damages_before, tile, damages_after):
    """
    When robot is on RepairTile he is supposed to be repaired after the 5th register.
    If he doesn't have any damages, the count remains the same as previous.
    """
    robot = Robot(Direction.N, (0, 0), "tester")
    state = State({(0, 0): [tile]}, [robot])
    robot.damages = damages_before
    robot.program = [MovementCard(100, 0) for x in range(5)]
    apply_all_effects(state)
    assert robot.damages == damages_after
Пример #19
0
def test_move_cards(direction, card, new_coordinates):
    """
    Give mock robot the MovementCard and check if he moved to the expected coordinates.
    Check if the robot's direction remained the same.
    """
    robot = Robot(direction, (4, 7), "tester")
    robot.program = [card]
    state = get_start_state("maps/test_3.json")
    card.apply_effect(robot, state)
    assert robot.coordinates == new_coordinates
    assert robot.direction == direction
Пример #20
0
def test_robots_cannot_switch_places(input_coordinates_1, input_coordinates_2):
    """
    Test robots cannot switch places on belts that go against each other.
    """
    robots = [Robot(Direction.N, input_coordinates_1, "tester"),
              Robot(Direction.N, input_coordinates_2, "tester"),
              ]
    board = get_board("maps/test_belts.json")
    state = State(board, robots)
    apply_tile_effects(state, 0)
    assert robots[0].coordinates == input_coordinates_1
    assert robots[1].coordinates == input_coordinates_2
Пример #21
0
def test_two_robots_movements_on_belts(input_coordinates_1, input_coordinates_2, output_coordinates_1, output_coordinates_2):
    """
    Test movement of two robots in a row on belts.
    """
    robots = [Robot(Direction.N, input_coordinates_1, "tester"),
              Robot(Direction.N, input_coordinates_2, "tester"),
              ]
    board = get_board("maps/test_belts.json")
    state = State(board, robots)
    apply_tile_effects(state, 0)
    assert robots[0].coordinates == output_coordinates_1
    assert robots[1].coordinates == output_coordinates_2
Пример #22
0
def test_robots_dont_change_direction_on_rotating_belts_after_move_card(input_coordinates, input_direction):
    """
    Test robot's direction isn't changed after he is moved by card to
    rotating conveyor belt.
    """
    robot = Robot(input_direction, input_coordinates, "tester")
    robot.program = [MovementCard(100, 1)]
    board = get_board("maps/test_belts.json")
    state = State(board, [robot])
    robot.program[0].apply_effect(robot, state)
    apply_tile_effects(state, 0)
    assert robot.direction == input_direction
Пример #23
0
def test_robot_does_not_move_onto_another_robot(input_coordinates_1, input_coordinates_2, output_coordinates_1, output_coordinates_2):
    """
    Test robot doesn't move to coordinates of other robot. Other robot stands
    on the end of belt but on the ground tile.
    """
    robots = [Robot(Direction.N, input_coordinates_1, "tester"),
              Robot(Direction.N, input_coordinates_2, "tester"),
              ]
    board = get_board("maps/test_belts.json")
    state = State(board, robots)
    apply_tile_effects(state, 0)
    assert robots[0].coordinates == output_coordinates_1
    assert robots[1].coordinates == output_coordinates_2
Пример #24
0
def test_robot_is_damaged_by_laser(input_coordinates, damages_after):
    """
    When robot stands on laser tile, he is damaged according to the laser strength, but only if there is no obstacle in the way.
    If there are obstacles, damage count changes accordingly.
    A special map test_laser was created in order to test this feature.
    """
    board = get_board("maps/test_laser.json")
    robot_obstacle1 = Robot(Direction.N, None, None, (1, 1))
    robot_obstacle2 = Robot(Direction.N, None, None, (3, 2))
    robot = Robot(Direction.E, None, None, input_coordinates)
    robot.damages = 0
    state = State(board, [robot_obstacle1, robot_obstacle2, robot], 16)
    apply_tile_effects(state)
    assert robot.damages == damages_after
Пример #25
0
def test_two_robots_movement_on_T_crossroad(input_coordinates_1, input_coordinates_2, output_coordinates_1, output_coordinates_2):
    """
    Test movement of two robots on T crossroads. Robots are facing each other
    across the crossroad. Both want to go through this crossroad, but none them
    move.
    """
    robots = [Robot(Direction.N, input_coordinates_1, "tester"),
              Robot(Direction.N, input_coordinates_2, "tester"),
              ]
    board = get_board("maps/test_belts.json")
    state = State(board, robots)
    apply_tile_effects(state, 0)
    assert robots[0].coordinates == output_coordinates_1
    assert robots[1].coordinates == output_coordinates_2
Пример #26
0
def test_robot_died(lives_before, lives_after):
    """
    When robot comes to a HoleTile (or goes / is pushed out of the game board),
    he gets killed.
    Check that his lives were lowered, he got inactive till the next game round
    and his coordinates changed to the None.
    """
    robot = Robot(Direction.N, (0, 0), "tester")
    state = State({(0, 1): [HoleTile(None, None, None)]}, [robot])
    robot.lives = lives_before
    robot.walk(1, state)
    assert robot.lives == lives_after
    assert robot.inactive is True
    assert robot.coordinates is None
Пример #27
0
def test_robot_movement_on_crossroad_belts(input_coordinates, output_coordinates):
    """
    Test movement of robots on crossroads from different directions.
    """
    robot = Robot(Direction.N, input_coordinates, "tester")
    board = get_board("maps/test_belts.json")
    state = State(board, [robot])
    apply_tile_effects(state, 0)
    assert robot.coordinates == output_coordinates
Пример #28
0
def test_robot_movement_on_normal_belts(input_coordinates, output_coordinates):
    """
    Test movement of robots on normal conveyor belts - 6 types of tiles.
    """
    robot = Robot(Direction.N, input_coordinates, "tester")
    board = get_board("maps/test_belts.json")
    state = State(board, [robot])
    apply_all_effects(state, 1)
    assert robot.coordinates == output_coordinates
Пример #29
0
def test_robot_changed_direction(direction_before, tile, direction_after):
    """
    When robot is on GearTile, he should be rotated according to the direction of the tile.
    Check that his direction changed after applying tile effect.
    """
    robot = Robot(direction_before, (0, 0), "tester")
    state = State({(0, 0): [tile]}, [robot])
    apply_tile_effects(state, 0)
    assert robot.direction == direction_after
Пример #30
0
def test_change_of_robots_direction_on_rotating_belts(input_coordinates, output_direction):
    """
    Test change of robot's direction after he is moved by conveyor belt to
    rotating conveyor belt.
    """
    robot = Robot(Direction.N, input_coordinates, "tester")
    board = get_board("maps/test_belts.json")
    state = State(board, [robot])
    apply_tile_effects(state, 0)
    assert robot.direction == output_direction