public void TurnRight_ForAllFacings_TurnTheRobotToRight(FacingEnum facing, FacingEnum expectedFacing) { _order1.CurrentState = new StateOfRobot { Cell = new Cell { Point = new Point(1, 1), State = CellStateEnum.StateS }, Faceing = facing }; _order1.Commands = new List <CommandEnum> { CommandEnum.TR }; var cleanService = new CleanService(_order1); var result = cleanService.Start(); Assert.That(expectedFacing, Is.EqualTo(result.FinalState.Faceing)); }
public void Advance_EverythingNormalForForward_RobotShouldGoNextPoint(int x, int y, FacingEnum facing, int expectedX, int expectedY) { _order1.CurrentState = new StateOfRobot { Cell = new Cell { Point = new Point(x, y), State = CellStateEnum.StateS }, Faceing = facing }; _order1.Commands = new List <CommandEnum> { CommandEnum.A }; var cleanService = new CleanService(_order1); var result = cleanService.Start(); Assert.That(expectedX, Is.EqualTo(result.FinalState.Cell.Point.X)); Assert.That(expectedY, Is.EqualTo(result.FinalState.Cell.Point.Y)); Assert.That(_order1.Battery, Is.EqualTo(78)); }
static void Main(string[] args) { var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory.ToString(), args[0]); using (StreamReader r = new StreamReader(path)) { string json = r.ReadToEnd(); dynamic array = JsonConvert.DeserializeObject(json); var orderFromJson = JsonConvert.DeserializeObject <OrderFromJson>(json); var order = orderFromJson.ConvertToOrder(); CleanService cleanService = new CleanService(order); var result = cleanService.Start(); var resultToJson = new ResultToJson { Battery = result.Battery, Cleaned = result.CleanedCells.Select(x => x.Point).ToList(), Visited = result.VisitedCells.Select(x => x.Point).ToList(), Final = new Start { Facing = Enum.GetName(typeof(FacingEnum), result.FinalState.Faceing).Substring(0, 1), X = result.FinalState.Cell.Point.X, Y = result.FinalState.Cell.Point.Y } }; var resultJson = JsonConvert.SerializeObject(resultToJson, new PointJsonConverter()); var resultPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory.ToString(), args[1]); File.WriteAllText(resultPath, JToken.Parse(resultJson).ToString(Formatting.Indented)); Console.WriteLine("Done"); } }
public void Start_Order1_ShouldReturnExpectedResult() { _order1.Commands = new List <CommandEnum> { CommandEnum.TL, CommandEnum.A, CommandEnum.C, CommandEnum.A, CommandEnum.C, CommandEnum.TR, CommandEnum.A, CommandEnum.C }; _order1.CurrentState = new StateOfRobot { Faceing = FacingEnum.North, Cell = new Cell { Point = new Point(3, 0) } }; var expectedVisitedCells = new List <Cell> { new Cell { Point = new Point(3, 0), State = CellStateEnum.StateS, IsVisited = false }, new Cell { Point = new Point(2, 0), State = CellStateEnum.StateS, IsVisited = false }, new Cell { Point = new Point(1, 0), State = CellStateEnum.StateS, IsVisited = false } }; var expectedCleanedCells = new List <Cell> { new Cell { Point = new Point(2, 0), State = CellStateEnum.StateS, IsVisited = false }, new Cell { Point = new Point(1, 0), State = CellStateEnum.StateS, IsVisited = false } }; var cleanService = new CleanService(_order1); var result = cleanService.Start(); Assert.That(54, Is.EqualTo(result.Battery)); Assert.That(3, Is.EqualTo(result.VisitedCells.Count)); CollectionAssert.AreEqual(expectedVisitedCells, result.VisitedCells); Assert.That(2, Is.EqualTo(result.CleanedCells.Count)); CollectionAssert.AreEqual(expectedCleanedCells, result.CleanedCells); Assert.That(FacingEnum.East, Is.EqualTo(result.FinalState.Faceing)); }
public void Start_Order2_ShouldReturnExpectedResult() { _order1.Commands = new List <CommandEnum> { CommandEnum.TR, CommandEnum.A, CommandEnum.C, CommandEnum.A, CommandEnum.C, CommandEnum.TR, CommandEnum.A, CommandEnum.C }; _order1.CurrentState = new StateOfRobot { Faceing = FacingEnum.South, Cell = new Cell { Point = new Point(3, 1) } }; _order1.Battery = 1094; var expectedVisitedCells = new List <Cell> { new Cell { Point = new Point(3, 2), State = CellStateEnum.StateS, IsVisited = false }, new Cell { Point = new Point(3, 1), State = CellStateEnum.StateS, IsVisited = false }, new Cell { Point = new Point(3, 0), State = CellStateEnum.StateS, IsVisited = false }, new Cell { Point = new Point(2, 2), State = CellStateEnum.StateS, IsVisited = false } }; var expectedCleanedCells = new List <Cell> { new Cell { Point = new Point(3, 2), State = CellStateEnum.StateS, IsVisited = false }, new Cell { Point = new Point(3, 0), State = CellStateEnum.StateS, IsVisited = false }, new Cell { Point = new Point(2, 2), State = CellStateEnum.StateS, IsVisited = false } }; var cleanService = new CleanService(_order1); var result = cleanService.Start(); expectedVisitedCells = expectedVisitedCells.OrderBy(x => x.Point.X).ThenBy(x => x.Point.Y).ToList(); result.VisitedCells = result.VisitedCells.OrderBy(x => x.Point.X).ThenBy(x => x.Point.Y).ToList(); expectedCleanedCells = expectedCleanedCells.OrderBy(x => x.Point.X).ThenBy(x => x.Point.Y).ToList(); result.CleanedCells = result.CleanedCells.OrderBy(x => x.Point.X).ThenBy(x => x.Point.Y).ToList(); Assert.That(1040, Is.EqualTo(result.Battery)); Assert.That(4, Is.EqualTo(result.VisitedCells.Count)); CollectionAssert.AreEqual(expectedVisitedCells, result.VisitedCells); Assert.That(3, Is.EqualTo(result.CleanedCells.Count)); CollectionAssert.AreEqual(expectedCleanedCells, result.CleanedCells); Assert.That(FacingEnum.East, Is.EqualTo(result.FinalState.Faceing)); }