Skip to content

Instantly share code, notes, and snippets.

@trikitrok
Created December 24, 2016 15:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trikitrok/7daea817f7d5c92776d18a6a3ddafad1 to your computer and use it in GitHub Desktop.
Save trikitrok/7daea817f7d5c92776d18a6a3ddafad1 to your computer and use it in GitHub Desktop.

Smelly Mars Rover movement refactoring exercise

Description

In this exercise we'll refactor a particularly smelly implementation of the movement of the rover from the Mars Rover kata.

This is a summary of the behavior of the rover:

  • It's located on a grid at some point with coordinates (x,y) and facing a direction encoded with a character.

  • The meaning of each direction character is:

    • N -> North

    • S -> South

    • E -> East

    • W -> West

  • The rover receives a sequence of commands (a string of characters) which are codified in the following way:

    • When it receives an f, it moves forward one position in the direction it is facing.

    • When it receives a b, it moves backward one position in the direction it is facing.

    • When it receives a l, it turns left changing its direction.

    • When it receives a r, it turns right changing its direction.

This initial code was created using TDD, but the coders unfortunately skipped the refactoring step of TDD.

For this reason, even though, the code is fully tested and behaves as expected, it's full of communication and maintanability problems.

We need to refactor it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment