Ejemplo n.º 1
0
def validate(program, bounds):
    parse_tree = xdrone_parser.parse(program)
    validator = Validate()
    validator.visit(parse_tree)

    if validator.max_z > bounds["height"]:
        return {"success": False, "message": "The drone flies too high"}
    if (abs(validator.max_x) > bounds["width"] / 2
            or abs(validator.min_x) > bounds["width"] / 2
            or abs(validator.max_y) > bounds["depth"] / 2
            or abs(validator.min_y) > bounds["depth"] / 2):
        return {"success": False, "message": "The drone flies out of bounds"}

    return {"success": True}
Ejemplo n.º 2
0
def test_missing_brackets():
    sample_program = "fly() TAKEOFF() LAND() }"
    with pytest.raises(Exception) as excinfo:
        parse_tree = xdrone_parser.parse(sample_program)
Ejemplo n.º 3
0
def test_blank():
    sample_program = "fly() { }"
    with pytest.raises(Exception) as excinfo:
        parse_tree = xdrone_parser.parse(sample_program)
Ejemplo n.º 4
0
def test_land_before_takeoff():
    sample_program = "fly() { LAND() TAKEOFF() }"
    with pytest.raises(Exception) as excinfo:
        parse_tree = xdrone_parser.parse(sample_program)
Ejemplo n.º 5
0
def test_missing_takeoff():
    sample_program = "fly() { LAND() }"
    with pytest.raises(Exception) as excinfo:
        parse_tree = xdrone_parser.parse(sample_program)
Ejemplo n.º 6
0
def fly(program, rs, addr="d0:3a:86:9d:e6:5a"):
    parse_tree = xdrone_parser.parse(program)
    requirements = generate_requirements(rs)
    Fly(addr, requirements).visit(parse_tree)

    return all(r.is_completed() for r in requirements)
Ejemplo n.º 7
0
def gen_simulate_commands(program):
    parse_tree = xdrone_parser.parse(program)
    return Simulate().transform(parse_tree)