コード例 #1
0
        public void CreateCommandFactory_AddZeroInputCommands_InputsAreComplete()
        {
            //arrange
            CommandFactory commandFactory = new CommandFactory();

            //act
            commandFactory.AddInput("0");
            commandFactory.AddInput("10 22");

            //assert
            Assert.IsTrue(commandFactory.InputsAreComplete);
        }
コード例 #2
0
        public void CreateCommandFactory_TabSeparator_PositionIsCorrect()
        {
            //arrange
            CommandFactory commandFactory = new CommandFactory();

            //act
            commandFactory.AddInput("0");
            commandFactory.AddInput("10\t22");

            //assert
            Assert.AreEqual(10, commandFactory._commandSet.StartPosition.X);
            Assert.AreEqual(22, commandFactory._commandSet.StartPosition.Y);
        }
コード例 #3
0
        public void CreateCommandFactory_OneMovementCommandInput_CorrectNumberMovementCommandsAdded()
        {
            //arrange
            CommandFactory commandFactory = new CommandFactory();

            //act
            commandFactory.AddInput("3");
            commandFactory.AddInput("10 22");
            commandFactory.AddInput("E 2");

            //assert
            Assert.AreEqual(1, commandFactory._commandSet.MovementCommands.Count);
        }
コード例 #4
0
        public void CreateCommandFactory_TooManySteps_StepsShouldBe99999()
        {
            //arrange
            CommandFactory commandFactory = new CommandFactory();

            //act
            commandFactory.AddInput("1");
            commandFactory.AddInput("10 22");
            commandFactory.AddInput("E 200000");
            MovementCommand movementCommands = commandFactory._commandSet.MovementCommands[0];

            //assert
            Assert.AreEqual(99999, movementCommands.MoveSteps);
        }
コード例 #5
0
        public void CreateCommandFactory_TooFewSteps_StepsShouldBe1()
        {
            //arrange
            CommandFactory commandFactory = new CommandFactory();

            //act
            commandFactory.AddInput("1");
            commandFactory.AddInput("10 22");
            commandFactory.AddInput("E -3");
            MovementCommand movementCommand = commandFactory._commandSet.MovementCommands[0];

            //assert
            Assert.AreEqual(1, movementCommand.MoveSteps);
        }
コード例 #6
0
        public void CommandFactory_AddInCompleteInputs_NullCommandSet()
        {
            //arrange
            CommandFactory commandFactory = new CommandFactory();

            //act
            commandFactory.AddInput("5");
            commandFactory.AddInput("10 22");
            commandFactory.AddInput("E -3");
            CommandSet commandSet = commandFactory.GetCommandSet();

            //assert
            Assert.IsNull(commandSet);
        }
コード例 #7
0
        public void CreateRobot_RobotCreated()
        {
            //arrange
            CommandFactory commandFactory = new CommandFactory();
            commandFactory.AddInput("0");
            commandFactory.AddInput("0 0");
            CommandSet commandSet = commandFactory.GetCommandSet();

            //act
            Robot robot = new Robot(commandSet, null);

            //assert
            Assert.IsNotNull(robot);
        }
コード例 #8
0
        public void CommandFactory_AddInCompleteInputs_NullCommandSet()
        {
            //arrange
            CommandFactory commandFactory = new CommandFactory();

            //act
            commandFactory.AddInput("5");
            commandFactory.AddInput("10 22");
            commandFactory.AddInput("E -3");
            CommandSet commandSet = commandFactory.GetCommandSet();

            //assert
            Assert.IsNull(commandSet);
        }
コード例 #9
0
        public void CreateRobot_RobotCreated()
        {
            //arrange
            CommandFactory commandFactory = new CommandFactory();

            commandFactory.AddInput("0");
            commandFactory.AddInput("0 0");
            CommandSet commandSet = commandFactory.GetCommandSet();

            //act
            Robot robot = new Robot(commandSet, null);

            //assert
            Assert.IsNotNull(robot);
        }
コード例 #10
0
        public void CreateCommandFactory_AddThreeInputsCommands_InputsAreComplete()
        {
            //arrange
            CommandFactory commandFactory = new CommandFactory();

            //act
            commandFactory.AddInput("3");
            commandFactory.AddInput("10 22");
            commandFactory.AddInput("E 2");
            commandFactory.AddInput("N 1");
            commandFactory.AddInput("S 1");

            //assert
            Assert.IsTrue(commandFactory.InputsAreComplete);
        }
