Skip to content

Instantly share code, notes, and snippets.

@cameronpresley
Last active June 9, 2020 02:00
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/eac0e6634e8d3d97d27236bba00b5648 to your computer and use it in GitHub Desktop.
Save cameronpresley/eac0e6634e8d3d97d27236bba00b5648 to your computer and use it in GitHub Desktop.
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