/ModifiedCoordinate.cs Secret
Last active
May 24, 2020 02:03
Star
You must be signed in to star a gist
Mars Rover - Implementing Rover Part 1
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
default(Direction); // North | |
default(int); // 0 | |
default(Coordinate); // null |
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 struct Coordinate | |
{ | |
public int X {get; set;} | |
public int Y {get; set;} | |
} |
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 Direction | |
{ | |
South, North, East, West | |
} |
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 class Rover | |
{ | |
public Direction Orientation {get; set;} | |
public Coordinate Location {get; set;} | |
public Rover() | |
{ | |
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
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}; | |
} | |
} |
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 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 |
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
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