コード例 #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Application Starts...");
            Console.WriteLine("Ready For Input");
            Console.WriteLine("Example Input:");
            Console.WriteLine("4 (commands)");
            Console.WriteLine("10 10 (start position)");
            Console.WriteLine("W 10 (west 10)");
            Console.WriteLine("N 4 (north 4)");
            Console.WriteLine("E 14 (east 14)");
            Console.WriteLine("5 20 (south 20)");

            RobotsCommands commandFactory = new RobotsCommands();

            while (!commandFactory.InputsCompleated)
            {
                // Adding Robot Inputs
                commandFactory.AddInput(Console.ReadLine());
            }

            Console.WriteLine("Robot Instructions are complete.");
            Console.ReadLine();

            // robot executing input commands
            SimpleReporter jobReporter  = new SimpleReporter();
            CleanerRobot   cleanerRobot = new CleanerRobot(commandFactory.GetCommandSet(), jobReporter, new Location(0, 0), new Location(12, 12));

            cleanerRobot.Run();

            //give output on the number of places cleaned
            Console.WriteLine(cleanerRobot.PrintReport());
        }
コード例 #2
0
        public void RobotCleanerReport()
        {
            RobotsCommands сommandFactory = new RobotsCommands();

            сommandFactory.AddInput("4");
            сommandFactory.AddInput("0 0");
            сommandFactory.AddInput("N 10");
            сommandFactory.AddInput("E 10");
            сommandFactory.AddInput("S 10");
            сommandFactory.AddInput("W 10");

            Commands commandSet = сommandFactory.GetCommandSet();

            // creating the report
            IReport testReporter = new SimpleReporter();

            // creating the robot
            CleanerRobot cleanerRobot = new CleanerRobot(commandSet, testReporter);

            // moving the robot
            cleanerRobot.Run();

            // gethering the report
            string whereHaveYouBeen = cleanerRobot.PrintReport();

            // Assert.AreEqual("=> Cleaned: 0", whereHaveYouBeen);
            // We are doing complete loop
            // And Robot comming back to 0 0

            Assert.AreEqual("=> Cleaned: 40", whereHaveYouBeen);
            Assert.AreEqual(commandSet.startPosition.x, cleanerRobot.location.x);
            Assert.AreEqual(commandSet.startPosition.y, cleanerRobot.location.y);
        }
コード例 #3
0
        public void AddingInputsTest4()
        {
            RobotsCommands сommandFactory = new RobotsCommands();

            сommandFactory.AddInput("0");
            сommandFactory.AddInput("40 66");

            Assert.IsTrue(сommandFactory.InputsCompleated);
        }
        public void MovementTest()
        {
            RobotsCommands сommandFactory = new RobotsCommands();

            сommandFactory.AddInput("3");
            сommandFactory.AddInput("10 22");
            сommandFactory.AddInput("E 100");

            Assert.AreEqual(1, сommandFactory.commandSet.commandToMove.Count);
        }
        public void SetReallyBad2Position()
        {
            RobotsCommands сommandFactory = new RobotsCommands();

            сommandFactory.AddInput("333");
            сommandFactory.AddInput("101                 \n                     202");

            Assert.AreEqual(101, сommandFactory.commandSet.startPosition.x);
            Assert.AreEqual(202, сommandFactory.commandSet.startPosition.y);
        }
コード例 #6
0
        public void AddingInputsTest2()
        {
            RobotsCommands сommandFactory = new RobotsCommands();

            сommandFactory.AddInput("2");
            сommandFactory.AddInput("100 200");
            сommandFactory.AddInput("W 2");
            сommandFactory.AddInput("N 1");

            Assert.IsTrue(сommandFactory.InputsCompleated);
            // Assert.Pass("AddingInputsTest 2 Completed with {0} Inputs:", сommandFactory.totalNumberOFCommands.ToString(), сommandFactory.InputsCompleated);
        }
