Skip to content

Instantly share code, notes, and snippets.

@cameronpresley
Last active June 15, 2020 01:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cameronpresley/fb95131d9e9f80e55d692b6b9ea6ed2f to your computer and use it in GitHub Desktop.
Save cameronpresley/fb95131d9e9f80e55d692b6b9ea6ed2f to your computer and use it in GitHub Desktop.
LTE Mars Rover - Turning Left
public void TurnLeft()
{
if (Orientation == Direction.North) {
Orientation = Direction.West;
}
}
public void TurnLeft()
{
if (Orientation == Direction.North) {
Orientation = Direction.West;
}
else if (Orientation == Direction.West) {
Orientation = Direction.South;
}
}
public void TurnLeft()
{
if (Orientation == Direction.North) {
Orientation = Direction.West;
}
else if (Orientation == Direction.West) {
Orientation = Direction.South;
}
else if (Orientation == Direction.South) {
Orientation = Direction.East;
}
}
public void TurnLeft()
{
if (Orientation == Direction.North) {
Orientation = Direction.West;
}
else if (Orientation == Direction.West) {
Orientation = Direction.South;
}
else if (Orientation == Direction.South) {
Orientation = Direction.East;
}
else if (Orientation == Direction.East) {
Orientation = Direction.North;
}
}
[TestFixture]
public class WhenTurningLeft
{
[Test]
public void AndFacingNorthThenTheRoverFacesWest()
{
var rover = new Rover {Orientation=Direction.North};
var initialLocation = rover.Location;
rover.TurnLeft();
Assert.AreEqual(initialLocation, rover.Location);
Assert.AreEqual(Direction.West, rover.Orientation);
}
[Test]
public void AndFacingWestThenTheRoverFacesSouth()
{
var rover = new Rover {Orientation=Direction.West};
var initialLocation = rover.Location;
rover.TurnLeft();
Assert.AreEqual(initialLocation, rover.Location);
Assert.AreEqual(Direction.South, rover.Orientation);
}
[Test]
public void AndFacingSouthThenTheRoverFacesEast()
{
var rover = new Rover {Orientation=Direction.South};
var initialLocation = rover.Location;
rover.TurnLeft();
Assert.AreEqual(initialLocation, rover.Location);
Assert.AreEqual(Direction.East, rover.Orientation);
}
[Test]
public void AndFacingEastThenTheRoverFacesNorth()
{
var rover = new Rover {Orientation=Direction.East};
var initialLocation = rover.Location;
rover.TurnLeft();
Assert.AreEqual(initialLocation, rover.Location);
Assert.AreEqual(Direction.North, rover.Orientation);
}
}
[TestFixture]
public class WhenTurningLeft
{
[Test]
[TestCase(Direction.North, Direction.West, TestName = "AndFacingNorthThenTheRoverFacesWest")]
[TestCase(Direction.West, Direction.South, TestName = "AndFacingWestThenTheRoverFacesSouth")]
[TestCase(Direction.South, Direction.East, TestName = "AndFacingSouthThenTheRoverFacesEast")]
[TestCase(Direction.East, Direction.North, TestName = "AndFacingEastThenTheRoverFacesNorth")]
public void RoverTurningLeft(Direction start, Direction expected)
{
var rover = new Rover { Orientation = start };
var initialLocation = rover.Location;
rover.TurnLeft();
Assert.AreEqual(expected, rover.Orientation);
Assert.AreEqual(initialLocation, rover.Location);
}
}
[TestFixture]
public class WhenTurningLeft
{
[Test]
[TestCase(Direction.East, Direction.North, TestName = "AndFacingEastThenTheRoverFacesNorth")]
public void RoverTurningLeft(Direction start, Direction expected)
{
var rover = new Rover { Orientation = start };
var initialLocation = rover.Location;
rover.TurnLeft();
Assert.AreEqual(expected, rover.Orientation);
Assert.AreEqual(initialLocation, rover.Location);
}
[Test]
[TestCase(Direction.North, Direction.West, TestName = "AndFacingNorthThenTheRoverFacesWest")]
[TestCase(Direction.West, Direction.South, TestName = "AndFacingWestThenTheRoverFacesSouth")]
[TestCase(Direction.South, Direction.East, TestName = "AndFacingSouthThenTheRoverFacesEast")]
[TestCase(Direction.East, Direction.North, TestName = "AndFacingEastThenTheRoverFacesNorth")]
public void RoverTurningLeft(Direction start, Direction expected)
{
var rover = new Rover { Orientation = start };
var initialLocation = rover.Location;
rover.TurnLeft();
Assert.AreEqual(expected, rover.Orientation);
Assert.AreEqual(initialLocation, rover.Location);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment