Skip to content

nifalconi/Mars-Rover

Folders and files

NameName
Last commit message
Last commit date

Latest commit

author
Nicolas Falconi
May 5, 2022
5f67e35 · May 5, 2022

History

30 Commits
May 5, 2022
May 5, 2022
May 5, 2022
May 5, 2022
May 3, 2022
May 3, 2022
May 5, 2022
May 5, 2022
May 5, 2022
May 5, 2022
May 5, 2022
May 5, 2022
May 5, 2022

Repository files navigation

Mars Rover

A squad of robotic rovers are to be landed by NASA on a plateau on Mars. This plateau is rectangular and must be navigated by the rovers. A rover's position and location is represented by a combination of x and y co-ordinates and a letter representing one of the four cardinal compass points. The plateau is divided up into a grid to simplify navigation. An example position might be 0, 0, N, which means the rover is in the bottom left corner and facing North. In order to control a rover, NASA sends a simple string of letters. The possible letters are 'L', 'R' and 'M'. 'L' and 'R' makes the rover spin 90 degrees left or right respectively, without moving from its current spot. 'M' means move forward one grid point, and maintain the same heading.

Assume that the square directly North from (x, y) is (x, y+1).

Example Input:

  • Plateau Size: 5 5
  • Rover's Position: 1 2 N
  • Rover Movement Instructions: LMLMLMLMM

Expected Output: 1 3 N

Assumptions

  • The API must handle arbitraty number of request asyncronally.
  • The sequence of instructions are arbitrary in size.
  • The API doesn't require a session.
  • The borders are impenetrable.

Project Structure

server
 ┣ src
 ┃ ┣ controller # responsible for handling incoming requests and returning responses to the client
 ┃ ┣ providers # responsible for handling use cases
 ┃ ┗ validations # responsible for validating the API requests
 ┣ tests # tests
 ┗ server.js # routing
 
 client 
 ┣ src # source code on react 
 ┣ tests # tests 

Commands

Run server

yarn server

Run client

yarn client

Install Packages

yarn

Testing

Jest has been set up to run tests on both server and client code. Any test files you add must have the .spec.js appendix to be picked up by the test runner. For frontend additional plugins are neccesary like the @babel/plugin-transform-runtime.

Run yarn test:client to run frontend tests.

Run yarn test:server to run backend tests.

Validation

The library yup was chosen to specify API validation as it is powerful yet simple. The validation schemas are defined in the src/validations directory and are used on the controller.

Error Handling

  • Client side: Any validation error is routed to the client to be shown to the user.

API Endpoints

POST /v1/move - moves the robot Example:

# expected input
{
 "width": 500,
 "height": 500,
 "position": { "x": 1, "y": 20, "direction": "N"},
 "instructions": "MMMMM"
}

# expected output
{
 "position": {
  "x": 1,
  "y": 25,
  "direction": [0, 1] # Mathematical Representation
     }
}

Improvements

  • Better web interface.
  • Better client testing.
  • Compress the intructions to send even more.

Linting

Linting is done using ESLint.

In this app, ESLint is configured to follow the Airbnb JavaScript style guide with some modifications.

To run the linter:

yarn run lint

License

MIT

About

Real-Full-Stack-Challenge

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published