예제 #1
0
        public void AndTheRoverIsFacingNorthThenTheYDecreasesByOne()
        {
            var rover    = new Rover(0, 0, Direction.North);
            var newRover = RoverCommands.MoveBackward(rover);

            Assert.AreEqual(newRover.X, rover.X);
            Assert.AreEqual(newRover.Y, rover.Y - 1);
            Assert.AreEqual(newRover.Direction, rover.Direction);
        }
예제 #2
0
        public void AndTheRoverIsFacingWestThenTheXIncreasesByOne()
        {
            var rover    = new Rover(0, 0, Direction.West);
            var newRover = RoverCommands.MoveBackward(rover);

            Assert.AreEqual(newRover.X, rover.X + 1);
            Assert.AreEqual(newRover.Y, rover.Y);
            Assert.AreEqual(newRover.Direction, rover.Direction);
        }
        public void ThenTheRoverIsFacingTheCorrectDirection(Direction start, Direction end)
        {
            var rover    = new Rover(0, 0, start);
            var newRover = RoverCommands.TurnLeft(rover);

            Assert.AreEqual(newRover.X, rover.X);
            Assert.AreEqual(newRover.Y, rover.Y);
            Assert.AreEqual(newRover.Direction, end);
        }
        public void TestKnonwPositionsResult1()
        {
            Robots robot1 = new Robots()
            {
                PositionX = 1, PositionY = 2, Direction = Directions.N, Commands = "LMLMLMLMM"
            };
            string resul1 = "1 3 N";

            List <Robots> robots = new List <Robots>()
            {
                robot1
            };

            RoverCommands rc = new RoverCommands(robots, new Area(5, 4));

            robots = rc.RedirectRobots();

            Assert.AreEqual(robots[0].NewPosition, resul1);
        }
        public void TestKnonwPositionsResult2()
        {
            Robots robot2 = new Robots()
            {
                PositionX = 3, PositionY = 3, Direction = Directions.E, Commands = "MMRMMRMRRM"
            };

            string result2 = "5 1 E";

            List <Robots> robots = new List <Robots>()
            {
                robot2
            };

            RoverCommands rc = new RoverCommands(robots, new Area(5, 4));

            robots = rc.RedirectRobots();

            Assert.AreEqual(robots[0].NewPosition, result2);
        }
        public void Test_Rover_Commands2()
        {
            const int inX = 3, inY = 3, w = 5, h = 5;
            const Utils.Orientation inOrientation = Utils.Orientation.East;
            const string            commandInput = "MMRMMRMRRM";

            const int outX = 5, outY = 1;
            const Utils.Orientation outOrientation = Utils.Orientation.East;

            RoverCommands.TryParse(commandInput, out RoverCommands commands);

            var rover = new Rover(inX, inY, inOrientation, commands, w, h);

            foreach (var cmd in rover.Commands)
            {
                rover.Execute(cmd, false, null);
            }

            Assert.AreEqual(rover.CurrentState.X, outX);
            Assert.AreEqual(rover.CurrentState.Y, outY);
            Assert.AreEqual(rover.CurrentState.Orientation, outOrientation);
        }