Example #1
0
        public void TestScanrio_33E()
        {
            RoboticRover firstRoboticRover = new RoboticRover(3, 3, Directions.Direction.N, new Plateau(5, 5));

            DirectRoboticRover.Direct(firstRoboticRover, "MRRMMRMRRM");
            Assert.Equal("3 2 E", GetRoboticRoverPosition.GetPosition(firstRoboticRover));
        }
Example #2
0
        public void When_The_Input_33E_MMRRMMRMRRM_The_Output_Should_Be_51E()
        {
            //CASE
            Input.Coorinates = new Constants.Coorinates(3, 3);
            Input.Direction  = Constants.Directions.East;
            Input.Moves      = "MMRMMRMRRM";

            //WHEN
            var response = new RoboticRover().Row(Input);

            if (!response.Success)
            {
                Assert.Fail(response.Results.FirstOrDefault().ErrorMessage);
            }
            var output = response.Value;

            //THEN
            var expectedOutput = new Output
            {
                Coorinates = new Constants.Coorinates(5, 1),
                Direction  = Constants.Directions.East
            };

            Assert.AreSame(expectedOutput.Direction.ToString(), output.Direction.ToString());
            Assert.AreEqual(expectedOutput.Coorinates.X, output.Coorinates.X);
            Assert.AreEqual(expectedOutput.Coorinates.Y, output.Coorinates.Y);
        }
Example #3
0
        public void ProcessDataTest()
        {
            RoboticRover roboticNew = new RoboticRover('N', new Plateau(5, 5)
            {
                XAxis = 1, YAxis = 2
            });                                                                                          //Standard documentation test

            VehicleHelper.ProcessData("LMLMLMLMM", roboticNew, originalPlateau);

            RoboticRover roboticNew2 = new RoboticRover('E', new Plateau(5, 5)
            {
                XAxis = 3, YAxis = 3
            });                                                                                          //Standard documentation test

            VehicleHelper.ProcessData("MMRMMRMRRM", roboticNew2, originalPlateau);

            RoboticRover roboticNew3 = new RoboticRover('E', new Plateau(5, 5)
            {
                XAxis = 3, YAxis = 3
            });                                                                                           //Check for what happens if boundaries exceed

            VehicleHelper.ProcessData("MMMRMMRMRRM", roboticNew3, originalPlateau);

            RoboticRover roboticNew4 = new RoboticRover('E', new Plateau(5, 5)
            {
                XAxis = 3, YAxis = 3
            });                                                                                           //Check for if direction changes

            VehicleHelper.ProcessData("MMMRMMRMRRMR", roboticNew4, originalPlateau);
        }
Example #4
0
        public void TestScanrio_14N()
        {
            RoboticRover firstRoboticRover = new RoboticRover(1, 3, Directions.Direction.N, new Plateau(5, 5));

            DirectRoboticRover.Direct(firstRoboticRover, "LMLMLMLMM");
            Assert.Equal("1 4 N", GetRoboticRoverPosition.GetPosition(firstRoboticRover));
        }
Example #5
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!");
        }
Example #6
0
        public void Test1()
        {
            Plateau      plateau = new Plateau(1, 1);
            RoboticRover robotic = new RoboticRover('N', plateau);

            var type = robotic.GetType();

            Console.ReadLine();
        }
