Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        public void All_Robotic_rover_move_inmars_plateau()
        {
            IMatrix   plateau            = new MarsPlateau(5, 5);
            IPosition positionfirst      = new RoboticPosition(1, 2);
            IPosition positionsecond     = new RoboticPosition(3, 3);
            var       roboticRoverFirst  = new RoboticRover(positionfirst, Direction.N, plateau);
            var       roboticRoverSecond = new RoboticRover(positionsecond, Direction.E, plateau);

            roboticRoverFirst.Move("LMLMLMLMM");

            var control = new MovementControl <IRover, IMatrix>(roboticRoverFirst, plateau).RoverInMatrix();

            Assert.IsTrue(control);
            Assert.IsTrue(roboticRoverFirst.Position.X == 1, "First Position X is not true!");
            Assert.IsTrue(roboticRoverFirst.Position.Y == 3, "First Position Y is not true!");
            Assert.IsTrue(roboticRoverFirst.Direction == Direction.N, "First Direction is wrong!");

            roboticRoverSecond.Move("MMRMMRMRRM");
            control = new MovementControl <IRover, IMatrix>(roboticRoverSecond, plateau).RoverInMatrix();

            Assert.IsTrue(control);
            Assert.IsTrue(roboticRoverSecond.Position.X == 5, "Second Position X is not true!");
            Assert.IsTrue(roboticRoverSecond.Position.Y == 1, "Second Position Y is not true!");
            Assert.IsTrue(roboticRoverSecond.Direction == Direction.E, "Second Direction is wrong!");
        }
Esempio n. 4
0
        public void PlateauTest()
        {
            MarsPlateau marsPlateau = new MarsPlateau(4, 5);

            Assert.NotNull(marsPlateau);
            Assert.Equal("4", marsPlateau.Width.ToString());
            Assert.Equal("5", marsPlateau.Height.ToString());
        }
Esempio n. 5
0
        public void ShouldRunASimulationWithNoRover()
        {
            IPlateau p = new MarsPlateau(new Coordinates(5, 5));

            var testReporter = new TestReporter();

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

            Assert.IsEmpty(testReporter.Errors);
            Assert.IsEmpty(testReporter.Dictionary);
        }
        public void LandOnInvalidPosition(int width, int height, CardinalDirections direction)
        {
            var marsPlateau = new MarsPlateau();
            var spaceProbe  = new SpaceProbe();

            marsPlateau.SetSize(1, 1);

            spaceProbe.Land(marsPlateau, new Position(width, height), direction);

            Assert.Null(spaceProbe.Position);
        }
        public void MarsPlateau_Shoud_Set_Initial_Coords()
        {
            // Arrange
            var marsPlateau = new MarsPlateau();

            // Act
            marsPlateau.SetInitialCoords(new Coordinate().SetCoords(5, 10));

            // Assert
            Assert.Equal(5, marsPlateau.Coordinate.X);
            Assert.Equal(10, marsPlateau.Coordinate.Y);
        }
        public void MarsPlateau_Shoud_Set_Initial_Coords_ByCommand()
        {
            // Arrange
            var marsPlateau = new MarsPlateau();

            // Act
            marsPlateau.SetInitialCoords("5 10");

            // Assert
            Assert.Equal(5, marsPlateau.Coordinate.X);
            Assert.Equal(10, marsPlateau.Coordinate.Y);
        }
        public void LandOnValidPosition(int width, int height, CardinalDirections direction)
        {
            var marsPlateau = new MarsPlateau();
            var spaceProbe  = new SpaceProbe();

            marsPlateau.SetSize(10, 10);

            spaceProbe.Land(marsPlateau, new Position(width, height), direction);

            Assert.Equal(spaceProbe.Position.XAxis, width);
            Assert.Equal(spaceProbe.Position.YAxis, height);
        }
        public void MarsPlateau_Shoud_GivenCoordinates_ShoulBe_Inside_Plateau()
        {
            // Arrange
            var marsPlateau = new MarsPlateau();

            marsPlateau.SetInitialCoords("5 5");

            // Act
            var isInside = marsPlateau.IsInside(new Coordinate().SetCoords(3, 4));

            // Assert
            Assert.Equal(isInside, true);
        }
