Exemplo n.º 1
0
        public Robot(CleaningProgram cleaningProgram, IOffice office)
        {
            _office = office;
            _programme = cleaningProgram;

            CleanCell(_programme.InitialPosition);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
 public Robot(CleaningProgram cleaningProgram)
     : this(cleaningProgram, new Office())
 {
 }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
        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());
        }