Пример #1
0
        public void WhenCommandFactoryIsInvokedReturnsTheCorrectCommandImplementation()
        {
            var surface = new Surface(new Coordinates(5, 5));
            var robot   = new Robot(new Position(1, 1, Orientation.E));
            var command = RobotCommandsFactory.GetComand(Instruction.F, robot, surface);

            Assert.IsType <ForwardMovement>(command);

            command = RobotCommandsFactory.GetComand(Instruction.L, robot, surface);
            Assert.IsType <LeftRotationCommand>(command);

            command = RobotCommandsFactory.GetComand(Instruction.R, robot, surface);
            Assert.IsType <RightRotationCommand>(command);
        }
Пример #2
0
        private Robot ExecuteInstructions(Robot robot, List <Instruction> instructions)
        {
            foreach (var instruction in instructions)
            {
                robot = RobotCommandsFactory.GetComand(instruction, robot, Surface)
                        .Execute();

                if (robot.Status == RobotStatus.Lost)
                {
                    Surface.AddScent(robot.Position.Coordinates);
                    return(robot);
                }
            }

            return(robot);
        }
Пример #3
0
        public void GetCommand_Invalid_Command_Throws(char command)
        {
            var commandsFactory = new RobotCommandsFactory();

            Assert.Throws <ArgumentOutOfRangeException>(() => commandsFactory.GetCommand(command));
        }
Пример #4
0
        public void GetCommand_Should_Success(char command)
        {
            var commandsFactory = new RobotCommandsFactory();

            Assert.NotNull(commandsFactory.GetCommand(command));
        }