/MarsRoversJS

MarsRovers challenge build with nodejs

Primary LanguageJavaScript

NASA ROVER TEST - Nodejs

This is a Nasa Rover Test implementation, using node v10.0.0 and tested using Mocha and Chai

The Challenge

A squad of rovers are to be sent by NASA to a plateau on Mars. The Agency must be able to control the movement of these rovers, to get a complete view of the terrain and send back to earth. A rover's position must be represented by a combination of an x and y coordinates and a letter representing one of the four cardinal compass points. The terrain to be explored in Mars is divided up into a grid to simplify navigation. An example of valid position is 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 containing a set of the letters 'L', 'R' and 'M'. 'L' and 'R' makes the rover spin 90 degrees left or right respectively, without moving from its current spot, and 'M' means move forward one grid point maintaining the same direction, so the instruction M for a rover with a cordinate like 0, 0, N must be 0, 1, N .

User interaction:

  • Input: -- Configuration Input: The first line of input is the upper-right coordinates of the plateau, the lower-left coordinates are assumed to be 0,0.

  • Per Rover Input: -- Input 1: Landing coordinates for the named Rover. The position is made up of two integers and a letter separated by spaces, corresponding to the x and y coordinates and the rover's orientation. -- Input 2: Navigation instructions for the named rover. i.e a string containing ('L', 'R', 'M').

IMPLEMENTATION

The implementation was made looking for a easy way to lead the user throught the application, so it was separated by user steps:

  • First step is to inform the terrain size, using a pair of numbers separated by space (ex: 12 8 will generate a terrain with 12x8).
  • Next step is to inform how many rover are going to be sent. This will provide a list with numerated and named rovers.
  • Next step is to inform, one by one, the landing coordinates and the direction for each rover (ex: 1, 8, N).
  • Doing that, the user will face a small menu, where 3 options are available: 1 - Move a rover, View rovers location and Exit application.
  • By choosing 1 - Move a rover:
    • The user will be asked the whitch rover is wanted to be moved.
    • The movement instructions (ex: RMMLMR).
    • The application then provide a feedback message informing if the rover was moved successfully or if it has an error.
    • The user will be sent back to the menu to choose his next action.
  • By choosing View rovers location:
    • A Message will be printed to show to the users the information about all the rovers sent to Mars.
  • By choosing Exit application:
    • User will be presented to shutdown message and exit the application

Using the application

With node v10 and npm installed:

  • Clone the repository https://github.com/DiegoSouzaDev/MarsRoversJS.git
  • Run npm install in the repository clone directory to install the dependencies.
  • Run npm start in the repository clone directory to start the application.

Testing the application

  • Run npm install in the repository clone directory to install the dependencies.
  • Run npm test in the repository clone directory to start the application.

Unit test coverage (generated by Istanbul)


File % Stmts % Branch % Funcs % Lines
All files 84.89 83.33 100 84.44
model 100 100 100 100
Rover.js 100 100 100 100
Terrain.js 100 100 100 100
service 84.21 83.33 100 83.72
MovementService.js 78.48 73.33 100 77.92
RoverService.js 92.68 100 100 92.31
TerrainService.js 92.31 100 100 92.31