Exemple #1
0
        public void Test_Execute_Method_ON_Environment_With_Input_X3Y4OrientationNorthAndControlInputSequenceLMLMLMLMMAnd_With_Input_X2Y4OrientationEastAndControlInputSequenceMMRMMRMRRM()
        {
            //This Test Can't be Executed due to the fact that Streams are multi-read, and can't be faked easily unless
            //the dynamic execution, is counting number of reads which could be possible, but not reliable, and therefore too complex to test.

            /*Entry For Robot 1:
             * 10 10
             * 1 2 N
             * MMRMMRMRRM
             */
            var plane = new Plane(10, 10, new Location {
                X = 0, Y = 0
            });
            var controller = new RobotController(plane);

            var robots = new List <Robot>();
            var inputOutputInstance = new StreamReadWriteInstance();

            inputOutputInstance.TextReader = new FakeStreamReader();
            inputOutputInstance.TextWriter = new FakeStreamWriter();

            var environmentSetup = new Mock <EnvironmentSetup>();

            environmentSetup.SetupProperty(mq => mq.Robots, robots);
            environmentSetup.SetupProperty(mq => mq.Controller, controller);
            environmentSetup.SetupProperty(mq => mq.Plane, plane);
            environmentSetup.SetupProperty(mq => mq.IInputOutputStream, inputOutputInstance);
            environmentSetup.Setup(mq => mq.ReadPlaneCordinates()).Returns("10 10");
            environmentSetup.Setup(mq => mq.ReadControlSequence()).Returns("LMLMLMLMM");
            environmentSetup.Setup(mq => mq.GetLocationArray(It.IsAny <string>())).Returns("3 4 N".Split());
            environmentSetup.Setup(mq => mq.Write1stLineOfOutput()).CallBase();
            environmentSetup.Setup(mq => mq.Write2ndLineOfOutput()).CallBase();
            environmentSetup.Setup(mq => mq.Write3rdLineOfOutput()).CallBase();
            environmentSetup.Setup(mq => mq.Write4thLineOfOutput()).CallBase();
            environmentSetup.Setup(mq => mq.ReadToAddAnotherRobot()).Returns("N");
            environmentSetup.Setup(mq => mq.MoveRobotSequence(It.IsAny <string>(), It.IsAny <RobotController>(), It.IsAny <Robot>())).CallBase();
            environmentSetup.Setup(mq => mq.Execute()).CallBase();

            environmentSetup.Object.Execute();

            Assert.AreEqual(robots[0].Location.X, 3);
            Assert.AreEqual(robots[0].Location.Y, 5);
            Assert.AreEqual(robots[0].Orientation, OrientationPosition.Orientation.N);

            var robots2 = new List <Robot>();

            environmentSetup.SetupProperty(mq => mq.Robots, robots2);
            environmentSetup.Setup(mq => mq.ReadPlaneCordinates()).Returns("7 6");
            environmentSetup.Setup(mq => mq.ReadControlSequence()).Returns("MMRMMRMRRM");
            environmentSetup.Setup(mq => mq.GetLocationArray(It.IsAny <string>())).Returns("2 4 E".Split());

            environmentSetup.Object.Execute();

            Assert.AreEqual(robots2[0].Location.X, 4);
            Assert.AreEqual(robots2[0].Location.Y, 2);
            Assert.AreEqual(robots2[0].Orientation, OrientationPosition.Orientation.E);
        }
