Пример #1
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);
        }
Пример #2
0
        static void Main(string[] args)
        {
            var source        = new ConsoleDataSource();
            var office        = new OfficeArea();
            var parser        = new CommandParser();
            var robot         = new RobotHoover(office, parser);
            var program       = new CleanProgram(source, office, robot);
            var cleanedPlaces = program.GetCleanedPlaces();

            System.Console.WriteLine($"=> Cleaned: {cleanedPlaces}");
            System.Console.ReadKey();
        }
Пример #3
0
        public void SetStartPosition_StorePosition_IfStepOutOfBonds(int x, int y, int expectedX, int expectedY)
        {
            // Arrange
            var office = new OfficeArea();
            var robot  = new RobotHoover(office, new CommandParser());

            // Act
            robot.SetStartPosition(x, y);

            // Assert
            robot.Position.X.Should().Be(expectedX);
            robot.Position.Y.Should().Be(expectedY);
        }
Пример #4
0
        public void SetStartPosition_StorePosition_IfCellNotCleaned(int x, int y)
        {
            // Arrange
            var office = new OfficeArea();
            var robot  = new RobotHoover(office, new CommandParser());

            // Act
            robot.SetStartPosition(x, y);

            // Assert
            robot.Position.X.Should().Be(x);
            robot.Position.Y.Should().Be(y);
        }
Пример #5
0
        public void DoInstructions_ReturnCleanedPlaces_IfCall()
        {
            // 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}");

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

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