The puzzle used for this kata is taken from Advent Of Code 2021 (Day 2 - Part 2). All credits goes to AOC's team for their incredible work.
The TCR Utility Tool I'm using is an adaptation on Murex's one that can be found in one of my repos.
The goal of this kata is to allow people to get familiar with TCR (Test && Commit || Revert), and experience it in a safe context as a pair or mob.
You need to figure how to pilot this submarine.
It seems like the submarine can take a series of commands like forward 1
, down 2
, or up 3
:
down X
increases your aim byX
units.up X
decreases your aim byX
units.forward X
does two things:- It increases your horizontal position by
X
units. - It increases your depth by your aim multiplied by
X
.
- It increases your horizontal position by
Note that since you're on a submarine, down
and up
affect your aim and do the opposite of what you might think.
The submarine seems to already have a planned course. You should probably figure out where it's going. For example:
forward 5
down 5
forward 8
up 3
down 8
forward 2
Your horizontal position, depth and aim all start at 0. The steps above would then modify them as follows:
forward 5
adds5
to your horizontal position, a total of5
.- Because your aim is
0
, your depth does not change.
- Because your aim is
down 5
adds5
to your aim, resulting in a value of5
.forward 8
adds8
to your horizontal position, a total of13
.- Because your aim is
5
, your depth increases by8*5=40
.
- Because your aim is
up 3
decreases your aim by3
, resulting in a value of2
.down 8
adds8
to your aim, resulting in a value of10
.forward 2
adds2
to your horizontal position, a total of15
.- Because your aim is
10
, your depth increases by2*10=20
to a total of60
.
- Because your aim is
After following these instructions, you would have a horizontal position of 15
and a depth of 60
.
The goal of the kata is to make all acceptance tests pass following Test-Driven Development and using the TCR Utility Tool.
Create a branch of your own so you don't push all your commits on the main branch!
- Follow the Test-Driven Development approach.
- Use the TCR Utility Tool with the according mode (Driver|Navigator)
- Here's the command line to use :
tcrw -p -t xunit
ISubmarine
interface cannot be changed.Submarine
component should have an empty constructor.- Handle empty/wrong input so they don't affect the state of the submarine without stopping the process.
- When an acceptance test pass, change its tag to 'Acceptance'.
- Apply SOLID principles whenever possible
- Think about design (not sure all the code should be in the Submarine class, right?).
- For example, grouping domain knowledge inside value objects might be a good idea.
- Refactor the code like it's production code.
- Baby-steps. If you think you're going small, think smaller.
- You should have TCR generating commits often, like every few minutes.
- If you spend more than 5 minutes on an implementation, discard your changes and start with another approach.
- The submarine's behavior is detailed in the summary.
- Try to implement pure functions for better predictability.
- Use acceptance tests to follow your progress.