public void DoInstruction_CleanExpectedPlaces_IfRobotGoToEast()
        {
            // Arrange
            const string instrunction     = "*do something*";
            const int    x                = 0;
            const int    y                = 0;
            const int    moqCleanedPlaces = 6;
            var          command          = new Command {
                Direction = CompassDirection.East, StepsNumber = 3
            };

            commandParser
            .Setup(_ => _.Parse(instrunction))
            .Returns(command);
            office
            .Setup(_ => _.GetValidCoordinate(It.IsAny <int>()))
            .Returns((int c) => c);
            office
            .Setup(_ => _.CleanedPlaces)
            .Returns(moqCleanedPlaces);

            // Act
            robot.DoInstruction(instrunction);

            // Assert
            commandParser.Verify(_ => _.Parse(instrunction), Times.Once);
            office.Verify(_ => _.Clean(x, y), Times.Once);
            office.Verify(_ => _.Clean(x + 1, y), Times.Once);
            office.Verify(_ => _.Clean(x + 2, y), Times.Once);
            office.Verify(_ => _.Clean(x + 3, y), Times.Once);
            office.Verify(_ => _.CleanedPlaces, Times.Once);
        }
Beispiel #2
0
        public void DoInstructions_ReturnCleanedPlaces_IfCleadTwiceSeveralCells()
        {
            // Arrange
            var office = new OfficeArea();
            var robot  = new RobotHoover(office, new CommandParser());

            robot.SetStartPosition(0, 0);
            const int stepsNumber = 5;

            // Act
            robot.DoInstruction($"E {stepsNumber}");
            robot.DoInstruction($"W {stepsNumber + 1}");

            // Assert
            const int initialPosition       = 1;
            const int command1              = stepsNumber;
            const int command2              = 1;
            const int expectedCleanedPlaces = command1 + command2 + initialPosition;

            office.CleanedPlaces.Should().Be(expectedCleanedPlaces);
        }
Beispiel #3
0
        public void DoInstructions_ReturnCleanedPlaces_IfMoveFromOneBondToAnother()
        {
            // Arrange
            var office = new OfficeArea();
            var robot  = new RobotHoover(office, new CommandParser());

            robot.SetStartPosition(-100000, 0);
            const int iterations = 2;

            // Act
            robot.SetStartPosition(-100000, 0);
            for (var i = 0; i < iterations; i++)
            {
                robot.DoInstruction($"E {office.MaxCoordinate}");
                robot.DoInstruction($"E {office.MaxCoordinate}");
                robot.DoInstruction("S 1");
                robot.DoInstruction($"W {office.MaxCoordinate}");
                robot.DoInstruction($"W {office.MaxCoordinate}");
                robot.DoInstruction("S 1");
            }

            // Assert
            const int initialPosition       = 1;
            var       command1              = office.MaxCoordinate * 2 + 1;
            var       command2              = office.MaxCoordinate * 2 + 1;
            var       expectedCleanedPlaces = (command1 + command2) * iterations + initialPosition;

            office.CleanedPlaces.Should().Be(expectedCleanedPlaces);
        }