public void ShouldReportFellOffOnLanding()
        {
            IPlateau p   = new MarsPlateau(new Coordinates(1, 1));
            IRover   one = new MarsRover.MarsRover(1, new Coordinates(1, 2), Direction.N,
                                                   new List <Command>
            {
                Command.L, Command.L, Command.M, Command.L, Command.M, Command.L, Command.M, Command.L, Command.M,
                Command.M
            });

            var testReporter = new TestReporter();

            new Houston(p, new List <IRover> {
                one
            }).Control(testReporter);

            Assert.AreEqual(new List <string>
            {
                $"Rover {one.Id} landed at [{one.Position.X}, {one.Position.Y}] outside the plateau"
            },
                            testReporter.Errors);

            Assert.AreEqual(new Dictionary <IRover, Status>
            {
                { one, Status.FellOff }
            }, testReporter.Dictionary);
            Assert.AreEqual(Direction.N, one.Direction);
            Assert.AreEqual(new Coordinates(1, 2), one.Position);
        }
 static void Main(string[] args)
 {
     if (args.Length == 0 || String.IsNullOrEmpty(args[0]) || args[0] == "/?" || args[0] == "?")
     {
         Console.WriteLine("\t\tA command sequence should be entered.\n" +
                           "\t\tThe allowable characters are R, L, F, B.\n" +
                           "\t\tThe program prints the final coordinates of the rover,\n" +
                           "\t\tthe index of the last executed command and then a word\n" +
                           "\t\t(Yes or No) specifying whether all the commands have\n" +
                           "\t\tbeen executed successfully.\n");
     }
     else
     {
         try
         {
             int  x;
             int  y;
             int  lastSuccessIndex;
             bool success = MarsRover.Run(args[0], out x, out y, out lastSuccessIndex);
             Console.WriteLine("{0} {1} {2} {3}", x, y, lastSuccessIndex, success ? "Yes" : "No");
         }
         catch (InvalidCommandsException ex)
         {
             Console.WriteLine(ex.Message);
         }
     }
 }
        public void ShouldRunASimulation()
        {
            IPlateau p   = new MarsPlateau(new Coordinates(5, 5));
            IRover   one = new MarsRover.MarsRover(1, new Coordinates(1, 2), Direction.N,
                                                   new List <Command>
            {
                Command.L, Command.M, Command.L, Command.M, Command.L, Command.M, Command.L, Command.M, Command.M
            });
            IRover two = new MarsRover.MarsRover(2, new Coordinates(3, 3), Direction.E,
                                                 new List <Command>
            {
                Command.M, Command.M, Command.R, Command.M, Command.M, Command.R, Command.M, Command.R, Command.R,
                Command.M
            });

            var testReporter = new TestReporter();

            new Houston(p, new List <IRover> {
                one, two
            }).Control(testReporter);

            Assert.IsEmpty(testReporter.Errors);
            var expected = new Dictionary <IRover, Status>()
            {
                { one, Status.Ok },
                { two, Status.Ok }
            };

            Assert.AreEqual(expected, testReporter.Dictionary);
            Assert.AreEqual(Direction.N, one.Direction);
            Assert.AreEqual(new Coordinates(1, 3), one.Position);
            Assert.AreEqual(Direction.E, two.Direction);
            Assert.AreEqual(new Coordinates(5, 1), two.Position);
        }
        public void AddRover(ICoordinates coordinates, string direction)
        {
            var initialPosition = new Position(Plateau, coordinates);

            CurrentRover = new MarsRover(initialPosition, direction);
            Rovers.Add(CurrentRover);
        }
Beispiel #5
0
        public void Setup()
        {
            _planetMock = new Mock <IPlanet>();
            _planetMock.Setup(x => x.GetSizeX()).Returns(10);
            _planetMock.Setup(x => x.GetSizeY()).Returns(10);

            _rover = new MarsRover.MarsRover(_planetMock.Object);
        }
Beispiel #6
0
        public void MSIsSetInTheCorrectPositionAndOrientation()
        {
            _rover = new MarsRover.MarsRover(3, 4, OrientationDirection.South);

            Assert.AreEqual(_rover.PositionX, 3);
            Assert.AreEqual(_rover.PositionY, 4);
            Assert.AreEqual(_rover.Orientation, OrientationDirection.South);
        }
Beispiel #7
0
        public void SetPlateauCorrectCheck()
        {
            var rover = new MarsRover.MarsRover();

            rover._Navigation.SetPlateau("1 2");
            var plateau = rover._Navigation.GetPlateau();

            Assert.IsTrue(plateau.Width == 1 && plateau.Height == 2);
        }