コード例 #11
0
        public void CreateCommandFactory_AddMinusInputCommands_InputsAreComplete()
        {
            //arrange
            CommandFactory commandFactory = new CommandFactory();

            //act
            commandFactory.AddInput("-3");
            commandFactory.AddInput("10 22");
            for (int i = 0; i < 10000; i++)
            {
                commandFactory.AddInput("E1");
            }

            //assert
            Assert.IsTrue(commandFactory.InputsAreComplete);
        }
コード例 #12
0
        public void CreateCommandFactory_AddNegativeInputsCommands_InputsAreComplete()
        {
            //arrange
            CommandFactory commandFactory = new CommandFactory();

            //act
            commandFactory.AddInput("-1");
            commandFactory.AddInput("10 22");
            for (int i = 0; i < 10000; i++)
            {
                commandFactory.AddInput("N1");
            }

            //assert
            Assert.IsTrue(commandFactory.InputsAreComplete);
        }
コード例 #13
0
        public void RunRobot_EmptyCommandSet_RobotPositionShouldNotChange()
        {
            //arrange
            CommandFactory commandFactory = new CommandFactory();
            commandFactory.AddInput("0");
            commandFactory.AddInput("0 0");
            CommandSet commandSet = commandFactory.GetCommandSet();
            Robot robot = new Robot(commandSet, null);

            //act
            robot.ExecuteCommands();

            //assert
            Assert.AreEqual(commandSet.StartPosition.X, robot.Position.X);
            Assert.AreEqual(commandSet.StartPosition.Y, robot.Position.Y);
        }
コード例 #14
0
        public void RunRobot_EmptyCommandSetNullReporter_ZeroPlaceReportGenerated()
        {
            //arrange
            CommandFactory commandFactory = new CommandFactory();
            commandFactory.AddInput("0");
            commandFactory.AddInput("0 0");
            CommandSet commandSet = commandFactory.GetCommandSet();
            Robot robot = new Robot(commandSet, null);

            //act
            robot.ExecuteCommands();
            string report = robot.PrintReport();

            //assert
            Assert.AreEqual("=> Cleaned: unknown", report);
        }
コード例 #15
0
        public void CreateCommandFactory_AddTwentyThousandInputCommands_InputsAreComplete()
        {
            //arrange
            CommandFactory commandFactory = new CommandFactory();

            //act
            commandFactory.AddInput("11000");
            commandFactory.AddInput("10 22");
            for (int i = 0; i < 20000; i++)
            {
                commandFactory.AddInput("E1");
            }

            //assert
            Assert.IsTrue(commandFactory.InputsAreComplete);
        }
コード例 #16
0
        public void RunRobot_EmptyCommandSet_RobotPositionShouldNotChange()
        {
            //arrange
            CommandFactory commandFactory = new CommandFactory();

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

            //act
            robot.ExecuteCommands();

            //assert
            Assert.AreEqual(commandSet.StartPosition.X, robot.Position.X);
            Assert.AreEqual(commandSet.StartPosition.Y, robot.Position.Y);
        }
コード例 #17
0
        public void RunRobot_EmptyCommandSetNullReporter_ZeroPlaceReportGenerated()
        {
            //arrange
            CommandFactory commandFactory = new CommandFactory();

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

            //act
            robot.ExecuteCommands();
            string report = robot.PrintReport();

            //assert
            Assert.AreEqual("=> Cleaned: unknown", report);
        }
コード例 #18
0
        public void RunRobot_SimpleCommandSet_RobotPositionYShouldChangeBy1()
        {
            //arrange
            CommandFactory commandFactory = new CommandFactory();

            commandFactory.AddInput("1");
            commandFactory.AddInput("0 0");
            commandFactory.AddInput("N 1");
            CommandSet commandSet = commandFactory.GetCommandSet();
            Robot      robot      = new Robot(commandSet, null);

            //act
            robot.ExecuteCommands();

            //assert
            Assert.AreEqual(commandSet.StartPosition.X, robot.Position.X);
            Assert.AreEqual(commandSet.StartPosition.Y + 1, robot.Position.Y);
        }
コード例 #19
0
        public void RunRobot_IllegalOutOfBoundsCommandSet_RobotPositionShouldRemainWithinBounds()
        {
            //arrange
            CommandFactory commandFactory = new CommandFactory();

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

            //act
            robot.ExecuteCommands();

            //assert
            Assert.AreEqual(commandSet.StartPosition.X, robot.Position.X);
            Assert.AreEqual(commandSet.StartPosition.Y, robot.Position.Y);
        }
