コード例 #1
0
ファイル: test_grid.py プロジェクト: digocse/robots-challenge
    def test_should_not_generate_robot_at_invalid_coordinate(self):
        grid = Grid(3, 3)

        with pytest.raises(CustomExceptions.CoordinateDoesntExistError) as exc:
            grid.generate_robot(4, 1, 'E')

        assert str(exc.value) == str((4, 1, 'E'))
コード例 #2
0
ファイル: test_grid.py プロジェクト: digocse/robots-challenge
    def test_generate_robot(self):
        grid = Grid(3, 3)

        grid.generate_robot(0, 0, 'N')

        assert len(grid.robots) > 0
        assert grid.robots[0].pos() == (0, 0, 'N')
コード例 #3
0
def grid_create(username: str):
    # if not request.json:
    #     return jsonify({"error": "Data not specified"}), 409
    # if not request.json.get("name"):
    #     return jsonify({"error": "Name not specified"}), 409
    # if not request.json.get("description"):
    #     return jsonify({"error": "Description not specified"}), 409
    # if not request.json.get("num_Days"):
    #     return jsonify({"error": "numDays not specified"}), 409

    schema = Schema({
        "name":
        And(str, len, error="Namr not specified"),
        "description":
        And(str, len, error="description not specified"),
        "num_Days":
        And(Use(int), error="Number of Days not specified"),
        "is_public":
        And(str, len, error="publicity not specified"),
    })
    form = {
        "name": request.form.get("name"),
        "description": request.form.get("description"),
        "num_Days": request.form.get("num_Days"),
        "is_public": request.form.get("is_public")
    }
    validated = schema.validate(form)

    #subvue_permalink = validated["grid"]
    #subvue = Subvue.objects(permalink__iexact=subvue_permalink).first()
    #if not subvue:
    #    return jsonify({"error": f"Subvue '{subvue_permalink}' not found"}), 404

    user = User.objects(username=username).first()

    grid = Grid(
        # user=user,
        # id = counter
        # name= validated["title"],
        # description="",
        # days = numDays,
        # repeat = [],
        # self.start_Date = [timer.strftime("%m"), timer.strftime("%d")], #A list with the month in mm format and day in the dd format
        # self.start_Day = int(timer.day()),
        # self.curr_Day = int(timer.day()),
        # endDate = []
        user=user,
        name=validated["name"],
        description=validated["description"],
        num_Days=validated["num_Days"],
        repeat=[],
        start_Date=datetime.now(),
        string_start=datetime.strftime(
            datetime.now(), "%B %m, %Y"
        ),  #A list with the month in mm format and day in the dd format
        curr_Date=datetime.now(),
        end_Date=datetime.now() + timedelta(days=int(validated["num_Days"])),
        is_public=validated["is_public"]).save()
    return jsonify(grid.to_public_json())
コード例 #4
0
ファイル: test_grid.py プロジェクト: digocse/robots-challenge
    def test_should_not_generate_robot_at_same_coordinate(self):
        grid = Grid(3, 3)
        grid.generate_robot(1, 1, 'E')

        with pytest.raises(CustomExceptions.LaunchRobotCrashError) as exc:
            grid.generate_robot(1, 1, 'E')

        assert str(exc.value) == str((1, 1, 'E'))
コード例 #5
0
ファイル: test_grid.py プロジェクト: digocse/robots-challenge
    def test_last_positions(self, robots, expected):
        grid = Grid(5, 5)
        for robot in robots:
            grid.generate_robot(*robot)

        final = grid.last_positions()

        assert len(final) == len(expected)
        assert final == expected
コード例 #6
0
def add_grid():
    data = request.get_json(force=True)
    form = NewGridForm(MultiDict(mapping=data))
    if form.validate():
        configuration = data.get('configuration')
        grid = Grid(configuration=configuration, date=datetime.utcnow())
        db.session.add(grid)
        db.session.commit()
        socketio.emit('new_grid', str(grid.to_json()))
        return jsonify({'success': 'true'}), 201
    return jsonify({"form_errors": form.errors}), 400
コード例 #7
0
ファイル: test_grid.py プロジェクト: digocse/robots-challenge
    def test_apply_robot_instructions(
        self,
        robot_position,
        instructions,
        final,
    ):
        grid = Grid(5, 5)
        grid.generate_robot(*robot_position)

        grid.apply_robot_instructions(instructions)

        assert grid.robots[0].pos() == final
コード例 #8
0
ファイル: solver.py プロジェクト: bennett39/sudoku-solver
def main():
    """
    A program to find the solution to a sudoku.
    """
    g = Grid()
    get_grid_from_file(g, "puzzles/p1.txt")

    print("Input:")
    g.print_grid()

    discover_vals(g)
    print("---\nSolution:")
    g.print_grid()
