Skip to content

Commit

Permalink
feat: Implement execute of LEFT, RIGHT, REPORT commands
Browse files Browse the repository at this point in the history
  • Loading branch information
maiisthebest committed Mar 3, 2024
1 parent 051050d commit 9340afc
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/RobotSimulator.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ class RobotSimulator {
case "MOVE":
this.move();
break;

case "LEFT":
this.turnLeft();
break;

case "RIGHT":
this.turnRight();
break;

case "REPORT":
return this.report();
}
}
}
Expand Down
51 changes: 51 additions & 0 deletions src/RobotSimulator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,5 +266,56 @@ describe("RobotSimulator", () => {
expect(robot.y).toBe(1);
expect(robot.direction).toBe("NORTH");
});

it.each`
command
${"LEFT"}
${"left "}
${" lEFt , , , "}
`("should execute LEFT command given $command", ({ command }) => {
const table = new Table(5, 5);
const robot = new Robot();
const simulator = new RobotSimulator(table, robot);
simulator.place(0, 0, "NORTH");

simulator.executeCommand(command);

expect(robot.x).toBe(0);
expect(robot.y).toBe(0);
expect(robot.direction).toBe("WEST");
});

it.each`
command
${"RIGHT"}
${"right "}
${" righT , , , "}
`("should execute RIGHT command given $command", ({ command }) => {
const table = new Table(5, 5);
const robot = new Robot();
const simulator = new RobotSimulator(table, robot);
simulator.place(0, 0, "NORTH");

simulator.executeCommand(command);

expect(robot.x).toBe(0);
expect(robot.y).toBe(0);
expect(robot.direction).toBe("EAST");
});

it.each`
command
${"REPORT"}
${"report "}
${" rePOrt , , , "}
`("should execute REPORT command given $command", ({ command }) => {
const table = new Table(5, 5);
const robot = new Robot();
const simulator = new RobotSimulator(table, robot);
simulator.place(0, 0, "NORTH");

const expectedOutput = `Output: 0,0,NORTH`;
expect(simulator.executeCommand(command)).toBe(expectedOutput);
});
});
});

0 comments on commit 9340afc

Please sign in to comment.