Skip to content

Instantly share code, notes, and snippets.

@cameronpresley

cameronpresley/Rover.cs Secret

Last active Jun 15, 2020
Embed
What would you like to do?
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
You can’t perform that action at this time.