コード例 #9
0
ファイル: viewer.py プロジェクト: shprintuzt/Dijkstra
 def __init__(self, master, row, col, fix, **kargs):
     super().__init__(master, **kargs)
     self.flag_flush = False
     self.params = (row, col, 900 // col, 500 // row, 50, 20)
     params = self.params
     self.g = Grid(params[0],
                   params[1],
                   params[2],
                   params[3],
                   params[4],
                   fix=fix)
     self.n_size = params[5]
     self.id = []
     self.drawing()
コード例 #10
0
ファイル: main.py プロジェクト: digocse/robots-challenge
def main():
	print('*** Welcome to the Mars Robots Guide! ***\n')
	print('Here are the computed outputs:\n')

	with open('robots_guide.in.md') as f:
		lines = f.readlines()

	grid_size = lines[0]

	if not grid_size:
		return

	grid_size = grid_size.split(' ')

	max_x_axis = int(grid_size[0])
	max_y_axis = int(grid_size[1])

	if max_x_axis > 50 or max_y_axis > 50:
		raise CustomExceptions.InvalidGridRangeError(max_x_axis, max_y_axis)

	grid = Grid(
		x=max_x_axis,
		y=max_y_axis,
	)

	updated_lines = lines.pop(0) 		# upper-right coordinates of the rectangular world
	robots_seed_positions = lines[::2]	# Robots initial position
	robots_instructions = lines[1::2]	# Robots instructions

	for position, instruction in zip(robots_seed_positions, robots_instructions):
		robot_initial_pos = position.strip('\n')

		if not robot_initial_pos:
			break

		robot_instruction = instruction

		robot_initial_pos = robot_initial_pos.split(' ')
		grid.generate_robot(
			x=int(robot_initial_pos[0]),
			y=int(robot_initial_pos[1]),
			orientation=robot_initial_pos[2],
		)
		grid.apply_robot_instructions(robot_instruction)
	f.close()
コード例 #11
0
def initialize_grid(line):
    if ':' in line:
        line = line[line.index(':') + 1:]

    width, height = [int(i.strip()) for i in line.split()]
    return Grid(width, height)
コード例 #12
0
 def position_1_1(self):
     grid = Grid(5, 5)
     return Position(1, 1, grid)
コード例 #13
0
 def position_5_0(self):
     grid = Grid(5, 5)
     return Position(5, 0, grid)
コード例 #14
0
 def position_5_5(self):
     grid = Grid(5, 5)
     return Position(5, 5, grid)
コード例 #15
0
 def test_grid_x_str_value_error(self):
     with pytest.raises(ValueError):
         Grid('foo', 2)
コード例 #16
0
 def grid(self):
     return Grid(5, 5)
コード例 #17
0
 def test_invalid_grid_coordinates_y(self):
     with pytest.raises(InvalidGridCoordinates):
         Grid(0, -1)
コード例 #18
0
 def test_grid_y_str_value_error(self):
     with pytest.raises(ValueError):
         Grid(2, 'foo')
コード例 #19
0
ファイル: viewer.py プロジェクト: shprintuzt/Dijkstra
 def reset(self):
     params = self.params
     self.g = Grid(params[0], params[1], params[2], params[3], params[4])
     self.drawing()
     self.flag_flush = False
コード例 #20
0
ファイル: test_grid.py プロジェクト: digocse/robots-challenge
    def test_is_outside_grid(self, robot_position, expected):
        grid = Grid(1, 1)

        value = grid.is_outside_grid(*robot_position)

        assert value == expected
コード例 #21
0
import argparse

from models import Grid, Position, LawnMower
from utils import parse_file

parser = argparse.ArgumentParser(description='Lawn mowers processor.')
parser.add_argument('lm_data_file',
                    metavar='lm-data-file',
                    type=str,
                    help='Lawn mowers data file locations.')
args = parser.parse_args()

if __name__ == '__main__':
    parse_data = parse_file(args.lm_data_file)
    grid = Grid(*parse_data['grid'])
    lm_actions = []
    for lm in parse_data['lawn_mowers']:
        position = Position(*lm['position'], grid=grid)
        orientation = lm['orientation']
        lm_actions.append([LawnMower(position, orientation), lm['actions']])
    for lawn_mower, actions in lm_actions:
        lawn_mower.perform_actions(actions)
        print(lawn_mower.position.x, lawn_mower.position.y,
              lawn_mower.orientation)
コード例 #22
0
ファイル: test_grid.py プロジェクト: digocse/robots-challenge
    def test_apply_robot_instructions_with_empty_grid(self):
        grid = Grid(5, 5)

        grid.apply_robot_instructions('')

        assert not grid.robots