Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gma/mars-rover-kata
https://github.com/gma/mars-rover-kata
Last synced: 28 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/gma/mars-rover-kata
- Owner: gma
- License: mit
- Created: 2023-11-30T19:05:26.000Z (12 months ago)
- Default Branch: main
- Last Pushed: 2023-12-02T23:14:47.000Z (12 months ago)
- Last Synced: 2023-12-03T22:21:28.848Z (12 months ago)
- Language: Python
- Size: 12.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Mars Rover Kata
===============I put this together during the Software Crafters meetup in Manchester, on 30 November 2023.
The focus of the evening was to apply the [Command Pattern] to the [Mars Rover kata].
[Command Pattern]: https://wiki.c2.com/?CommandPattern
[Mars Rover kata]: https://www.codurance.com/katas/mars-roverThe solution
------------Using the Command pattern suggests that we'll have separate commands for:
- moving forwards
- turning left
- turning rightEach of those commands should be able to access some shared state (i.e. the rover's location),
and should have the same public API/interface. In other words, they all need an `execute()`
method.I decided to store the rover's current location in a `Location` object that had `x` and `y`
attributes. I realised that in order to move the rover forward, I would only need to modify
`x` or `y`, and that the trick was going to be working out how to change them based on
which way the rover was facing.What if the direction it was facing was also represented by an object with `x` and `y`
attributes? North would be `x=0, y=1`, east would be `x=1, y=0`, etc. We could then move
forwards by just adding the direction we were currently facing to the current location.I think that should be enough background for you to explore the code.
Tests are in [test_mars.py](./test_mars.py). The implementation of the commands is in
[mars.py](./mars.py).Running the tests
-----------------To run the tests you'll first need to install a couple of things.
Create and activate a virtual environment, into which you can install the dependencies:
python3 -m venv .venv
source .venv/bin/activateInstall the dependencies with pip-tools:
pip install pip-tools
pip-sync dev-requirements.txtRun the tests:
./test