Skip to content

Commit 1f37e82

Browse files
author
Vince Wong
committed
Source code and test files for toy robot
0 parents  commit 1f37e82

15 files changed

+1733
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

PROBLEM.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Toy Robot Simulator
2+
3+
## Description
4+
5+
- The application is a simulation of a toy robot moving on a square tabletop,
6+
of dimensions 5 units x 5 units.
7+
- There are no other obstructions on the table surface.
8+
- The robot is free to roam around the surface of the table, but must be
9+
prevented from falling to destruction. Any movement that would result in the
10+
robot falling from the table must be prevented, however further valid
11+
movement commands must still be allowed.
12+
13+
Create an application that can read in commands of the following (textual) form:
14+
15+
PLACE X,Y,F
16+
MOVE
17+
LEFT
18+
RIGHT
19+
REPORT
20+
21+
- PLACE will put the toy robot on the table in position X,Y and facing NORTH,
22+
SOUTH, EAST or WEST.
23+
- The origin (0,0) can be considered to be the SOUTH WEST most corner.
24+
- The first valid command to the robot is a PLACE command, after that, any
25+
sequence of commands may be issued, in any order, including another PLACE
26+
command. The application should discard all commands in the sequence until
27+
a valid PLACE command has been executed.
28+
- MOVE will move the toy robot one unit forward in the direction it is
29+
currently facing.
30+
- LEFT and RIGHT will rotate the robot 90 degrees in the specified direction
31+
without changing the position of the robot.
32+
- REPORT will announce the X,Y and F of the robot. This can be in any form,
33+
but standard output is sufficient.
34+
35+
- A robot that is not on the table can choose the ignore the MOVE, LEFT, RIGHT
36+
and REPORT commands.
37+
- Input can be from a file, or from standard input, as the developer chooses.
38+
- Provide test data to exercise the application.
39+
- The application must be a command line application.
40+
41+
## Constraints
42+
43+
- The toy robot must not fall off the table during movement. This also
44+
includes the initial placement of the toy robot.
45+
- Any move that would cause the robot to fall must be ignored.
46+
47+
## Example Input and Output
48+
49+
### Example a
50+
51+
PLACE 0,0,NORTH
52+
MOVE
53+
REPORT
54+
55+
Expected output:
56+
57+
0,1,NORTH
58+
59+
### Example b
60+
61+
PLACE 0,0,NORTH
62+
LEFT
63+
REPORT
64+
65+
Expected output:
66+
67+
0,0,WEST
68+
69+
### Example c
70+
71+
PLACE 1,2,EAST
72+
MOVE
73+
MOVE
74+
LEFT
75+
MOVE
76+
REPORT
77+
78+
Expected output
79+
80+
3,3,NORTH

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# NodeJS CLI Toy Robot Simulator
2+
3+
## Description
4+
5+
This is a NodeJS command-line application. The Node version used to develop this is v10.11.0.
6+
7+
## Demo Video Link
8+
9+
## Installation
10+
11+
1. Install globally by running `npm install -g`
12+
2. Execute the command `toy-robot`
13+
14+
## Running it from source
15+
16+
1. Install dependencies by running `yarn install`
17+
2. Start the program by running `yarn start`
18+
19+
## Different Cases Handled
20+
21+
- When user go through the normal flow
22+
- When user keys in an invalid 1st command (that should be a PLACE command)
23+
- When user keys in an invalid coordinate
24+
- When user keys in an invalid direction
25+
- When user keys in an invalid commands (input other than PLACE, MOVE, LEFT, RIGHT, REPORT)
26+
- When the toy robot had moved to an invalid coordinate (changes will be discarded)
27+
28+
## Test
29+
30+
You may check on the test by running `yarn test`

0 commit comments

Comments
 (0)