Esempio n. 11
0
        public void Second_Robotic_rover_move_inmars_plateau()
        {
            IMatrix   plateau  = new MarsPlateau(5, 5);
            IPosition position = new RoboticPosition(3, 3);

            var roboticRover = new RoboticRover(position, Direction.E, plateau);

            roboticRover.Move("MMRMMRMRRM");
            var control = new MovementControl <IRover, IMatrix>(roboticRover, plateau).RoverInMatrix();

            Assert.IsTrue(control);
            Assert.IsTrue(roboticRover.Position.X == 5, "Position X is not true");
            Assert.IsTrue(roboticRover.Position.Y == 1, "Position Y is not true");
            Assert.IsTrue(roboticRover.Direction == Direction.E, "Direction is not true");
        }
Esempio n. 12
0
 /// <summary>
 /// This method creates the rectangular plateau based on the coordinate provided.
 /// The corner provided is expected to be the northeast corner of the plateau.
 /// </summary>
 /// <param name="northEastCornerCoordinate"></param>
 /// <exception cref="System.ArgumentOutOfRangeException">Thrown if X or Y coordinate provided is less than 0.</exception>
 public void CreatePlateau(MarsCoordinate northEastCornerCoordinate)
 {
     if (northEastCornerCoordinate == null)
     {
         throw new ArgumentNullException(nameof(northEastCornerCoordinate));
     }
     if (northEastCornerCoordinate.X < 0)
     {
         throw new ArgumentOutOfRangeException("The X coordinate for the northeast corner cannot be less than 0.");
     }
     if (northEastCornerCoordinate.Y < 0)
     {
         throw new ArgumentOutOfRangeException("The Y coordinate for the northeast corner cannot be less than 0.");
     }
     plateau = new MarsPlateau(northEastCornerCoordinate.X, northEastCornerCoordinate.Y);
 }
        public void MoveForward(CardinalDirections direction, int expectedXAxis, int expectedYAxis)
        {
            var spaceProbe = new SpaceProbe();

            spaceProbe.Position  = new Position(2, 2);
            spaceProbe.Direction = direction;

            var marsPlateau = new MarsPlateau();

            marsPlateau.SetSize(3, 3);
            spaceProbe.PlateauLanded = marsPlateau;

            spaceProbe.MoveForward();

            Assert.Equal(spaceProbe.Position.XAxis, expectedXAxis);
            Assert.Equal(spaceProbe.Position.YAxis, expectedYAxis);
        }
Esempio n. 14
0
        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);
        }
Esempio n. 15
0
        public static void Main(string[] args)
        {
            var marsPlateau             = new MarsPlateau();
            List <SpaceProbe> probeList = new List <SpaceProbe>();
            var probe       = new SpaceProbe();
            var consoleRead = "initial";

            while (true)
            {
                consoleRead = Console.ReadLine();

                if (!string.IsNullOrEmpty(consoleRead))
                {
                    var command = new CommandParser(consoleRead);
                    if (command.CommandType == Core.Auxiliar.CommandType.CreatePlateau)
                    {
                        marsPlateau.SetSize(command.Size.Height, command.Size.Width);
                    }
                    else if (command.CommandType == Core.Auxiliar.CommandType.Land)
                    {
                        probe = new SpaceProbe();
                        probeList.Add(probe);
                        probe.Land(marsPlateau, command.Position, command.Direction);
                    }
                    else if (command.CommandType == Core.Auxiliar.CommandType.Move)
                    {
                        probe.Move(command.Movements);
                    }
                }
                else
                {
                    foreach (var item in probeList)
                    {
                        Console.WriteLine(item.Location());
                    }
                }
            }
        }
Esempio n. 16
0
        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);
        }
 public MarsPlateauTests()
 {
     marsPlateau = new MarsPlateau();
 }
 public MarsPlateauSurfaceShould()
 {
     _sut = new MarsPlateau();
 }