public Robot(CleaningProgram cleaningProgram, IOffice office) { _office = office; _programme = cleaningProgram; CleanCell(_programme.InitialPosition); }
public void ExecutionOutput_PathWithoutRepeatingCells_ReturnsCorrectValue() { var position = new Location(10, 22); var expectedOutput = "=> Cleaned: 2"; IList<MovementInstruction> instructions = new List<MovementInstruction>(); instructions.Add(new MovementInstruction(Direction.East, 1)); var cleaningProgram = new CleaningProgram(position, instructions); var robot = new Robot(cleaningProgram); robot.Clean(); var output = robot.ExecutionOutput(); Assert.AreEqual(expectedOutput, output); }
public void ExecutionOutput_NoInstructionsProvided_ReturnsCorrectValue() { var position = new Location(10, 22); var expectedOutput = "=> Cleaned: 1"; IList<MovementInstruction> instructions = new List<MovementInstruction>(); var cleaningProgram = new CleaningProgram(position, instructions); var robot = new Robot(cleaningProgram); robot.Clean(); var output = robot.ExecutionOutput(); Assert.AreEqual(expectedOutput, output); }
public Robot(CleaningProgram cleaningProgram) : this(cleaningProgram, new Office()) { }
public void RobotCreation_SetsCurrentPosition() { var officeMock = new Mock<IOffice>(); officeMock.Setup(o => o.MarkCellAsCleaned(It.IsAny<Location>())).Verifiable(); var position = new Location(10, 22); IList<MovementInstruction> instructions = new List<MovementInstruction>(); var cleaningProgram = new CleaningProgram(position, instructions); var robot = new Robot(cleaningProgram, officeMock.Object); Assert.AreEqual(position, robot.CurrentPosition); }
public void RobotMovement_WestInstructionOutsideOfPlane_PositionIsOnLeftBoundary() { var officeMock = new Mock<IOffice>(); officeMock.Setup(o => o.MarkCellAsCleaned(It.IsAny<Location>())).Verifiable(); var position = new Location(10, 22); var expectedPosition = new Location(Constants.PlaneRightBoundary, 22); IList<MovementInstruction> instructions = new List<MovementInstruction>(); instructions.Add(new MovementInstruction(Direction.East, Constants.PlaneRightBoundary)); var cleaningProgram = new CleaningProgram(position, instructions); var robot = new Robot(cleaningProgram , officeMock.Object); robot.Clean(); Assert.AreEqual(expectedPosition, robot.CurrentPosition); }
public void RobotMovement_MultipleInstructions_ReturnCorrectPosition() { var officeMock = new Mock<IOffice>(); officeMock.Setup(o => o.MarkCellAsCleaned(It.IsAny<Location>())).Verifiable(); var position = new Location(10, 22); IList<MovementInstruction> instructions = new List<MovementInstruction>(); instructions.Add(new MovementInstruction(Direction.East, 1)); instructions.Add(new MovementInstruction(Direction.South, 1)); instructions.Add(new MovementInstruction(Direction.West, 1)); instructions.Add(new MovementInstruction(Direction.North, 1)); var cleaningProgram = new CleaningProgram(position, instructions); var robot = new Robot(cleaningProgram, officeMock.Object); robot.Clean(); Assert.AreEqual(position, robot.CurrentPosition); }
public void RobotMovement_MaxNumberOfInstructionsProvided_ExecutesWithoutErrors() { var officeMock = new Mock<IOffice>(); officeMock.Setup(o => o.MarkCellAsCleaned(It.IsAny<Location>())).Verifiable(); var position = new Location(10, 22); IList<MovementInstruction> instructions = new List<MovementInstruction>(); var random = new Random(); for (var i = 0; i < 10000; i++) { var direction = (Direction) (random.Next(1, 4)); var steps = 10; instructions.Add(new MovementInstruction(direction, steps)); } var cleaningProgram = new CleaningProgram(position, instructions); var robot = new Robot(cleaningProgram, officeMock.Object); Assert.DoesNotThrow(() => robot.Clean()); }