LTE Mars Rover - Turning Left
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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