Example #7
0
        static void Main(string[] args)
        {
            string[] plateauCoordinates           = Console.ReadLine().Split(' ');
            string[] firstRoboticRoverCoordinates = Console.ReadLine().Split(' ');
            string   firstRoboticRoverActions     = Console.ReadLine();

            string[] secondRoboticRoverCoordinates = Console.ReadLine().Split(' ');
            string   secondRoboticRoverActions     = Console.ReadLine();

            Plateau plateau = new Plateau()
            {
                UpperRightXCoordinate = Convert.ToInt16(plateauCoordinates[0]),
                UpperRightYCoordinate = Convert.ToInt16(plateauCoordinates[1])
            };

            RoboticRover[] roboticRover = new RoboticRover[2];

            roboticRover[0] = new RoboticRover(plateau);
            roboticRover[1] = new RoboticRover(plateau);

            roboticRover[0].Location = new Location()
            {
                XCoordinate = Convert.ToInt16(firstRoboticRoverCoordinates[0]),
                YCoordinate = Convert.ToInt16(firstRoboticRoverCoordinates[1]),
                Direction   = firstRoboticRoverCoordinates[2].ToEnum <CompassDirection>(true)
            };

            roboticRover[1].Location = new Location()
            {
                XCoordinate = Convert.ToInt16(secondRoboticRoverCoordinates[0]),
                YCoordinate = Convert.ToInt16(secondRoboticRoverCoordinates[1]),
                Direction   = secondRoboticRoverCoordinates[2].ToEnum <CompassDirection>(true)
            };

            RoboticRoverBusiness[] roboticRoverBusiness = new RoboticRoverBusiness[2];

            roboticRoverBusiness[0] = new RoboticRoverBusiness(roboticRover[0]);
            roboticRoverBusiness[1] = new RoboticRoverBusiness(roboticRover[1]);


            roboticRoverBusiness[0].DoActions(firstRoboticRoverActions);
            roboticRoverBusiness[1].DoActions(secondRoboticRoverActions);

            Console.Write(roboticRover[0].Location.XCoordinate + " ");
            Console.Write(roboticRover[0].Location.YCoordinate + " ");
            Console.WriteLine(roboticRover[0].Location.Direction.ToStringValue());

            Console.Write(roboticRover[1].Location.XCoordinate + " ");
            Console.Write(roboticRover[1].Location.YCoordinate + " ");
            Console.WriteLine(roboticRover[1].Location.Direction.ToStringValue());

            Console.ReadLine();
        }
Example #8
0
        public void MoveVehicleTest()
        {
            RoboticRover roboticNew = new RoboticRover('N', new Plateau(5, 5)
            {
                XAxis = 1, YAxis = 1
            });

            for (int i = 0; i < 4; i++)
            {
                VehicleHelper.MoveVehicle(roboticNew, originalPlateau);
                VehicleHelper.TurnVehicle(roboticNew, 'L');
            }
        }
Example #9
0
        public void CheckForBoundaries()
        {
            RoboticRover roboticNew = new RoboticRover('N', new Plateau(5, 5)
            {
                XAxis = 1, YAxis = 1
            });
            Plateau plateau = VehicleHelper.GetDirectionToMove(robotic);

            for (int i = 0; i < 4; i++)//One iteration for each side
            {
                VehicleHelper.CheckForBoundaries(roboticNew.CurrentCoordinates(), plateau, originalPlateau);
                plateau = TurnAndGetDirection(robotic);
            }
        }
Example #10
0
        private static MarsMap GetMap(int roverX, int roverY, ICardinalPoint cardinalPoint, List <DirectionType> directionTypes)
        {
            RoboticRover rover      = new RoboticRover(new MarsPoint(roverX, roverY), cardinalPoint);
            var          directions = directionTypes;

            rover.MovePattern = new MovePattern(directions);
            MarsMap map = new MarsMap(new MarsPoint(5, 5));

            map.Rovers = new List <RoverBase>()
            {
                rover
            };
            return(map);
        }
Example #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");
        }
Example #12
0
        public void When_The_Input_IsNull_Should_Take_An_Error()
        {
            //CASE

            Input = null;
            //WHEN
            var response = new RoboticRover().Row(Input);


            //THEN
            if (response.Success)
            {
                Assert.Fail();
            }

            Assert.AreEqual(response.Results.FirstOrDefault().ErrorCode, nameof(ErrorCodes.NullParamether));
        }
