The challenge is to create a martian robots simulator.
Sample input:
5 3
1 1 E
RFRFRFRF
/
|– src
| |– martian_robots.js
| |– martian_robots.test.js
✅ Robot turns left from any orientation when receives "L" instruction .
✅ Robot turns right from any orientation when receives "R" instruction .
✅ Robot moves forward when receives "F" instruction.
✅ The output indicates the final grid position and orientation of the robot.
✅ If the robot falls off the edge of the grid, the word "LOST" is printed after the position and orientation.
❌ More than one robot.
❌ An instruction to move "off" the world from a grid point from which a robot has been previously lost is ignored by the current robot.
Since it was the first time that I faced this kind of exercise, I took that as an opportunity to keep learning and improving.
This is why I performed the exercise trying to follow TDD methodology:
- Write the test.
- Write the production code.
- Refactor.
That allows me to take "baby steps" and detect errors easier and faster, so that I could fix them before the next step.
You need to have either Node
or Docker
previously installed in your computer.
To start using this project, clone this repo to a new directory.
$ git clone https://github.com/conchaasensiomr/node-martian-robots.git
You have to go to run npm install in order to install the necesary dependencies.
$ npm install
Finally, to run the tests, you need to introduce the following command on your terminal:
$ npm test
⚠️ Should you are a MacOS user, please note that this process might be a bit slow. Take it into account if you are using Docker on a MAC computer.
In case you are using Docker, first of all you need to write the following command on your terminal:
$ docker-compose run martian-robots npm install
Finally, to run the tests, you need to introduce the following command on your terminal:
$ docker-compose run martian-robots npm test
This App has been developed by Concha Asensio.