Ejemplo n.º 1
0
        public void Rover_WhenCorrectInput_Success()
        {
            var rov = new RoverManager();

            rov.Rover("1 3 N", "5 5");
            rov.Rover("2 2 W", "4 4");
        }
Ejemplo n.º 2
0
        public void ScenarioTwo()
        {
            var plateau = new Plateau(5, 5);
            var manager = new RoverManager(new CommandFactory());

            try
            {
                plateau.AddRover(3, 3, 'E');
                manager.ExecuteCommand('M', plateau);
                manager.ExecuteCommand('M', plateau);
                manager.ExecuteCommand('R', plateau);
                manager.ExecuteCommand('M', plateau);
                manager.ExecuteCommand('M', plateau);
                manager.ExecuteCommand('R', plateau);
                manager.ExecuteCommand('M', plateau);
                manager.ExecuteCommand('R', plateau);
                manager.ExecuteCommand('R', plateau);
                manager.ExecuteCommand('M', plateau);

                Assert.AreEqual("5 1 E", plateau.Rovers.Last().ToString());
            }
            catch (Exception)
            {
                Assert.Fail("Should not be here");
            }
        }
Ejemplo n.º 3
0
        public void Calculate()
        {
            RoverManager roverManager = new RoverManager();
            var          direction    = roverManager.Calculate();

            Assert.AreEqual(direction, Entities.Enums.Direction.N);
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            Console.Write("Upper-Right Coordinates Of The Plateu: ");
            var plateuCoordinates = Console.ReadLine().Split(' ');
            var plateuXCoordinate = int.Parse(plateuCoordinates[0]);
            var plateuYCoordinate = int.Parse(plateuCoordinates[1]);

            var plateuDto    = PlateuDtoFactory.CreatePlateuDto(plateuXCoordinate, plateuYCoordinate);
            var roverManager = new RoverManager();

            Console.Write("Rover Count: ");
            var roverCount = int.Parse(Console.ReadLine());

            int count = 1;

            while (count <= roverCount)
            {
                Console.Write($"Rover{count} Initial Position: ");
                var roverPosition    = Console.ReadLine().Split(' ');
                var roverXCoordinate = int.Parse(roverPosition[0]);
                var roverYCoordinate = int.Parse(roverPosition[1]);
                var roverDireciton   = char.Parse(roverPosition[2]);

                Console.Write($"Rover{count} Command: ");
                var roverCommand = Console.ReadLine();

                var roverDto = RoverDtoFactory.CreateRoverDto(count, roverXCoordinate, roverYCoordinate, roverDireciton, roverCommand, plateuDto);
                roverManager.AddRoverToList(roverDto);

                count++;
            }

            roverManager.MoveRovers();
            Console.ReadLine();
        }
Ejemplo n.º 5
0
        public void Should_Be_Throw_Rover_Cannot_Found_Exception(int x, int y)
        {
            var      p       = new Plateau(x, y);
            IManager manager = new RoverManager(p);

            Assert.ThrowsException <RoverCannotFoundException>(() => manager.Run());
        }
 public void initialize()
 {
     roverManager = new RoverManager(); //class to test
     roverProgram = new MainRoverProgram();
     text         = new StringWriter();
     Console.SetOut(text);
 }
Ejemplo n.º 7
0
 private void Awake()
 {
     if (!instance)
     {
         instance = this;
     }
 }
Ejemplo n.º 8
0
        public void LandRover_MustNotLandOnAnotherRover()
        {
            var manager = new RoverManager();

            manager.DiscoverPlateau(5, 5);

            manager.LandRover(new Rover()
            {
                Id       = 1,
                Position = new Vector()
                {
                    X = 4,
                    Z = 3
                }
            });

            Assert.Throws <InvalidOperationException>(() => manager.LandRover(new Rover()
            {
                Id       = 2,
                Position = new Vector()
                {
                    X = 4,
                    Z = 3
                }
            }));
        }
Ejemplo n.º 9
0
        static void Main(string[] args)
        {
            var rectangularManager = new RectangularManager();
            var roverManager       = new RoverManager();
            var movesManager       = new MovesManager();

            string rectangular = Console.ReadLine();
            var    rec         = rectangularManager.Rectangular(rectangular);


            string rover = Console.ReadLine();
            var    rov   = roverManager.Rover(rover, rectangular);

            string moves = Console.ReadLine();

            movesManager.Moves(moves, rov);

            string rover2 = Console.ReadLine();
            var    rov2   = roverManager.Rover(rover2, rectangular);

            string moves2 = Console.ReadLine();

            movesManager.Moves(moves2, rov2);

            Console.WriteLine(rov.X + " " + rov.Y + " " + rov.Direction);
            Console.WriteLine(rov2.X + " " + rov2.Y + " " + rov2.Direction);

            Console.ReadLine();
        }
