Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dallas_mars_rover

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dallas_mars_rover

  • 1.0.0
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

MarsRover

Mars Rover is program which takes a text file in the format as described below and then displays its resulting rover location to the console.

File Format

8 8
1 2 E
MMLMRMMRRMML

Where line 1 is the size of the survey zone. Line 2 is the start position of the mars rover and the starting direction. Line 3 contains the commands for the rover to follow. M moves the rover, L turns the rover 90 degrees left and R turns the rover 90 degrees right.

The application does all the pre-checks before executing; from validating program arguments, checking starting points are in the define survey zone and validating all actions are valid. Once the checks have passed, commands are passed to the rover for execution. On completion the resulting location is displayed to the console.

Installation

Add this line to your application's Gemfile:

gem 'dallas_mars_rover'

And then execute:

$ bundle

Or install it yourself as:

$ gem install dallas_mars_rover

Usage

Just run the executable:

$ dallas_mars_rover command_file

There are 3 sample files to test: file1.txt is the test file file2.txt is a case failure file3.txt is a larger test pass

And it will output the resultant position to the console.

See the screenshot for usage examples

Design Considerations

I implemented this assignment as a gem as it shows all the features that make up a ruby application. From gem creation, using bundler, versioning and ruby conventions. Traditionally code correctness would be tested using TDD or BDD, I implement some basic tests showing the use of minitest, but for this solution pencil and graph paper was used to test as well. I design the app to run as modular as possible keeping each major component to its own object, namely:

  • MarsRover
  • Commander
  • Zone
  • Rover

MarsRover This is the main application. It handles the creation of the objects, the starting of the rover, displaying the results and simple validations on the file passed as an argument. If multiple arguments are passed it checks them to see which are actual files and if more than one file will let the user know to supply one. On successful creation of all the required objects, it passes the commands to the rover for processing.

Commander The commander object handles the validation of the contents of the command file. It reads in the 3 lines and validates each against a set of rules before passing over control. I checks the start position is in the survey zone. Checks the start direction is a valid cardinal point. Then runs all the rover locomotion commands through a validator to see only the 3 required commands are there.

Zone The zone object holds a map of the co-ordinates for the rover and can check if a rover move is valid.

Rover The object for the physical rover. It tracks its current position in the zone and drives and turns based on the commands given to it from the commander object. On completion of processing its commands, it gives control back to MarsRover to return its current position.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/dallasgoldswain/mars_rover.

License

The gem is available as open source under the terms of the MIT License.

FAQs

Package last updated on 17 Aug 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc