Пример #1
0
        public void CreateCommandFactory_AddZeroInputCommands()
        {
            CommandFactory commandFactory = new CommandFactory();

            commandFactory.AddInputs("0");
            commandFactory.AddInputs("10 22");

            Assert.IsTrue(commandFactory.IsInputComplete);
        }
Пример #2
0
        public void CreateCommandFactory_SingleMoveCommand()
        {
            CommandFactory commandFactory = new CommandFactory();

            commandFactory.AddInputs("2");
            commandFactory.AddInputs("10 22");
            commandFactory.AddInputs("E 2");

            Assert.AreEqual(1, commandFactory.commandSet.MoveCommands.Count);
        }
Пример #3
0
        public void CreateCommandFactory_NormalPosition()
        {
            CommandFactory commandFactory = new CommandFactory();

            commandFactory.AddInputs("0");
            commandFactory.AddInputs("10 22");

            Assert.AreEqual(10, commandFactory.commandSet.StartPosition.X);
            Assert.AreEqual(22, commandFactory.commandSet.StartPosition.Y);
        }
Пример #4
0
        public void CreateCommandFactory_SingleMoveCommandWithLessSteps()
        {
            CommandFactory commandFactory = new CommandFactory();

            commandFactory.AddInputs("2");
            commandFactory.AddInputs("10 22");
            commandFactory.AddInputs("E -1");
            MoveCommand moveCommand = commandFactory.commandSet.MoveCommands[0];

            Assert.AreEqual(1, moveCommand.MoveSteps);
        }
Пример #5
0
        public void CreateCommandFactory_AddNegativeInputCommands()
        {
            CommandFactory commandFactory = new CommandFactory();

            commandFactory.AddInputs("-1");
            commandFactory.AddInputs("10 22");

            commandFactory.AddInputs("N 1");

            Assert.IsTrue(commandFactory.IsInputComplete);
        }
Пример #6
0
        public void CreateCommandFactory_AddThreeInputcommands()
        {
            CommandFactory commandFactory = new CommandFactory();

            commandFactory.AddInputs("3");
            commandFactory.AddInputs("10 22");
            commandFactory.AddInputs("E 2");
            commandFactory.AddInputs("N 1");
            commandFactory.AddInputs("S 2");

            Assert.IsTrue(commandFactory.IsInputComplete);
        }
Пример #7
0
        public void CommandFactory_NullCommandSet()
        {
            CommandFactory commandFactory = new CommandFactory();

            commandFactory.AddInputs("3");
            commandFactory.AddInputs("10 22");
            commandFactory.AddInputs("E -1");

            CommandSet commandSet = commandFactory.GetCommandSet();

            Assert.IsNull(commandSet);
        }
Пример #8
0
        public void CreateRobot_RoboCreation()
        {
            CommandFactory commandFactory = new CommandFactory();

            commandFactory.AddInputs("0");
            commandFactory.AddInputs("0 0");

            CommandSet commandSet = commandFactory.GetCommandSet();

            Robot robot = new Robot(commandSet, null);

            Assert.IsNotNull(robot);
        }
Пример #9
0
        public void CreateCommandFactory_AddTwentyThousandInputCommands()
        {
            CommandFactory commandFactory = new CommandFactory();

            commandFactory.AddInputs("12000");
            commandFactory.AddInputs("10 22");

            for (int i = 0; i < 20000; i++)
            {
                commandFactory.AddInputs("N 1");
            }

            Assert.IsTrue(commandFactory.IsInputComplete);
        }
Пример #10
0
        public void RunRobot_EmptyCommandSetWithNullReport()
        {
            CommandFactory commandFactory = new CommandFactory();

            commandFactory.AddInputs("0");
            commandFactory.AddInputs("0 0");

            CommandSet commandSet = commandFactory.GetCommandSet();
            Robot      robot      = new Robot(commandSet, null);

            robot.ExecuteCommands();
            string report = robot.ReportOutPut();

            Assert.AreEqual("=> Cleaned: unknown", report);
        }
Пример #11
0
        public void RunRobot_WithNoPositionChange()
        {
            CommandFactory commandFactory = new CommandFactory();

            commandFactory.AddInputs("0");
            commandFactory.AddInputs("0 0");

            CommandSet commandSet = commandFactory.GetCommandSet();
            Robot      robot      = new Robot(commandSet, null);

            robot.ExecuteCommands();

            Assert.AreEqual(commandSet.StartPosition.X, robot.Position.X);
            Assert.AreEqual(commandSet.StartPosition.Y, robot.Position.Y);
        }
Пример #12
0
        static void Main(string[] args)
        {
            //Get input commands
            CommandFactory commandFactory = new CommandFactory();

            Console.WriteLine("Enter Inputs:");

            while (!commandFactory.IsInputComplete)
            {
                Console.WriteLine(">");
                commandFactory.AddInputs(Console.ReadLine());
            }
            Console.WriteLine("Input Complete, Press any key to continue..");
            Console.ReadLine();

            //Execute commands
            SimpleReporter reporter = new SimpleReporter();
            Robot          robo     = new Robot(commandFactory.GetCommandSet(), reporter, new Location(0, 0), new Location(10, 10));

            robo.ExecuteCommands();

            //Reports number of places cleaned
            Console.WriteLine(reporter.ReportOutPut());

            Console.ReadLine();
        }
Пример #13
0
        public void RunRobot_OutofBoundsCommandSetWithMovements()
        {
            CommandFactory commandFactory = new CommandFactory();

            commandFactory.AddInputs("1");
            commandFactory.AddInputs("100000 100000");
            commandFactory.AddInputs("N 1");

            CommandSet commandSet = commandFactory.GetCommandSet();
            Robot      robot      = new Robot(commandSet, null, null, new Location(100000, 100000));

            robot.ExecuteCommands();

            Assert.AreEqual(commandSet.StartPosition.X, robot.Position.X);
            Assert.AreEqual(commandSet.StartPosition.Y, robot.Position.Y);
        }
Пример #14
0
        public void RunRobot_SimpleCommandSetWithMovementBy1()
        {
            CommandFactory commandFactory = new CommandFactory();

            commandFactory.AddInputs("1");
            commandFactory.AddInputs("0 0");
            commandFactory.AddInputs("N 1");

            CommandSet commandSet = commandFactory.GetCommandSet();
            Robot      robot      = new Robot(commandSet, null);

            robot.ExecuteCommands();

            Assert.AreEqual(commandSet.StartPosition.X, robot.Position.X);
            Assert.AreEqual(commandSet.StartPosition.Y + 1, robot.Position.Y);
        }
Пример #15
0
        public void RunRobot_ZeroPlaceCleanReport()
        {
            CommandFactory commandFactory = new CommandFactory();

            commandFactory.AddInputs("0");
            commandFactory.AddInputs("0 0");

            IReport reporter = new TestReporter();

            CommandSet commandSet = commandFactory.GetCommandSet();
            Robot      robot      = new Robot(commandSet, reporter);

            robot.ExecuteCommands();
            string report = robot.ReportOutPut();

            Assert.AreEqual("=> Cleaned: 0", report);
        }
Пример #16
0
        public void RunRobot_SimpleCommandSetReportLocationCleaned()
        {
            CommandFactory commandFactory = new CommandFactory();

            commandFactory.AddInputs("1");
            commandFactory.AddInputs("20 20");
            commandFactory.AddInputs("N 1");

            CommandSet commandSet = commandFactory.GetCommandSet();
            IReport    reporter   = new SimpleReporter();

            Robot robot = new Robot(commandSet, reporter, new Location(-100000, -100000), new Location(100000, 100000));

            robot.ExecuteCommands();

            string report = robot.ReportOutPut();

            Assert.AreEqual("=> Cleaned: 1", report);
        }
Пример #17
0
        public void CommandFactory_4CommandSet()
        {
            CommandFactory commandFactory = new CommandFactory();

            commandFactory.AddInputs("4");
            commandFactory.AddInputs("10 22");
            commandFactory.AddInputs("E -1");
            commandFactory.AddInputs("E -1");
            commandFactory.AddInputs("E -1");
            commandFactory.AddInputs("E -1");

            CommandSet commandSet = commandFactory.GetCommandSet();

            Assert.AreEqual(4, commandSet.MoveCommands.Count);
        }
Пример #18
0
        public void RunRobot_CommandSetWithLocationMovements()
        {
            CommandFactory commandFactory = new CommandFactory();

            commandFactory.AddInputs("4");
            commandFactory.AddInputs("0 0");
            commandFactory.AddInputs("N 5");
            commandFactory.AddInputs("E 5");
            commandFactory.AddInputs("S 5");
            commandFactory.AddInputs("W 5");

            CommandSet commandSet = commandFactory.GetCommandSet();

            IReport reporter = new SimpleReporter();

            Robot robot = new Robot(commandSet, reporter, new Location(0, 0), new Location(5, 5));

            robot.ExecuteCommands();

            string report = robot.ReportOutPut();

            Assert.AreEqual("=> Cleaned: 20", report);
        }