예제 #1
0
        public static void Moving(int endPositionX, int endPositionY, RobotOrientation orientation)
        {
            var arenaMock = new Mock <IArena>();
            var robotMock = new Mock <IRobot>();

            int[] mockGetPositionReturn = { 4, 1 };
            arenaMock.Setup(x => x.CheckPosition(endPositionX, endPositionY)).Returns(true);
            robotMock.Setup(x => x.GetOrientation()).Returns(orientation);
            robotMock.Setup(x => x.GetPosition()).Returns(mockGetPositionReturn);
            string commandStream = "M";

            var robotActionExecutor = new RobotActionExecutor(robotMock.Object, commandStream, arenaMock.Object);

            robotActionExecutor.ExecuteAllActions();

            robotMock.Verify(x => x.SetPosition(endPositionX, endPositionY), Times.Once());
        }
예제 #2
0
        public static void TurningRight()
        {
            var arenaMock = new Mock <IArena>();
            var robotMock = new Mock <IRobot>();

            robotMock.Setup(x => x.GetOrientation()).Returns(RobotOrientation.South);
            string commandStream = "R";

            var robotActionExecutor = new RobotActionExecutor(robotMock.Object, commandStream, arenaMock.Object);

            robotActionExecutor.ExecuteAllActions();
            robotMock.Verify(x => x.SetOrientation(RobotOrientation.North), Times.Never());
            robotMock.Verify(x => x.SetOrientation(RobotOrientation.East), Times.Never());
            robotMock.Verify(x => x.SetOrientation(RobotOrientation.South), Times.Never());
            robotMock.Verify(x => x.SetOrientation(RobotOrientation.West), Times.Once());

            robotMock.Setup(x => x.GetOrientation()).Returns(RobotOrientation.West);

            robotActionExecutor.ExecuteAllActions();
            robotMock.Verify(x => x.SetOrientation(RobotOrientation.North), Times.Once());
            robotMock.Verify(x => x.SetOrientation(RobotOrientation.East), Times.Never());
            robotMock.Verify(x => x.SetOrientation(RobotOrientation.South), Times.Never());
            robotMock.Verify(x => x.SetOrientation(RobotOrientation.West), Times.Once());

            robotMock.Setup(x => x.GetOrientation()).Returns(RobotOrientation.North);

            robotActionExecutor.ExecuteAllActions();
            robotMock.Verify(x => x.SetOrientation(RobotOrientation.North), Times.Once());
            robotMock.Verify(x => x.SetOrientation(RobotOrientation.East), Times.Once());
            robotMock.Verify(x => x.SetOrientation(RobotOrientation.South), Times.Never());
            robotMock.Verify(x => x.SetOrientation(RobotOrientation.West), Times.Once());

            robotMock.Setup(x => x.GetOrientation()).Returns(RobotOrientation.North);

            robotActionExecutor.ExecuteAllActions();
            robotMock.Verify(x => x.SetOrientation(RobotOrientation.North), Times.Once());
            robotMock.Verify(x => x.SetOrientation(RobotOrientation.East), Times.Exactly(2));
            robotMock.Verify(x => x.SetOrientation(RobotOrientation.South), Times.Never());
            robotMock.Verify(x => x.SetOrientation(RobotOrientation.West), Times.Once());
        }
예제 #3
0
        public static void GivenExampleIntput_RetursCorrectOutput()
        {
            var inputData = new InputDataBuffer();

            inputData.SetSizeOfArena("5 5");
            inputData.AddInitialPositionAndOrientation("1 2 N");
            inputData.AddCommandStream("LMLMLMLMM");
            inputData.AddInitialPositionAndOrientation("3 3 E");
            inputData.AddCommandStream("MMRMMRMRRM");

            int nrOfRobots = inputData.NrOfRobots;

            var mineRovers = new MineRovers(nrOfRobots);

            var inputConsumer = new ConsumeInputPhaseExecutor(inputData, mineRovers);

            inputConsumer.Run();

            for (int robotIndex = 0; robotIndex < nrOfRobots; robotIndex++)
            {
                var robotActionExecutor = new RobotActionExecutor(mineRovers.Robots[robotIndex],
                                                                  mineRovers.CommandStreams[robotIndex],
                                                                  mineRovers.arena);
                robotActionExecutor.ExecuteAllActions();
            }

            string[] resultOutputs = new string[2];
            for (int robotIndex = 0; robotIndex < nrOfRobots; robotIndex++)
            {
                int[] finalPosition    = mineRovers.Robots[robotIndex].GetPosition();
                char  finalOrientation = mineRovers.Robots[robotIndex].GetOrientationAsChar();
                resultOutputs[robotIndex] = finalPosition[0] + " " + finalPosition[1] + " " + finalOrientation;
            }
            string[] expectedOutputs = { "1 3 N", "5 1 E" };
            for (int i = 0; i < nrOfRobots; i++)
            {
                Assert.Equal(expectedOutputs[i], resultOutputs[i]);
            }
        }