Skip to content

Instantly share code, notes, and snippets.

@cameronpresley cameronpresley/RoverFacingEast.cs Secret
Last active Jun 9, 2020

Embed
What would you like to do?
Gists needed for LTE Mars Rover - Moving Backward
public class Rover
{
public Direction Orientation {get; set;}
public Coordinate Location {get; set;}
public Rover()
{
Orientation = Direction.North;
Location = new Coordinate(){X=0, Y=0};
}
public void MoveBackward()
{
if (Orientation == Direction.North) {
Location=Location.AdjustYBy(-1);
}
if (Orientation == Direction.South) {
Location = Location.AdjustYBy(1);
}
Location = Location.AdjustXBy(-1);
}
}
public class Rover
{
public Direction Orientation {get; set;}
public Coordinate Location {get; set;}
public Rover()
{
Orientation = Direction.North;
Location = new Coordinate(){X=0, Y=0};
}
public void MoveBackward()
{
Location=Location.AdjustYBy(-1);
}
}
public class Rover
{
public Direction Orientation {get; set;}
public Coordinate Location {get; set;}
public Rover()
{
Orientation = Direction.North;
Location = new Coordinate(){X=0, Y=0};
}
public void MoveBackward()
{
if (Orientation == Direction.North) {
Location=Location.AdjustYBy(-1);
}
Location = Location.AdjustYBy(1);
}
}
public class Rover
{
public Direction Orientation {get; set;}
public Coordinate Location {get; set;}
public Rover()
{
Orientation = Direction.North;
Location = new Coordinate(){X=0, Y=0};
}
public void MoveBackward()
{
if (Orientation == Direction.North) {
Location=Location.AdjustYBy(-1);
}
if (Orientation == Direction.South) {
Location = Location.AdjustYBy(1);
}
if (Orientation == Direction.East) {
Location = Location.AdjustXBy(-1);
}
if (Orientation == Direction.West) {
Location = Location.AdjustXBy(1);
}
}
}
public class Rover
{
public Direction Orientation {get; set;}
public Coordinate Location {get; set;}
public Rover()
{
Orientation = Direction.North;
Location = new Coordinate(){X=0, Y=0};
}
public void MoveForward()
{
if (Orientation == Direction.North) {
Location = Location.AdjustYBy(1);
}
if (Orientation == Direction.South) {
Location = Location.AdjustYBy(-1);
}
if (Direciton == Direction.East) {
Location = Location.AdjustXBy(1);
}
if (Orientation == Direction.West) {
Location = Location.AdjustXBy(-1);
}
}
public void MoveBackward()
{
if (Orientation == Direction.North) {
Location=Location.AdjustYBy(-1);
}
if (Orientation == Direction.South) {
Location = Location.AdjustYBy(1);
}
if (Orientation == Direction.East) {
Location = Location.AdjustXBy(-1);
}
if (Orientation == Direction.West) {
Location = Location.AdjustXBy(1);
}
}
}
[TestFixture]
public class WhenMovingBackward
{
[Test]
public void AndFacingNorthThenYDecreasesByOne()
{
var rover = new Rover { Orientation = Direction.North };
var initialLocation = rover.Location;
rover.MoveBackward();
var expectedLocation = new Coordinate(initialLocation.X, initialLocation.Y - 1);
Assert.AreEqual(expectedLocation, rover.Location);
Assert.AreEqual(Direction.North, rover.Orientation);
}
[Test]
public void AndFacingEastThenXDecreasesByOne()
{
var rover = new Rover { Orientation = Direction.East };
var initialLocation = rover.Location;
rover.MoveBackward();
var expectedLocation = new Coordinate(initialLocation.X - 1, initialLocation.Y);
Assert.AreEqual(expectedLocation, rover.Location);
Assert.AreEqual(Direction.East, rover.Orientation);
}
[Test]
public void AndFacingSouthThenYIncreasesByOne()
{
var rover = new Rover { Orientation = Direction.South };
var initialLocation = rover.Location;
rover.MoveBackward();
var expectedLocation = new Coordinate(initialLocation.X, initialLocation.Y + 1);
Assert.AreEqual(expectedLocation, rover.Location);
Assert.AreEqual(Direction.South, rover.Orientation);
}
[Test]
public void AndFacingWestThenXIncreasesByOne()
{
var rover = new Rover { Orientation = Direction.West };
var initialLocation = rover.Location;
rover.MoveBackward();
var expectedLocation = new Coordinate(initialLocation.X + 1, initialLocation.Y);
Assert.AreEqual(expectedLocation, rover.Location);
Assert.AreEqual(Direction.West, rover.Orientation);
}
}
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.