In this directory, you'll find the files you need to be able to package up your Ruby library into a gem.
The program consists of two class lib/mars_rover/map.rb and lib/mars_rover/rover.rb.
The lib/mars_rover/map.rb class saves the state of the mars_rover map. It's max and min (x,y) co-ordinates. It also checks if the current position of rover is valid or not. Any other state or responsibility related to the map can be extended in this class.
The lib/mars_rover/rover.rb class is the class that represents the rover and its state such as current_postion and instructions. Each instruction from the instructions list is executed one by one sequentially. The rover is either rotated left, right or moved forward according to the instruction. This is done in execute! method. Also, for every unique instruction a method is created to peform that instruction. Any other state or responsibility related to the rover can be extended in this class.
The whole program is then run from the module method
MarsRover.run
in the lib/mars_rover.rb file.
Unit test of each class is placed in test/map_test.rb and test/rover_test.rb file. The intergration test of fully working program is in test/mars_rover_test.rb file.
To experiment with that code, run bin/console
for an interactive prompt.
This program was built with Ruby 2.3.
Install bundle gem and run bundle install in working directory.
gem install bundle && bundle
Build and install the gem.
rake install
After the installation simply run the program with command:
marsrover
or you can execute the file directly:
ruby ./lib/mars_rover.rb
The program will read the input from STDIN and moves the mars rover according to given instruction string.
First line of input should be top right co-ordinate of mars map.
The bottom left is always assumed to be (0,0).
The second line should be the number of mars rover (test case) to be expected.
The second line is followed by the current postion of mars rover and the move instructions.
Allowed moves are:
R : Turns the direction of rover to right
L : Turns the direction of rover to left
M : Moves the rover one unit to current direction
For an example:
Test Input:
5 5
2
1 2 N
LMLMLMLMM
3 3 E
MMRMMRMRRM
Expected Output:
1 3 N
5 1 E
Get the help message with:
marsrover -h
After checking out the repo, run bin/setup
to install dependencies. Then, run rake test
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.
Bug reports and pull requests are welcome on GitHub at https://github.com/bishwahang/mars_rover. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
The gem is available as open source under the terms of the MIT License.