Ejemplo n.º 10
0
        public void CalculateDirectionNandR()
        {
            RoverManager roverManager = new RoverManager();
            var          direction    = roverManager.CalculateDirection(Entities.Enums.Direction.N, Entities.Enums.Path.R);

            Assert.AreEqual(direction, Entities.Enums.Direction.E);
        }
Ejemplo n.º 11
0
        public void Rover_WhenOutOffLimits_Error()
        {
            var rov = new RoverManager();

            rov.Rover("7 3 N", "5 5");
            rov.Rover("2 8 W", "4 4");
            rov.Rover("9 9 E", "5 5");
        }
Ejemplo n.º 12
0
        public void Rover_WhenLastCharacterNotDirection_Error()
        {
            var rov = new RoverManager();

            rov.CheckDirection("S");
            rov.CheckDirection("3");
            rov.CheckDirection("k");
        }
Ejemplo n.º 13
0
        public void Rover_WhenFirst2CharacterNotInt_Error()
        {
            var rov = new RoverManager();

            rov.Rover("3 f N", "5 5");
            rov.Rover("f 8 W", "5 5");
            rov.Rover("T R E", "5 5");
        }
Ejemplo n.º 14
0
        private static void Main()
        {
            var roverFactory   = new RoverFactory();
            var userIo         = new ConsoleUserIO();
            var roverManager   = new RoverManager(roverFactory);
            var missionControl = new MissionControl(roverManager, userIo);

            missionControl.StartMission();
        }
Ejemplo n.º 15
0
        public void Rover_WhenLengthDifferent3_Error()
        {
            var rov = new RoverManager();

            rov.Rover("3", "5 5");
            rov.Rover("2 2", "5 5");
            rov.Rover(" 2 2", "5 5");
            rov.Rover("6 6 6 6", "5 5");
        }
Ejemplo n.º 16
0
        public void TestCase2()
        {
            Plateau  plateau  = new Plateau(5, 5);
            Position position = new Position(3, 3);

            Rover rover = new Rover(position, DirectionEnum.E);

            RoverManager.Execute(rover, plateau, "MMRMMRMRRM");
            Assert.AreEqual(RoverManager.CurrentPosition(rover), "5 1 E");
        }
Ejemplo n.º 17
0
        public void TestCase1()
        {
            Plateau  plateau  = new Plateau(5, 5);
            Position position = new Position(1, 2);

            Rover rover = new Rover(position, DirectionEnum.N);

            RoverManager.Execute(rover, plateau, "LMLMLMLMM");
            Assert.AreEqual(RoverManager.CurrentPosition(rover), "1 3 N");
        }
Ejemplo n.º 18
0
        public RoverMove SetupRoverMove(string input)
        {
            if (!RoverManager.MoveValidate(input))
            {
                throw new ArgumentException("Error occurred while creating Plateu, try again.");
            }

            var result = RoverManager.SetupMove(input);

            return(result);
        }
Ejemplo n.º 19
0
        public Rover AddRover(RoverInfo info, RoverMove move)
        {
            if (!RoverManager.Validate(info, move))
            {
                throw new ArgumentException("Error occurred while creating Rover, try again.");
            }

            var result = RoverManager.Insert(info, move);

            return(result);
        }
Ejemplo n.º 20
0
        public void Move()
        {
            Rover rover = new Rover();

            rover.Direction = Entities.Enums.Direction.N;
            rover.X         = 1;
            rover.Y         = 2;
            RoverManager roverManager = new RoverManager();

            roverManager.Move(rover);
            Assert.AreEqual(rover.X, 1);
            Assert.AreEqual(rover.Y, 3);
        }
Ejemplo n.º 21
0
        static void Main(string[] args)
        {
            IRoverManager roverController = new RoverManager();

            var integers = Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray();

            roverController.Plateau = new Rover[integers[0] + 1, integers[1] + 1];

            while (true)
            {
                roverController.PrepareEnvironment();
            }
        }
Ejemplo n.º 22
0
        public void RoverDeploy(string command, int plataueWidth, int plataueHeight)
        {
            var plataue = new Plataeu();

            plataue.DefineSize(plataueWidth, plataueHeight);

            IRoverManager manager             = new RoverManager(plataue);
            var           commandSplit        = command.Split(' ');
            var           expectedXCoordinate = int.Parse(commandSplit[0]);
            var           expectedYCoordinate = int.Parse(commandSplit[1]);
            var           expectedDirection   = (Direction)Enum.Parse(typeof(Direction), commandSplit[2]);

            manager.DeployRover(expectedXCoordinate, expectedYCoordinate, expectedDirection);
        }
Ejemplo n.º 23
0
        public void CanChangeDirection()
        {
            var plateau = new Plateau(5, 5);
            var manager = new RoverManager(new CommandFactory());

            try
            {
                plateau.AddRover(1, 2, 'N');
                manager.ExecuteCommand('R', plateau);

                Assert.AreEqual(DirectionE.E, plateau.Rovers.Last().Direction);
            }
            catch (Exception)
            {
                Assert.Fail("Should not be here");
            }
        }
