Skip to content

Commit

Permalink
Spinning right is now available!
Browse files Browse the repository at this point in the history
  • Loading branch information
tirolo committed Jan 11, 2016
1 parent 2b81325 commit 4edfd91
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/Tirolo.CodeKata.PlutoRover.Domain/PlutoRover.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ public void ExecuteCommand(char command)
{
this.CurrentRoverHeadingDirection.Spin("L");
}
else if (command.Equals('R'))
{
this.CurrentRoverHeadingDirection.Spin("R");
}
else
{
throw new NotSupportedException("Command not supported.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ public void Spin(string direction)
else
this.HeadingDirection = (HeadingDirections)currentHeadingDirection - 1;
}
else if (string.Equals(direction.ToUpper(), "R"))
{
if (this.HeadingDirection == HeadingDirections.W)
this.HeadingDirection = HeadingDirections.N;
else
this.HeadingDirection = (HeadingDirections)currentHeadingDirection + 1;
}
}
}
}
18 changes: 17 additions & 1 deletion src/Tirolo.CodeKata.PlutoRover.Tests/PlutoRoverTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,23 @@ public void Rover_Should_Spin_Right_And_Keep_Same_Position_When_R_Command_Given(

// Assert
var actualRoverPosition = plutoRover.ReportPosition();
var expectedRoverPosition = "0,0,N";
var expectedRoverPosition = "0,0,E";

Assert.AreEqual(expectedRoverPosition, actualRoverPosition);
}

[Test]
public void Rover_Should_Be_At_0_0_W_When_FRFRFRFRL_Command_Given()
{
// Arrange
Domain.PlutoRover plutoRover = new Domain.PlutoRover();

// Act
plutoRover.ExecuteCommand("FRFRFRFRL");

// Assert
var actualRoverPosition = plutoRover.ReportPosition();
var expectedRoverPosition = "0,0,W";

Assert.AreEqual(expectedRoverPosition, actualRoverPosition);
}
Expand Down

0 comments on commit 4edfd91

Please sign in to comment.