This is an attempt to solve the given imaginary problem.
- The application is a simulation of a toy robot moving on a square tabletop, of dimensions 5 units x 5 units.
- There are no other obstructions on the table surface.
- The robot is free to roam around the surface of the table, but must be prevented from falling to destruction. Any movement that would result in the robot falling from the table must be prevented, however further valid movement commands must still be allowed.
Create an application that can read in commands of the following form:
PLACE X,Y,F
MOVE
LEFT
RIGHT
REPORT
-
PLACE
will put the toy robot on the table in position X,Y and facingNORTH
,SOUTH
,EAST
orWEST
. -
The origin (0,0) can be considered to be the
SOUTH WEST
most corner. -
The first valid command to the robot is a
PLACE
command, after that, any sequence of commands may be issued, in any order, including anotherPLACE
command. The application should discard all commands in the sequence until a validPLACE
command has been executed. -
MOVE
will move the toy robot one unit forward in the direction it is currently facing. -
LEFT
andRIGHT
will rotate the robot 90 degrees in the specified direction without changing the position of the robot. -
REPORT
will announce the X,Y and F of the robot. This can be in any form, but standard output is sufficient. -
A robot that is not on the table can choose to ignore the
MOVE
,LEFT
,RIGHT
andREPORT
commands. -
Input can be from a file, or from standard input, as the developer chooses.
-
Provide test data to exercise the application.
-
It is not required to provide any graphical output showing the movement of the toy robot.
Add this line to your application's Gemfile:
gem 'awesome_toy_robot_simulator'
And then execute:
$ bundle
Or install it yourself as:
$ gem install awesome_toy_robot_simulator
The reason why I chose to go with gem was basically for nicety of an easy installation for whoever is trying to make use of our ToyRobot Simulator. Not to mention the fact that it can be also used alongside in another app as a new dependency. I have tried to write this test solution in way that can provide scalabiliy for new upcoming features, and to also ensure readability, by creating small classes with basic responsabilities. That way, it can follow a more smoothly onboarding process.
This gems is using the follwing gems for self support:
- bundler (our default dependency manager)
- pry (for testing purposes only)
- simplecov (for increase/ensure test coverage)
- rake (for creating our custom rake tasks)
- reek (for adding nice linting for code smells)
- rspec (our BDD testing gem)
- rubocop (same as reek, but for more general syntax rules)
To run our AwesomeToyRobotSimulator, just install the gem, and run:
$ awesome_toy_robot_simulator path_for_the_given_file_to_be_processed
After checking out the repo, run bin/setup
to install dependencies. Then, run rake spec
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/tiarly/awesome_toy_robot_simulator. 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.
Everyone interacting in the AwesomeToyRobotSimulator project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.