Example #13
0
        public void GenerateRoboticRover()
        {
            //arrange

            var borders      = new int[] { 5, 6 };
            var coordinates  = new int[] { 1, 2 };
            var direction    = 'N';
            var instructions = new List <char>()
            {
                'L', 'M', 'L', 'M', 'L', 'M', 'L', 'M', 'M'
            };


            //act
            var roboticRover = new RoboticRover(borders, coordinates, direction, instructions);

            //assert
            Assert.AreEqual(roboticRover.BorderX, borders[0]);
            Assert.AreEqual(roboticRover.BorderY, borders[1]);
            Assert.AreEqual(roboticRover.CoordinateX, coordinates[0]);
            Assert.AreEqual(roboticRover.CoordinateY, coordinates[1]);
            Assert.AreEqual(roboticRover.Direction.ToString()[0], direction);
            //Assert.AreEqual(roboticRover.Instructions, instructions);
        }
Example #14
0
 /// <summary>
 /// Set the first roboticRover
 /// </summary>
 private void SetupFirstRover()
 {
     firstRover = new RoboticRover(1, 2, RoboticRover.Direction.N, new Plateau(5, 5));
 }
Example #15
0
 /// <summary>
 /// Set the second roboticRover
 /// </summary>
 private void SetupSecondRover()
 {
     secondRover = new RoboticRover(3, 3, RoboticRover.Direction.E, new Plateau(5, 5));
 }
Example #16
0
        static void Main(string[] args)
        {
            Console.WriteLine("Please enter maximum coordinates of plateau (x, y): ");
            string coordinates = Console.ReadLine();

            string[] cor = coordinates.Split(',').ToArray();
            int      x = 0, y = 0, num = 0;

            if (cor.Length == 2)
            {
                x = Convert.ToInt16(cor[0].Trim());
                y = Convert.ToInt16(cor[1].Trim());
            }
            Console.WriteLine("Please enter number of rovers on plateau : ");
            string numberOfRovers = Console.ReadLine();

            if (!string.IsNullOrEmpty(numberOfRovers))
            {
                num = Convert.ToInt16(numberOfRovers.Trim());
            }
            Plateau p = new Plateau(x, y);
            int     xRover = 0, yRover = 0;
            bool    notValidCords = true;

            string[] corRover = new string[3];
            for (int i = 0; i < num; i++)
            {
                notValidCords = true;
                while (notValidCords)
                {
                    Console.WriteLine(string.Format("Please enter starting coordinates and facing of rover{0} (x y facing): ", i + 1));
                    string coor = Console.ReadLine();
                    corRover = coor.Split(' ').ToArray();
                    xRover   = Convert.ToInt16(corRover[0].Trim());
                    yRover   = Convert.ToInt16(corRover[1].Trim());
                    if (0 <= xRover && xRover <= x && yRover >= 0 && yRover <= y)
                    {
                        notValidCords = false;
                        break;
                    }
                    else
                    {
                        Console.WriteLine("Invalid Coordinates!");
                    }
                }
                Direction c = Direction.N;
                switch (corRover[2].Trim().ToUpper())
                {
                case "N":
                    c = Direction.N;
                    break;

                case "W":
                    c = Direction.W;
                    break;

                case "S":
                    c = Direction.S;
                    break;

                case "E":
                    c = Direction.E;
                    break;

                default:
                    c = Direction.N;
                    break;
                }
                RoboticRover rover = new RoboticRover(xRover, yRover, c);
                Console.WriteLine(string.Format("Please enter command for rover{0}", i + 1));
                string command = Console.ReadLine();
                rover.Command(command.Trim(), x, y);
                p.Rovers.Add(rover);
            }

            Console.WriteLine(Environment.NewLine);
            Console.WriteLine("Final position of Rovers respectively: ");
            foreach (var rover in p.Rovers)
            {
                Console.WriteLine(rover.GetPosition());
            }
            Console.ReadLine();
        }
Example #17
0
 /// <summary>
 /// Set the first roboticRover
 /// </summary>
 private void SetupRover(int x, int y, Direction dir)
 {
     Rover = new RoboticRover(x, y, dir);
 }
 public void SetUp()
 {
     _point         = Substitute.For <Point>();
     _cardinalPoint = Substitute.For <ICardinalPoint>();
     _rover         = new RoboticRover(_point, _cardinalPoint);
 }