コード例 #7
0
        public void IncompleteCommandTest()
        {
            RobotsCommands сommandFactory = new RobotsCommands();

            сommandFactory.AddInput("3");
            сommandFactory.AddInput("5 25");
            сommandFactory.AddInput("W 2");

            Commands сommandSet = сommandFactory.GetCommandSet();

            Assert.IsNull(сommandSet);
        }
        public void MovementMaxTest()
        {
            RobotsCommands сommandFactory = new RobotsCommands();

            сommandFactory.AddInput("1");
            сommandFactory.AddInput("100 200");
            сommandFactory.AddInput("N 50000");

            CommandToMove cmmandToMove = сommandFactory.commandSet.commandToMove[0];

            Assert.AreEqual(10000, cmmandToMove.numberOfSteps);
        }
        public void SetGoodPosition()
        {
            RobotsCommands сommandFactory = new RobotsCommands();

            сommandFactory.AddInput("0");
            сommandFactory.AddInput("101 202");

            Location location = new Location(400, 600);

            Assert.AreEqual(101, сommandFactory.commandSet.startPosition.x);
            Assert.AreEqual(202, сommandFactory.commandSet.startPosition.y);
        }
コード例 #10
0
        public void CreateRobotTest()
        {
            RobotsCommands сommandFactory = new RobotsCommands();

            сommandFactory.AddInput("0");
            сommandFactory.AddInput("0 0");

            Commands commandSet = сommandFactory.GetCommandSet();

            CleanerRobot cleanerRobot = new CleanerRobot(commandSet, null);

            Assert.IsTrue(сommandFactory.InputsCompleated);
        }
コード例 #11
0
        public void AddingInputsTest6()
        {
            RobotsCommands сommandFactory = new RobotsCommands();

            сommandFactory.AddInput("10001");
            сommandFactory.AddInput("1111 222");

            for (int cnt = 0; cnt < 30000; cnt++)
            {
                сommandFactory.AddInput(cnt.ToString());
            }

            Assert.IsTrue(сommandFactory.InputsCompleated);
        }
コード例 #12
0
        public void AddingInputsTest1()
        {
            // Example input:
            // 2
            // 10 22
            // E 2
            // N 1

            RobotsCommands сommandFactory = new RobotsCommands();

            сommandFactory.AddInput("2");
            сommandFactory.AddInput("10 22");
            сommandFactory.AddInput("E 2");
            сommandFactory.AddInput("N 1");

            Assert.IsTrue(сommandFactory.InputsCompleated);
            // Assert.Pass("AddingInputsTest 1 Completed with {0} Inputs:", сommandFactory.totalNumberOFCommands.ToString(), сommandFactory.InputsCompleated);
        }
コード例 #13
0
        public void CompleteCommandTest()
        {
            RobotsCommands сommandFactory = new RobotsCommands();

            сommandFactory.AddInput("7");
            сommandFactory.AddInput("10 20");
            сommandFactory.AddInput("S 10");
            сommandFactory.AddInput("S 10");
            сommandFactory.AddInput("S 10");
            сommandFactory.AddInput("S 10");
            сommandFactory.AddInput("S 10");
            сommandFactory.AddInput("S 10");
            сommandFactory.AddInput("S 10");

            Commands сommandSet = сommandFactory.GetCommandSet();

            Assert.IsNotNull(сommandSet);
        }
コード例 #14
0
        public void MovingRobotTest()
        {
            RobotsCommands сommandFactory = new RobotsCommands();

            сommandFactory.AddInput("4");
            сommandFactory.AddInput("0 0");
            сommandFactory.AddInput("N 10");
            сommandFactory.AddInput("E 10");
            сommandFactory.AddInput("S 10");
            сommandFactory.AddInput("W 10");

            Commands commandSet = сommandFactory.GetCommandSet();

            CleanerRobot cleanerRobot = new CleanerRobot(commandSet, null);

            // moving the robot
            cleanerRobot.Run();

            Assert.AreEqual(commandSet.startPosition.x, cleanerRobot.location.x);
            Assert.AreEqual(commandSet.startPosition.y, cleanerRobot.location.y);
        }
コード例 #15
0
        public void CheckIfCommandSetIsCorrectTest()
        {
            RobotsCommands сommandFactory = new RobotsCommands();

            сommandFactory.AddInput("11");
            сommandFactory.AddInput("10 20");
            сommandFactory.AddInput("S 10");
            сommandFactory.AddInput("S 10");
            сommandFactory.AddInput("S 10");
            сommandFactory.AddInput("S 10");
            сommandFactory.AddInput("S 10");
            сommandFactory.AddInput("S 10");
            сommandFactory.AddInput("S 10");
            сommandFactory.AddInput("S 10");
            сommandFactory.AddInput("S 10");
            сommandFactory.AddInput("S 10");
            сommandFactory.AddInput("S 10");

            Commands сommandSet = сommandFactory.GetCommandSet();

            Assert.AreEqual(11, сommandSet.commandToMove.Count);
        }