Skip to content

Instantly share code, notes, and snippets.

@cameronpresley cameronpresley/ModifiedCoordinate.cs Secret
Last active May 24, 2020

Embed
What would you like to do?
Mars Rover - Implementing Rover Part 1
default(Direction); // North
default(int); // 0
default(Coordinate); // null
public struct Coordinate
{
public int X {get; set;}
public int Y {get; set;}
}
public Direction
{
South, North, East, West
}
public class Rover
{
public Direction Orientation {get; set;}
public Coordinate Location {get; set;}
public Rover()
{
Orientation = Direction.North;
}
}
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 struct Date
{
public int Month {get; set;}
public int Day {get; set;}
public int Year {get; set;}
}
public class Order
{
public Date TransactionDate {get; set;}
public decimal Total {get; set;}
}
var order = new Order{Total=9.99m}; // at this point, Order will have a Date of 0/00/0000
order.TransactionDate = new Date{Month=6, Day=22, Year=2020}; // Order has a new date!
order.TransactionDate.Day = 23 // Fail to compile => Cannot modify the return value of `TransactionDate`
// because it is not a variable
using NUnit;
namespace MarsRover.UnitTests.RoverTests
{
[TestFixture]
public class WhenCreating
{
[Test]
public void ThenTheRoverIsFacingNorth()
{
// Arrange and Act
var rover = new Rover();
// Assert
Assert.AreEqual(Direction.North, rover.Orientation);
}
[Test]
public void ThenTheRoverIsAt00()
{
// Arrange and Act
var rover = new Rover();
var expectedLocation = new Coordinate{X=0, Y=0};
Assert.AreEqual(expectedLocation, 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.