Beispiel #8
0
        public void SetPositionCorrectCheck()
        {
            var rover = new MarsRover.MarsRover();

            rover._Navigation.SetPlateau("5 5");
            rover._Navigation.SetPosition("1 2 W");
            var position = rover._Navigation.GetPosition();

            Assert.IsTrue(position.X == 1 && position.Y == 2 && position._Direction == Direction.West);
        }
Beispiel #9
0
        static void Main(string[] args)
        {
            var marsRover = new MarsRover(5, 5);

            marsRover.AddRover(1, 2, 'N');
            marsRover.SendCommand("LMLMLMLMM");
            marsRover.AddRover(3, 3, 'E');
            marsRover.SendCommand("MMRMMRMRRM");
            marsRover.GetPositions();
            Console.ReadLine();
        }
Beispiel #10
0
        public void Navigation1Check()
        {
            var marsRover = new MarsRover.MarsRover();

            marsRover._Navigation.SetPlateau("5 5");
            marsRover._Navigation.SetPosition("1 2 N");
            marsRover._Navigation.SetInput("LMLMLMLMM");
            marsRover._Navigation.Navigate();
            var position = marsRover._Navigation.GetPosition();

            Assert.IsTrue(position.X == 1 && position.Y == 3 && position._Direction == Direction.North);
        }
Beispiel #11
0
        public void Navigation2Check()
        {
            var marsRover = new MarsRover.MarsRover();

            marsRover._Navigation.SetPlateau("5 5");
            marsRover._Navigation.SetPosition("3 3 E");
            marsRover._Navigation.SetInput("MMRMMRMRRM");
            marsRover._Navigation.Navigate();
            var position = marsRover._Navigation.GetPosition();

            Assert.IsTrue(position.X == 5 && position.Y == 1 && position._Direction == Direction.East);
        }
Beispiel #12
0
 public void SetPlateauBadFormatCheck()
 {
     try
     {
         var rover = new MarsRover.MarsRover();
         rover._Navigation.SetPlateau("a 2");
     }
     catch (BadFormatException)
     {
         Assert.Pass();
     }
 }
Beispiel #13
0
 public void SetPositionOutOfPlateauCheck()
 {
     try
     {
         var rover = new MarsRover.MarsRover();
         rover._Navigation.SetPlateau("1 1");
         rover._Navigation.SetPosition("2 2 W");
     }
     catch (OutOfPlateauException)
     {
         Assert.Pass();
     }
 }
Beispiel #14
0
        static void Main(string[] args)
        {
            string input = "5 5\n1 2 N\nLMLMLMLMM\n3 3 E\nMMRMMRMRRM";

            input = args.Length != 0 ? args[0] : input;


            DeviceControl(input);
            foreach (var assignment in RoversCommands)
            {
                var marsRover = new MarsRover(assignment);
                marsRover.Initialize();
                marsRover.Navigate();
                Console.WriteLine(marsRover.FinalPosition);
            }
            Console.ReadLine();
        }
Beispiel #15
0
        // Please see the MarsRoverTests.TestRunCommands_ReturnsCorrectPositionAndDirection
        // for various test inputs and their expected result.
        static void Main(string[] args)
        {
            string stringCommands = string.Join(string.Empty, args);

            if (string.IsNullOrEmpty(stringCommands))
            {
                Console.Write("Enter Commands for Rover: ");
                stringCommands = Console.ReadLine();
            }
            IDirection  direction        = new North();
            Coordinates startCoordinates = new Coordinates(0, 0);
            IGrid       grid             = new Grid(startCoordinates, new Coordinates(5, 5));
            IRover      marsRover        = new MarsRover(direction, startCoordinates, grid);

            marsRover.RunCommands(stringCommands);
            Console.WriteLine(
                "Position of Rover after executing the commands : {0}", marsRover);
            Console.ReadLine();
        }