コード例 #20
0
        public void RunRobot_SimplestCommandSetOneMove_RobotReports1LocationCleaned()
        {
            //arrange
            CommandFactory commandFactory = new CommandFactory();

            commandFactory.AddInput("1");
            commandFactory.AddInput("10 10");
            commandFactory.AddInput("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();

            //act
            string report = robot.PrintReport();

            //assert
            Assert.AreEqual("=> Cleaned: 1", report);
        }
コード例 #21
0
        public void CommandFactory_Add5Command_NotNullCommandSetHas5Commands()
        {
            //arrange
            CommandFactory commandFactory = new CommandFactory();

            //act
            commandFactory.AddInput("5");
            commandFactory.AddInput("10 22");
            commandFactory.AddInput("E -3");
            commandFactory.AddInput("E -3");
            commandFactory.AddInput("E -3");
            commandFactory.AddInput("E -3");
            commandFactory.AddInput("E -3");
            CommandSet commandSet = commandFactory.GetCommandSet();

            //assert
               Assert.AreEqual(5, commandSet.MovementCommands.Count);
        }
コード例 #22
0
        public void CommandFactory_Add5Command_NotNullCommandSetHas5Commands()
        {
            //arrange
            CommandFactory commandFactory = new CommandFactory();

            //act
            commandFactory.AddInput("5");
            commandFactory.AddInput("10 22");
            commandFactory.AddInput("E -3");
            commandFactory.AddInput("E -3");
            commandFactory.AddInput("E -3");
            commandFactory.AddInput("E -3");
            commandFactory.AddInput("E -3");
            CommandSet commandSet = commandFactory.GetCommandSet();

            //assert
            Assert.AreEqual(5, commandSet.MovementCommands.Count);
        }
コード例 #23
0
ファイル: Program.cs プロジェクト: shaneinsweden/RobotCleaner
        static void Main(string[] args)
        {
            //collect a set of inputs from standard in
            CommandFactory commandFactory = new CommandFactory();

            while (!commandFactory.InputsAreComplete)
            {
                Console.WriteLine(">");
                commandFactory.AddInput(Console.ReadLine());
            }
            Console.WriteLine("Input complete. Press any key to continue..");
            Console.ReadLine();

            //robot should execute cleaning commands
            SimpleReporter reporter = new SimpleReporter();
            Robot robbie = new Robot(commandFactory.GetCommandSet(), reporter, new Location(0,0), new Location(7,7));
            robbie.ExecuteCommands();

            //give output on the number of places cleaned
            Console.WriteLine(robbie.PrintReport());
        }
コード例 #24
0
        static void Main(string[] args)
        {
            //collect a set of inputs from standard in
            CommandFactory commandFactory = new CommandFactory();

            while (!commandFactory.InputsAreComplete)
            {
                Console.WriteLine(">");
                commandFactory.AddInput(Console.ReadLine());
            }
            Console.WriteLine("Input complete. Press any key to continue..");
            Console.ReadLine();

            //robot should execute cleaning commands
            SimpleReporter reporter = new SimpleReporter();
            Robot          robbie   = new Robot(commandFactory.GetCommandSet(), reporter, new Location(0, 0), new Location(7, 7));

            robbie.ExecuteCommands();

            //give output on the number of places cleaned
            Console.WriteLine(robbie.PrintReport());
        }
コード例 #25
0
        static void Main(string[] args)
        {
            //accept a set of input from standard in
            CommandFactory commandFactory = new CommandFactory();

            while (!commandFactory.InputsAreComplete)
            {
                Console.WriteLine(">");
                commandFactory.AddInput(Console.ReadLine());
            }
            Console.WriteLine("Input is Complete. Press any key to continue");
            Console.ReadLine();

            //robot cleaner should execute cleaning commands
            SimpleReporter repoter = new SimpleReporter();
            Robot          vacuum  = new Robot(commandFactory.GetCommandSet(), repoter, new Location(0, 0), new Location(7, 7));

            vacuum.ExecuteCommands();

            //robot cleaner should output the number of places cleaned
            Console.WriteLine(vacuum.PrintReport());
        }
コード例 #26
0
        public void RunRobot_BoxMoveCommandSet_NumberofLocationsIsCorrect()
        {
            //arrange
            CommandFactory commandFactory = new CommandFactory();
            commandFactory.AddInput("4");
            commandFactory.AddInput("0 0");
            commandFactory.AddInput("N 7");
            commandFactory.AddInput("E 7");
            commandFactory.AddInput("S 7");
            commandFactory.AddInput("W 7");
            CommandSet commandSet = commandFactory.GetCommandSet();
            IReport reporter = new SimpleReporter();
            Robot robot = new Robot(commandSet, reporter, new Location(0, 0), new Location(7, 7));

            //act
            robot.ExecuteCommands();
            string report = robot.PrintReport();

            //assert
            Assert.AreEqual("=> Cleaned: 28", report);
        }
コード例 #27
0
        public void RunRobot_BoxMoveCommandSet_NumberofLocationsIsCorrect()
        {
            //arrange
            CommandFactory commandFactory = new CommandFactory();

            commandFactory.AddInput("4");
            commandFactory.AddInput("0 0");
            commandFactory.AddInput("N 7");
            commandFactory.AddInput("E 7");
            commandFactory.AddInput("S 7");
            commandFactory.AddInput("W 7");
            CommandSet commandSet = commandFactory.GetCommandSet();
            IReport    reporter   = new SimpleReporter();
            Robot      robot      = new Robot(commandSet, reporter, new Location(0, 0), new Location(7, 7));

            //act
            robot.ExecuteCommands();
            string report = robot.PrintReport();

            //assert
            Assert.AreEqual("=> Cleaned: 28", report);
        }
コード例 #28
0
        public void RunRobot_IllegalOutOfBoundsCommandSet_RobotPositionShouldRemainWithinBounds()
        {
            //arrange
            CommandFactory commandFactory = new CommandFactory();
            commandFactory.AddInput("1");
            commandFactory.AddInput("100000 100000");
            commandFactory.AddInput("N 1");
            CommandSet commandSet = commandFactory.GetCommandSet();
            Robot robot = new Robot(commandSet, null, null, new Location(100000, 100000) );

            //act
            robot.ExecuteCommands();

            //assert
            Assert.AreEqual(commandSet.StartPosition.X, robot.Position.X);
            Assert.AreEqual(commandSet.StartPosition.Y, robot.Position.Y);
        }
コード例 #29
0
        public void RunRobot_SimpleCommandSet_RobotPositionYShouldChangeBy1()
        {
            //arrange
            CommandFactory commandFactory = new CommandFactory();
            commandFactory.AddInput("1");
            commandFactory.AddInput("0 0");
            commandFactory.AddInput("N 1");
            CommandSet commandSet = commandFactory.GetCommandSet();
            Robot robot = new Robot(commandSet, null);

            //act
            robot.ExecuteCommands();

            //assert
            Assert.AreEqual(commandSet.StartPosition.X, robot.Position.X);
            Assert.AreEqual(commandSet.StartPosition.Y + 1, robot.Position.Y);
        }
コード例 #30
0
        public void RunRobot_SimplestCommandSetOneMove_RobotReports1LocationCleaned()
        {
            //arrange
            CommandFactory commandFactory = new CommandFactory();
            commandFactory.AddInput("1");
            commandFactory.AddInput("10 10");
            commandFactory.AddInput("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();

            //act
            string report = robot.PrintReport();

            //assert
            Assert.AreEqual("=> Cleaned: 1", report);
        }
コード例 #31
0
        public void CreateCommandFactory_OneMovementCommandInput_CorrectNumberMovementCommandsAdded()
        {
            //arrange
            CommandFactory commandFactory = new CommandFactory();

            //act
            commandFactory.AddInput("3");
            commandFactory.AddInput("10 22");
            commandFactory.AddInput("E 2");

            //assert
            Assert.AreEqual(1,commandFactory._commandSet.MovementCommands.Count);
        }
コード例 #32
0
        public void CreateCommandFactory_TabSeparator_PositionIsCorrect()
        {
            //arrange
            CommandFactory commandFactory = new CommandFactory();

            //act
            commandFactory.AddInput("0");
            commandFactory.AddInput("10\t22");

            //assert
            Assert.AreEqual(10, commandFactory._commandSet.StartPosition.X);
            Assert.AreEqual(22, commandFactory._commandSet.StartPosition.Y);
        }
コード例 #33
0
        public void CreateCommandFactory_AddZeroInputCommands_InputsAreComplete()
        {
            //arrange
            CommandFactory commandFactory = new CommandFactory();

            //act
            commandFactory.AddInput("0");
            commandFactory.AddInput("10 22");

            //assert
            Assert.IsTrue(commandFactory.InputsAreComplete);
        }
コード例 #34
0
        public void CreateCommandFactory_TooManySteps_StepsShouldBe99999()
        {
            //arrange
            CommandFactory commandFactory = new CommandFactory();

            //act
            commandFactory.AddInput("1");
            commandFactory.AddInput("10 22");
            commandFactory.AddInput("E 200000");
            MovementCommand movementCommand = commandFactory._commandSet.MovementCommands[0];

            //assert
            Assert.AreEqual(99999, movementCommand.MoveSteps);
        }