Ejemplo n.º 24
0
        public void WillNotMoveForwardIfStandingOnEdge()
        {
            var plateau = new Plateau(5, 5);
            var manager = new RoverManager(new CommandFactory());

            try
            {
                plateau.AddRover(1, 5, 'N');
                manager.ExecuteCommand('M', plateau);

                Assert.AreEqual(5, plateau.Rovers.Last().PositionY);
            }
            catch (Exception)
            {
                Assert.Fail("Should not be here");
            }
        }
Ejemplo n.º 25
0
        public void DirectRover_RequiresRoverToHaveLanded()
        {
            var manager = new RoverManager();

            manager.DiscoverPlateau(5, 5);

            manager.LandRover(new Rover()
            {
                Id       = 1,
                Position = new Vector()
                {
                    X = 4,
                    Z = 3
                }
            });

            Assert.Throws <InvalidOperationException>(() => manager.DirectRover(2, RoverOperationType.Move));
        }
Ejemplo n.º 26
0
        public void WillExecuteCommand()
        {
            var command = new Mock <ICommand>();

            var commandFactory = new Mock <ICommandFactory>();
            var manager        = new RoverManager(commandFactory.Object);

            var plateau = new Plateau(5, 5);

            plateau.AddRover(0, 0, 'N');
            var rover = plateau.ActiveRover;

            command.Setup(x => x.Execute(rover));

            commandFactory.Setup(x => x.GetCommand(It.IsAny <char>())).Returns(command.Object);
            manager.ExecuteCommand('M', plateau);
            commandFactory.Verify(x => x.GetCommand('M'));
            command.Verify(x => x.Execute(rover));
        }
Ejemplo n.º 27
0
        public void RoverMove(string command)
        {
            var plataue = new Plataeu();

            plataue.DefineSize(5, 5);
            IRoverManager roverManager = new RoverManager(plataue);

            roverManager.DeployRover(0, 0, Direction.N);

            foreach (var moveCommand in command.ToCharArray())
            {
                var movement = (Movement)Enum.Parse(typeof(Movement), moveCommand.ToString());
                roverManager.ActiveRover.Move(movement);
            }

            Assert.Equal(0, roverManager.ActiveRover.XCoordinate);
            Assert.Equal(Direction.N, roverManager.ActiveRover.Direction);
            Assert.Equal(2, roverManager.ActiveRover.YCoordinate);
        }
Ejemplo n.º 28
0
        public void Rover_Is_Deployed_In_UnAcceptable_Position_On_Plateau(string command)
        {
            // Arrange
            ISurface plateau = new Plateau();

            plateau.SetSize(1, 1);

            IRoverManager roverManager        = new RoverManager(plateau);
            var           commandSplitted     = command.Split(' ');
            var           expectedXCoordinate = int.Parse(commandSplitted[0]);
            var           expectedYCoordinate = int.Parse(commandSplitted[1]);
            var           expectedDirection   = Enum.Parse <Direction>(commandSplitted[2]);

            // Act
            var action = new Action(() => roverManager.DeployRover(new Point(expectedXCoordinate, expectedYCoordinate), expectedDirection));

            // Assert
            action.Should().Throw <Exception>().WithMessage($"Rover outside of bounds. X: {expectedXCoordinate}, Y:{expectedYCoordinate}. Surface Width:{plateau.Size.Width}, Height:{plateau.Size.Height}");
        }
Ejemplo n.º 29
0
        public void Rover_Moves_To_North_More_Than_Plateau_Height_Returns_X_Position_Maximum_Plateau_Height(string command)
        {
            // Arrange
            ISurface plateau = new Plateau();

            plateau.SetSize(5, 5);
            IRoverManager roverManager = new RoverManager(plateau);

            roverManager.DeployRover(new Point(0, 0), Direction.N);
            var movements = command.ToCharArray().Select(x => Enum.Parse <Movement>(x.ToString())).ToList();

            //Act
            roverManager.ActiveRover.Move(movements);

            //Assert
            roverManager.ActiveRover.Should().NotBeNull();
            roverManager.ActiveRover.Position.Should().Be(new Point(0, 5));
            roverManager.ActiveRover.Direction.Should().Be(Direction.N);
        }
Ejemplo n.º 30
0
        public void Should_Be_Valid_Coordinates_For_All_Rovers(int x, int y)
        {
            //Arrange
            var p      = new Plateau(x, y);
            var rover1 = new Rover(1, 2, Direction.N, "LMLMLMLMM");
            var rover2 = new Rover(3, 3, Direction.E, "MMRMMRMRRM");

            //Act
            p.AddRover(rover1);
            p.AddRover(rover2);

            IManager manager = new RoverManager(p);

            manager.Run();

            //Assert
            Assert.AreEqual("1 3 N", rover1.ToString());
            Assert.AreEqual("5 1 E", rover2.ToString());
        }