Beispiel #16
0
        static void Main(string[] args)
        {
            kernel = new StandardKernel(new RegisterNinjectModule());

            var marsRover = new MarsRover();

            marsRover._Navigation.SetPlateau("5 5");

            marsRover._Navigation.SetPosition("1 2 N");
            marsRover._Navigation.SetInput("LMLMLMLMM");
            marsRover._Navigation.Navigate();
            Console.WriteLine(marsRover._Navigation.GetPosition().ToString());


            marsRover._Navigation.SetPosition("3 3 E");
            marsRover._Navigation.SetInput("MMRMMRMRRM");
            marsRover._Navigation.Navigate();
            Console.WriteLine(marsRover._Navigation.GetPosition().ToString());

            Console.ReadKey();
        }
        public void ShouldRunASimulationWithLandingOnly()
        {
            IPlateau p   = new MarsPlateau(new Coordinates(5, 5));
            IRover   one = new MarsRover.MarsRover(1, new Coordinates(1, 2), Direction.N,
                                                   new List <Command>());

            var testReporter = new TestReporter();

            new Houston(p, new List <IRover> {
                one
            }).Control(testReporter);

            Assert.IsEmpty(testReporter.Errors);
            var expected = new Dictionary <IRover, Status>()
            {
                { one, Status.Ok },
            };

            Assert.AreEqual(expected, testReporter.Dictionary);
            Assert.AreEqual(Direction.N, one.Direction);
            Assert.AreEqual(new Coordinates(1, 2), one.Position);
        }
Beispiel #18
0
        public override void Execute(MarsRover rover, IPlanet planet)
        {
            switch (rover.Orientation)
            {
            case OrientationDirection.North:
                rover.PositionY = (rover.PositionY + 1) % planet.GetSizeY();
                break;

            case OrientationDirection.South:
                if (rover.PositionY == 0)
                {
                    rover.PositionY = planet.GetSizeY() - 1;
                }
                else
                {
                    rover.PositionY--;
                }
                break;

            case OrientationDirection.East:
                rover.PositionX = (rover.PositionX + 1) % planet.GetSizeX();
                break;

            case OrientationDirection.West:
                if (rover.PositionX == 0)
                {
                    rover.PositionX = planet.GetSizeX() - 1;
                }
                else
                {
                    rover.PositionX--;
                }
                break;

            default:
                throw new InvalidEnumArgumentException();
            }
        }
Beispiel #19
0
        static void Main(string[] args)
        {
            Plateau   plateau = new Plateau(5, 5);
            MarsRover rover   = new MarsRover(1, 2, "N", plateau);

            string commands = "LMLMLMLMM";

            foreach (var command in commands)
            {
                if (command == 'M')
                {
                    rover.move();
                }
                else
                {
                    rover.turn(command.ToString());
                }

                Console.WriteLine(rover);
            }

            Console.ReadLine();
        }
        public void ShouldReportCrashWhileMoving()
        {
            IPlateau p   = new MarsPlateau(new Coordinates(5, 5));
            IRover   one = new MarsRover.MarsRover(1, new Coordinates(1, 2), Direction.N,
                                                   new List <Command>
            {
                Command.L, Command.M, Command.L, Command.M, Command.L, Command.M, Command.L, Command.M, Command.M
            });
            IRover two = new MarsRover.MarsRover(2, new Coordinates(0, 3), Direction.E,
                                                 new List <Command>
            {
                Command.M, Command.M, Command.R, Command.M, Command.M, Command.R, Command.M, Command.R, Command.R,
                Command.M
            });

            var testReporter = new TestReporter();

            new Houston(p, new List <IRover> {
                one, two
            }).Control(testReporter);

            Assert.AreEqual(new List <string>
            {
                $"Rover {two.Id} crashed into another Rover {one.Id} at [{one.Position.X}, {one.Position.Y}]"
            },
                            testReporter.Errors);

            Assert.AreEqual(new Dictionary <IRover, Status>
            {
                { one, Status.Ok },
                { two, Status.Crashed }
            }, testReporter.Dictionary);
            Assert.AreEqual(Direction.N, one.Direction);
            Assert.AreEqual(new Coordinates(1, 3), one.Position);
            Assert.AreEqual(Direction.E, two.Direction);
            Assert.AreEqual(new Coordinates(1, 3), two.Position);
        }
Beispiel #21
0
        public override void Execute(MarsRover rover, IPlanet planet)
        {
            switch (rover.Orientation)
            {
            case OrientationDirection.North:
                rover.Orientation = OrientationDirection.West;
                break;

            case OrientationDirection.South:
                rover.Orientation = OrientationDirection.East;
                break;

            case OrientationDirection.East:
                rover.Orientation = OrientationDirection.North;
                break;

            case OrientationDirection.West:
                rover.Orientation = OrientationDirection.South;
                break;

            default:
                throw new InvalidEnumArgumentException();
            }
        }
Beispiel #22
0
 public void initial()
 {
     marsRover = new MarsRover.MarsRover(10, 10, DIRECTION.EAST);
     marsRover.setRange(100, 100); //设定了火星车的活动范围
 }