예제 #1
0
    def test_right(self):

        route_builder = RouteBuilder()
        route_builder.right()

        assert len(route_builder.instructions) == 1
        assert route_builder.instructions[0] == f'{Instruction.RIGHT.value}:'
예제 #2
0
    def test_route_forward_step(self):
        route_builder = RouteBuilder()
        route_builder.step(3)

        assert len(route_builder.instructions) == 1
        assert route_builder.instructions[
            0] == f'{Instruction.FORWARD.value}:3'
예제 #3
0
    def test_many_instructions(self):

        route_builder = RouteBuilder()
        place = 'Where winter is coming'
        route_builder.step(10).right().left().reach(place)

        assert len(route_builder.instructions) == 4
        expected = [
            f'{Instruction.FORWARD.value}:10',
            f'{Instruction.RIGHT.value}:',
            f'{Instruction.LEFT.value}:',
            f'{Instruction.REACH.value}:{place}',
        ]
        assert route_builder.instructions == expected
예제 #4
0
    def test_yaml_import(self, yaml_sample):

        routeset = RouteBuilder.from_yaml(yaml_sample)

        assert len(routeset.routes) == 2

        route1 = routeset.routes[0]
        assert route1.name == 'My route'
        assert route1.start == (10, 10)
        assert route1.instructions == [
            f'{Instruction.RIGHT.value}:',
            f'{Instruction.NORTH.value}:3',
            f'{Instruction.EAST.value}:3',
            f'{Instruction.RIGHT.value}:',
            f'{Instruction.FORWARD.value}:3',
            f'{Instruction.REACH.value}:Saint Valley',
        ]

        route2 = routeset.routes[1]
        assert route2.name == 'Route only for packagers'
        assert route2.target == 'Packagers'
        assert route2.instructions == [
            f'{Instruction.NORTH.value}:3',
            f'{Instruction.EAST.value}:3',
            f'{Instruction.RIGHT.value}:',
            f'{Instruction.FORWARD.value}:10',
        ]
예제 #5
0
    def test_robot_different_instructions(self, robot):
        route = RouteBuilder().right().right().step(10).step(
            10, Direction.SOUTH).build()

        robot.load(route)
        assert robot.position == Point(0, -20)

        route = RouteBuilder().left().step(10).right().step(
            10, Direction.NORTH).build()

        robot.load(route)

        assert robot.position == Point(10, -10)

        route = RouteBuilder().step(100, Direction.NORTH).build()

        robot.load(route)
        assert robot.position == Point(10, 90)
        assert robot.facing == Direction.NORTH
예제 #6
0
def routebuilder():
    route_builder = RouteBuilder()
    place = 'Where winter is coming'
    route_builder.step(10).right().left().reach(place)
    return route_builder
예제 #7
0
def routeb_north_factory():

    return lambda blocks: RouteBuilder().step(blocks, Direction.NORTH)
예제 #8
0
from core.bot import Robot, spawn_robots
from core.geo import Direction
from core.models import Route
from core.route import RouteBuilder

# We can either use provided API

route = RouteBuilder(name='Example route')\
    .start(245, 161)\
    .step(5, Direction.NORTH)\
    .right()\
    .reach('Statue of Old Man with Large Hat')\
    .step(25, Direction.WEST)\
    .left()\
    .step(3)\
    .build()

simple_robot = Robot()
# robot info will be logged
simple_robot.load(route)

print(f'Simple robot arrived: {simple_robot.position}')

# Or read many routes from yaml
# ```
# - name: 'My route'
#   start: '10:10'
#   steps:
#     - north: 3
#     - east: 3
#     - right:
예제 #9
0
import os

import yaml

from core.route import RouteBuilder


builder = None
try:
    builder = RouteBuilder.from_yaml('route.yml')
except yaml.YAMLError as exc:

    if hasattr(exc, 'problem_mark'):
        mark = exc.problem_mark

        print("Error position: (%s:%s)" % (mark.line + 1, mark.column + 1))
    print('Cannot parse file')
    os._exit(1)


builder
예제 #10
0
 def test_wrong_yaml(self, yaml_wrong_sample):
     with pytest.raises(YamlRouteValidationException):
         routeset = RouteBuilder.from_yaml(yaml_wrong_sample)
예제 #11
0
    def test_route_builder_create(self):

        route_builder = RouteBuilder()
        assert route_builder.name is not None
        assert route_builder.instructions == []
예제 #12
0
    def test_route_step(self):
        route_builder = RouteBuilder()
        route_builder.step(10, Direction.EAST)

        assert len(route_builder.instructions) == 1
        assert route_builder.instructions[0] == f'{Instruction.EAST.value}:10'