A solution to the Mars Rover challenge for Platform45.
To install all relevant Node packages, run
npm ciMars Rover v.2 is a solution to the Mars Rover coding challenge. My application is a terminal application that receives all relevant data from the user. I perform some validation on this data to make sure it is in the correct form, throwing errors and allowing for correction in most cases.
For my second go at this challenge, not only did I do it in TypeScript, but I tried to apply some OOP principles learnt from Metz's Practical Object-Oriented Design in Ruby and from work done with the Nestjs framework. I encapsulated responsibilities in classes and handled their dependencies by injecting them where required.
The point of entry for this app is main.ts.
While coding this app, I assumed
- the rovers complete their instructions sequentially and don't clash on the plateau
- the rovers cannot exceed the bounds of the plateau
- user data is not persisted between sessions of the app
npm run appFollow the prompts in your terminal to play the game. Hit ctrl+c to exit the game.
The code coverage is quite low as testing the stdin and stdout of Node's process is quite tricky. In the interests of time, I therefore only wrote unit tests for the crucial small methods that move and direct the rover.
The e2e spec tests that, given the correct user input, the app works from start to finish. The first test in this suite uses the example given in the challenge as test data.
To run the unit tests, run
npm run testTo run them with coverage, run
npm run test:covThe coverage report for the units tests is stored in the coverage directory.
To run the tests in watch mode, run
npm run test:watchThe e2e test tests a typical user journey through the app.
To run the e2e tests, run
npm run test:e2eTo run the e2e tests with coverage, run
npm run test:e2e:covThe coverage report is stored in the tests/coverage directory.
To run the e2e tests in watch mode, run
npm run test:e2e:watch