public void ValidPlacementShouldOccur() { placementRequest = new PlacementRequest { X = 0, Y = 1, F = RobotDirection.NORTH }; var placed = _theRobot.Place(placementRequest); Assert.IsTrue(placed); }
public void InvalidPlacementShouldNotOccur() { placementRequest = new PlacementRequest { X = 10, Y = 10, F = RobotDirection.NORTH }; var placed = _theRobot.Place(placementRequest); Assert.IsFalse(placed); }
/// <summary> /// Sets _x, _y and _f values if request contains valid data and returns a bool to indicate success or failure /// </summary> public bool Place(IPlacementRequest req) { var placed = false; if (req != null && robotPlacementValidator.IsValid(req.X.Value) && robotPlacementValidator.IsValid(req.Y.Value) && req.F != null) { _x = req.X; _y = req.Y; _f = req.F; placed = true; } return(placed); }
public void MoveLeftFromFacingNorthShouldBeWest() { placementRequest = new PlacementRequest { X = 4, Y = 4, F = RobotDirection.NORTH }; using (var sw = new StringWriter()) { Console.SetOut(sw); _theRobot.Place(placementRequest); _theRobot.TurnLeft(); _theRobot.Report(); var report = sw.ToString(); Assert.AreEqual(RobotDirection.WEST.ToString(), report.Split(new string[] { ",", ":" }, StringSplitOptions.None)[3].Replace("\n", String.Empty).Replace("\r", string.Empty)); } }
public void ReportShouldOutputIfPlacementOccurred() { placementRequest = new PlacementRequest { X = 4, Y = 4, F = RobotDirection.NORTH }; using (var sw = new StringWriter()) { Console.SetOut(sw); _theRobot.Place(placementRequest); _theRobot.Move(); _theRobot.Report(); var report = sw.ToString(); Assert.IsFalse(string.IsNullOrEmpty(report)); } }
public void InvalidMoveShouldNotOccur() { placementRequest = new PlacementRequest { X = 4, Y = 4, F = RobotDirection.NORTH }; using (var sw = new StringWriter()) { Console.SetOut(sw); _theRobot.Place(placementRequest); _theRobot.Move(); _theRobot.Report(); var report = sw.ToString(); Assert.AreNotEqual(report, "5"); } }
public void MoveRighttManyTimesShouldNotBeInvalid(int x, int y, RobotDirection f) { placementRequest = new PlacementRequest { X = x, Y = y, F = f }; using (var sw = new StringWriter()) { Console.SetOut(sw); _theRobot.Place(placementRequest); _theRobot.TurnRight(); _theRobot.TurnRight(); _theRobot.TurnRight(); _theRobot.TurnRight(); _theRobot.TurnRight(); _theRobot.Report(); var report = sw.ToString(); Assert.AreEqual(RobotDirection.SOUTH.ToString(), report.Split(new string[] { ",", ":" }, StringSplitOptions.None)[3].Replace("\n", String.Empty).Replace("\r", String.Empty)); } }