示例#1
0
        public void Move_Rovers()
        {
            //Rover move tests
            var logger = new FileLogger(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "MainLog");

            var plateau = new Plateau(logger);

            plateau.SetPlateauSize("5 5");


            //Add rover 1
            var rover1 = new Rover(logger, "rover1");

            plateau.AddRover(rover1, "1 2 N");

            plateau.MoveRover("rover1", "LMLMLMLMM");

            Assert.Equal("1 3 N", plateau.GetRoverPoition("rover1"));


            //Add rover 2
            var rover2 = new Rover(logger, "rover2");

            plateau.AddRover(rover2, "3 3 E");

            plateau.MoveRover("rover2", "MMRMMRMRRM");

            plateau.GetRoverPoition("rover2");

            Assert.Equal("5 1 E", plateau.GetRoverPoition("rover2"));
        }
示例#2
0
        public void Check_move_position()
        {
            //Test that rovers can't occupy the same space when moving
            var logger = new FileLogger(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "MainLog");

            //Plateau
            var plateau = new Plateau(logger);

            plateau.SetPlateauSize("5 5");


            //Add rover 1
            var rover1 = new Rover(logger, "rover1");

            plateau.AddRover(rover1, "1 2 N");

            plateau.MoveRover("rover1", "LMLMLMLMM");

            Assert.Equal("1 3 N", plateau.GetRoverPoition("rover1"));


            //Add rover 2
            var rover2 = new Rover(logger, "rover2");

            plateau.AddRover(rover2, "1 2 N");

            Assert.ThrowsAny <Exception> (() => plateau.MoveRover("rover2", "LMLMLMLMMMLMLMLM"));
        }
示例#3
0
        public void Move_Action_ShouldThrowException(int x, int y, char compassDirection)
        {
            var plateau = new Plateau(5, 5);

            plateau.AddRover(new RoverCuriosity(1, 1, 'N', plateau));

            var rover = new RoverCuriosity(x, y, compassDirection, plateau);

            plateau.AddRover(rover);

            Assert.That(() => rover.MoveForward(), Throws.InvalidOperationException);
        }
示例#4
0
        public void IncorrectCommand()
        {
            Plateau Plateau = new Plateau(5, 5);
            Rover   rover   = new Rover(new Point(3, 3, "E"));

            Plateau.AddRover(rover, "AMMRMMRMRRM");
        }
示例#5
0
        public void IncorrectDirection()
        {
            Plateau Plateau = new Plateau(5, 5);
            Rover   rover   = new Rover(new Point(3, 3, "K"));

            Plateau.AddRover(rover, "MMRMMRMRRM");
        }
示例#6
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");
            }
        }
示例#7
0
        public void AddRover_IsOutOfTheBoundsOfThePlateau_ShouldThrowInvalidOperationException(int top, int right, int roverX, int roverY)
        {
            var plateau = new Plateau(top, right);
            var rover   = new RoverCuriosity(roverX, roverY, 'N', plateau);

            Assert.That(() => plateau.AddRover(rover), Throws.InvalidOperationException);
        }
示例#8
0
        public void FirstRoverCheckOutput()
        {
            Plateau Plateau = new Plateau(5, 5);
            Rover   rover   = new Rover(new Point(1, 2, "N"));

            Plateau.AddRover(rover, "LMLMLMLMM");
            Assert.AreEqual(rover.ToString(), "1 3 N");
        }
示例#9
0
        public void SecondRoverCheckOutput()
        {
            Plateau Plateau = new Plateau(5, 5);
            Rover   rover   = new Rover(new Point(3, 3, "E"));

            Plateau.AddRover(rover, "MMRMMRMRRM");
            Assert.AreEqual(rover.ToString(), "5 1 E");
        }
示例#10
0
        public void CheckBorderCrossing()
        {
            Plateau Plateau = new Plateau(2, 2);
            Rover   rover   = new Rover(new Point(0, 0, "W"));

            Plateau.AddRover(rover, "MMM");
            Assert.AreEqual(rover.ToString(), "0 0 W");
        }
示例#11
0
        public void AddRoverShould()
        {
            var plateau = new Plateau(5, 5);

            plateau.AddRover(1, 1, Direction.North, null);

            Assert.True(plateau.Rovers.Count == 1);
        }
示例#12
0
        public void AddRover_Action_ShouldRunWithoutException(int top, int right, int roverX, int roverY)
        {
            var plateau = new Plateau(top, right);
            var rover   = new RoverCuriosity(roverX, roverY, 'N', plateau);

            plateau.AddRover(rover);
            Assert.That(plateau.Rovers[0].X() == roverX);
            Assert.That(plateau.Rovers[0].Y() == roverY);
        }