Exemple #2
0
        public void Test_MoveForward_And_New_Positions_Are_Correct()
        {
            var plane = new Plane(10, 10, new Location {
                X = 0, Y = 0
            });
            var robot1 = new Robot(plane);

            robot1.Location = new Location {
                X = 1, Y = 2
            };
            robot1.Orientation = OrientationPosition.Orientation.N;
            _controller.MoveForward(robot1);
            Assert.AreEqual(robot1.Orientation, OrientationPosition.Orientation.N);
            Assert.AreEqual(robot1.Location.X, 1);
            Assert.AreEqual(robot1.Location.Y, 3);

            var robot2 = new Robot(plane);

            robot2.Location = new Location {
                X = 3, Y = 3
            };
            robot2.Orientation = OrientationPosition.Orientation.E;
            _controller.MoveForward(robot2);
            Assert.AreEqual(robot2.Orientation, OrientationPosition.Orientation.E);
            Assert.AreEqual(robot2.Location.X, 4);
            Assert.AreEqual(robot2.Location.Y, 3);

            var robot3 = new Robot(plane);

            robot3.Location = new Location {
                X = 1, Y = 2
            };
            robot3.Orientation = OrientationPosition.Orientation.W;
            _controller.MoveForward(robot3);
            Assert.AreEqual(robot3.Orientation, OrientationPosition.Orientation.W);
            Assert.AreEqual(robot3.Location.X, 0);
            Assert.AreEqual(robot3.Location.Y, 2);

            var robot4 = new Robot(plane);

            robot4.Location = new Location {
                X = 5, Y = 3
            };
            robot4.Orientation = OrientationPosition.Orientation.S;
            _controller.MoveForward(robot4);
            Assert.AreEqual(robot4.Orientation, OrientationPosition.Orientation.S);
            Assert.AreEqual(robot4.Location.X, 5);
            Assert.AreEqual(robot4.Location.Y, 2);
        }
Exemple #3
0
        public void SetUp()
        {
            var plane = new Plane(10, 10, new Location {
                X = 0, Y = 0
            });

            var robot1 = new Robot(plane);

            robot1.Location = new Location {
                X = 1, Y = 2
            };
            robot1.Orientation = OrientationPosition.Orientation.N;

            var robot2 = new Robot(plane);

            robot2.Location = new Location {
                X = 3, Y = 3
            };
            robot2.Orientation = OrientationPosition.Orientation.E;

            var robot3 = new Robot(plane);

            robot3.Location = new Location {
                X = 1, Y = 2
            };
            robot3.Orientation = OrientationPosition.Orientation.W;

            var robot4 = new Robot(plane);

            robot4.Location = new Location {
                X = 5, Y = 3
            };
            robot4.Orientation = OrientationPosition.Orientation.S;
            _controller        = new RobotController(plane);

            var Robots = new List <Robot>();

            Robots.Add(robot1);
            Robots.Add(robot2);
            Robots.Add(robot3);
            Robots.Add(robot4);

            _controller.Robots         = Robots.ToArray();
            _streamInstance            = new StreamReadWriteInstance();
            _streamInstance.TextReader = new FakeStreamReader();
            _streamInstance.TextWriter = new FakeStreamWriter();
            _environment = new EnvironmentSetup(_controller, plane, Robots, _streamInstance);
        }
Exemple #4
0
        public void Test_Turn_Left_When_At_Min_South_Position_And_Orientation_Is_South()
        {
            var plane = new Plane(10, 10, new Location {
                X = 0, Y = 0
            });
            var robot3 = new Robot(plane);

            robot3.Location = new Location {
                X = 4, Y = 0
            };
            robot3.Orientation = OrientationPosition.Orientation.S;
            _controller.TurnLeft(robot3);
            Assert.AreEqual(robot3.Orientation, OrientationPosition.Orientation.E);
            Assert.AreEqual(robot3.Location.X, 4);
            Assert.AreEqual(robot3.Location.Y, 0);
        }
Exemple #5
0
        public void Test_Not_CanMoveForward_When_At_Min_South_Position_And_Orientation_Is_South()
        {
            var plane = new Plane(10, 10, new Location {
                X = 0, Y = 0
            });
            var robot3 = new Robot(plane);

            robot3.Location = new Location {
                X = 4, Y = 0
            };
            robot3.Orientation = OrientationPosition.Orientation.S;
            _controller.MoveForward(robot3);
            Assert.AreEqual(robot3.Orientation, OrientationPosition.Orientation.S);
            Assert.AreEqual(robot3.Location.X, 4);
            Assert.AreEqual(robot3.Location.Y, 0);
        }
Exemple #6
0
        public void Test_Not_CanMoveForward_When_At_Max_East_Position_And_Orientation_Is_East()
        {
            var plane = new Plane(10, 10, new Location {
                X = 0, Y = 0
            });
            var robot3 = new Robot(plane);

            robot3.Location = new Location {
                X = 10, Y = 3
            };
            robot3.Orientation = OrientationPosition.Orientation.E;
            _controller.MoveForward(robot3);
            Assert.AreEqual(robot3.Orientation, OrientationPosition.Orientation.E);
            Assert.AreEqual(robot3.Location.X, 10);
            Assert.AreEqual(robot3.Location.Y, 3);
        }