This repository contains a Scala implementation of the Goose Game Kata. It implements all the requirements, mandatory and optional, see src/test/scala/chaordic/goose/GameSpec.scala
for test coverage of all cases (there are other tests as well, but game logic is contained in this test).
This code is released under a MIT License.
- A recent version of SBT and the Java Development Kit is required (this implementation has been tested with SBT 1.3.3 and OpenJDK 11.0.2).
- Run
sbt
- To run the application from sbt, simply type
run
at the prompt after starting sbt. - To run as a standalone executable jar:
- Build with
assembly
through the sbt interactive prompt, then - Exit sbt
- Run
java -jar target/scala-2.12/game-of-goose.jar
- Build with
- To run the test-suite, run
test
from the sbt prompt.
This implementation uses a purely functional style using Cats IO
-monad.
This gives us a couple of benefits:
- Side-effecting code is clearly separated from pure code by return type-signature.
IO
allows us to use stack-safe recursion (more).- Which in turn allows us to implement the entire application immutably with an event-loop, with no mutable state whatsoever.
- Immutability has clear benefits in reducing the potential number of bugs.
Furthermore, we use Scalas Parser Combinators to safely
parse user input in a less error-prone way than hand-munging Strings
at no extra code-weight.
Finally, we use JLine3 to give a more pleasant experience when entering game commands.
The application has comprehensive test-coverage (100% branch coverage), which can be inspected with the coverage plugin:
run coverageOn
, followed by clean
, test
and coverageReport
in sbt to generate the report.
There are many ways this could be implemented, this is one flavour of it!