示例#13
0
        static void Main()
        {
            var     input       = File.OpenText("input.txt");
            var     plateauSize = input.ReadLine().Split();
            var     maxX        = Convert.ToInt32(plateauSize[0]);
            var     maxY        = Convert.ToInt32(plateauSize[1]);
            Plateau plateau     = null;

            try
            {
                plateau = new Plateau(maxX, maxY);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Environment.Exit(1);
            }

            var manager = new RoverManager(new CommandFactory());

            do
            {
                var line = input.ReadLine();
                if (line == null)
                {
                    break;
                }

                var  position  = line.Split();
                int  positionX = Convert.ToInt32(position[0]);
                int  positionY = Convert.ToInt32(position[1]);
                char direction = Convert.ToChar(position[2]);

                Rover rover = null;

                try
                {
                    rover = plateau.AddRover(positionX, positionY, direction);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    Environment.Exit(1);
                }

                var commandStream = input.ReadLine();

                Array.ForEach(commandStream.ToCharArray(), command => manager.ExecuteCommand(command, plateau));
            } while (true);

            input.Close();

            plateau.PrintRovers();

            Console.ReadKey();
        }
示例#14
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());
        }
示例#15
0
        public void Should_Be_Valid_Coordinate_Rover(int x, int y, Direction direction, string commands, string result)
        {
            var plateau = new Plateau(5, 5);

            plateau.AddRover(x, y, direction, commands);
            plateau.Run();
            var roverResult = plateau.Rovers.First().ToString();

            Assert.True(result == roverResult);
        }
示例#16
0
        public void CanAddRoverToPlateau()
        {
            //  arrange
            var plateau = new Plateau(x: 5, y: 5);
            var rover   = new Rover(x: 1, y: 1, cardinalDirection: CardinalDirection.North);

            //  act
            plateau.AddRover(rover);

            //  assert
            Assert.AreEqual(1, plateau.Rovers.Count);
        }
示例#17
0
        public void CannotAddRoverOutOfPlateauArea()
        {
            //  arrange
            var plateauUpperRighCoordinate = new Coordinate(x: 5, y: 5);
            var roverInitialCoordinate     = new Position(x: 6, y: 6, cardinalDirection: CardinalDirection.North);

            var plateau = new Plateau(plateauUpperRighCoordinate);
            var rover   = new Rover(roverInitialCoordinate);

            //  act
            plateau.AddRover(rover);
        }
示例#18
0
        public void CanAddRovers()
        {
            var plateau = new Plateau(5, 5);

            try
            {
                plateau.AddRover(1, 2, 'N');
            }
            catch (InvalidOperationException e)
            {
                Assert.Fail(e.Message);
            }
        }
示例#19
0
        public void Check_set_position()
        {
            //Test that rovers can't occupy the same space when adding
            var logger = new FileLogger(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "MainLog");

            var plateau = new Plateau(logger);

            plateau.SetPlateauSize("5 5");

            var rover3 = new Rover(logger, "rover3");

            Assert.ThrowsAny <Exception>(() => plateau.AddRover(rover3, "1 8 N"));
        }
示例#20
0
        public void Should_Be_Valid_Rover_Coordinates_On_Plateau(int x, int y, Direction direction, string cmd)
        {
            //Arrange
            var p = new Plateau(5, 5);

            //Act
            var rover = p.AddRover(new Rover(x, y, direction, cmd));

            //Assert
            Assert.AreEqual(1, rover.X);
            Assert.AreEqual(2, rover.Y);
            Assert.AreEqual(Direction.N, rover.Direction);
            Assert.IsNotNull(p._points[x, y].RoverOn);
        }
示例#21
0
        public void CanNotAddRovers()
        {
            var plateau = new Plateau(5, 5);

            try
            {
                // Invalid direction
                plateau.AddRover(1, 2, 'A');

                Assert.Fail("Should fail on invalid direction");
            }
            catch (ArgumentException e)
            {
                Assert.AreEqual("Invalid direction A", e.Message);
                throw;
            }
        }
示例#22
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");
            }
        }
示例#23
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");
            }
        }
示例#24
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));
        }
示例#25
0
        public void Should_Be_Throw_Invalid_Argument_Exception(int x, int y, Direction direction, string cmd)
        {
            var p = new Plateau(x, y);

            Assert.ThrowsException <InvalidArgumentException>(() => p.AddRover(new Rover(x, y, direction, cmd)));
        }
示例#26
0
        public void Should_Throw_Invalid_Coordinates_Exception(int x, int y, Direction direction, string cmd)
        {
            var p = new Plateau(5, 5);

            Assert.ThrowsException <InvalidCoordinateException>(() => p.AddRover(new Rover(x, y, direction, cmd)));
        }