예제 #1
0
        public void MoveFromOvestDirection_ObstaclePoint_ThrowException()
        {
            var       B = new Backward();
            Grid      G = new Grid(5, 5, new FakeObstacleGenerator());
            RoverMars R = new RoverMars('O');

            R.Position.X = 1;
            R.Position.Y = 2;
            B.MoveFromOvestDirection(R, G);
        }
예제 #2
0
        public void MoveFromSudDirection_turnLeft_expectedNewDirection_E()
        {
            var  rover    = new RoverMars('S');
            var  g        = new Grid(2, 3, new FakeObstacleGenerator());
            var  L        = new Left();
            char expected = 'E';

            L.MoveFromSudDirection(rover, g);
            Assert.AreEqual(expected, rover.Direction);
        }
예제 #3
0
        public void MoveFromEstDirection_TurnRight_newExpectedDirection_S()
        {
            var r = new RoverMars('E');
            var g = new Grid(4, 4, new FakeObstacleGenerator());
            var R = new Right();

            R.MoveFromEstDirection(r, g);
            char expected = 'S';

            Assert.AreEqual(expected, r.Direction);
        }
예제 #4
0
        public void MoveRover_RoverDirectionSRightInputCommand_MoveFromSudDirectionOfRightCommandIsCalled()
        {
            var rover   = new RoverMars('S');
            var g       = new Grid(4, 4, new FakeObstacleGenerator());
            var command = new List <ICommand> {
                new FakeRigtCommand()
            };

            Move.MoveRover(rover, g, command);
            var TestCommand = command[0] as FakeRigtCommand;

            Assert.IsTrue("Right.MoveFromSudDirection".Equals(TestCommand.Fake));
        }
예제 #5
0
        public void MoveRover_RoverDirectionNLeftImputCommand_MoveFromNordDirectionOfLeftCommandIsCalled()
        {
            var rover   = new RoverMars('N');
            var g       = new Grid(4, 4, new FakeObstacleGenerator());
            var command = new List <ICommand> {
                new FakeLeftCommand()
            };

            Move.MoveRover(rover, g, command);
            var TestCommand = command[0] as FakeLeftCommand;

            Assert.IsTrue("Left.MoveFromNordDirection".Equals(TestCommand.Fake));
        }
예제 #6
0
 public void MoveFromOvestDirection_NewRoverPoint_OutOfGridValueLessThenZero_Expected_NewXEqualsMaxXOfGrid()
 {
     {
         var       B = new Backward();
         Grid      G = new Grid(5, 5, new FakeObstacleGenerator());
         RoverMars R = new RoverMars('O');
         R.Position.X = -2;
         R.Position.Y = 2;
         B.MoveFromOvestDirection(R, G);
         Point expectedNewRoverPosition = new Point(5, 2);
         Assert.AreEqual(expectedNewRoverPosition, R.Position);
     }
 }
예제 #7
0
        public void MoveFromSudDirection_ObstaclePoint_ThrowException()
        {
            var       B = new Backward();
            RoverMars R = new RoverMars('N');

            // this case should never happen but this class does not know
            // i give to the rover an impossible point
            R.Position.X = 2;
            R.Position.Y = 1;
            Grid G = new Grid(5, 5, new FakeObstacleGenerator());

            B.MoveFromSudDirection(R, G);
        }
예제 #8
0
        public void MoveRover_RoverDirectionEBackwardtInputCommand_MoveFromEstDirectionOfBackwardCommandIsCalled()
        {
            var rover   = new RoverMars('E');
            var g       = new Grid(4, 4, new FakeObstacleGenerator());
            var command = new List <ICommand> {
                new FakeBackwardCommand()
            };

            Move.MoveRover(rover, g, command);
            var TestCommand = command[0] as FakeBackwardCommand;

            Assert.IsTrue("Backward.MoveFromEstDirection".Equals(TestCommand.Fake));
        }
예제 #9
0
        public void MoveFromNordDirection_NewRoverPoint_OutOfGrid_Expected_NewYEqualsZero()
        {
            var       B = new Backward();
            RoverMars R = new RoverMars('N');

            R.Position.X = 1;
            R.Position.Y = 7;
            Grid G = new Grid(5, 5, new FakeObstacleGenerator());

            B.MoveFromNordDirection(R, G);
            Point expectedNewRoverPosition = new Point(1, 0);

            Assert.AreEqual(expectedNewRoverPosition, R.Position);
        }
예제 #10
0
        public void MoveFromEstDirection_NewRoverPoint_OutOfGrid_Expected_NewXEqualsZero()
        {
            Backward  B = new Backward();
            RoverMars R = new RoverMars('E');

            R.Position.X = 7;
            R.Position.Y = 1;
            Grid G = new Grid(5, 5, new FakeObstacleGenerator());

            B.MoveFromEstDirection(R, G);
            Point expectedNewRoverPosition = new Point(0, 1);

            Assert.AreEqual(expectedNewRoverPosition, R.Position);
        }
예제 #11
0
        public void MoveFromEstDirection_MoveRoverInXMinusOne()
        {
            var       B = new Backward();
            RoverMars R = new RoverMars('E');

            R.Position.X = 1;
            R.Position.Y = 1;
            Grid G = new Grid(5, 5, new FakeObstacleGenerator());

            B.MoveFromEstDirection(R, G);
            Point expectedNewRoverPosition = new Point(0, 1);

            Assert.AreEqual(expectedNewRoverPosition, R.Position);
        }
예제 #12
0
        public void MoveFromOvestDirection_NewRoverPoint_OutOfGrid_Expected_NewXEqualsZero()
        {
            var       B = new Backward();
            Grid      G = new Grid(5, 5, new FakeObstacleGenerator());
            RoverMars R = new RoverMars('O');

            //rover orientation is ovest direction
            R.Position.X = 5;
            R.Position.Y = 1;
            B.MoveFromOvestDirection(R, G);
            Point expectedNewRoverPosition = new Point(0, 1);

            Assert.AreEqual(expectedNewRoverPosition, R.Position);
        }
예제 #13
0
        public void MoveFromSudDirection_MoveRoverInYMinusOne()
        {
            Foreward  F = new Foreward();
            RoverMars R = new RoverMars('S');

            R.Position.X = 1;
            R.Position.Y = 1;
            Grid G = new Grid(5, 5, new FakeObstacleGenerator());

            F.MoveFromSudDirection(R, G);
            Point expectedNewRoverPosition = new Point(1, 0);

            Assert.AreEqual(expectedNewRoverPosition, R.Position);
        }
예제 #14
0
        public void MoveFromOvestDirection_NewRoverPoint_OutOfGrid_Expected_NewXEqualsZero()
        {
            Foreward  F = new Foreward();
            Grid      G = new Grid(5, 5, new FakeObstacleGenerator());
            RoverMars R = new RoverMars('O');

            //rover orientation is ovest direction
            //rover actual position is an impossible point since in the reality this case never occurs
            R.Position.X = 7;
            R.Position.Y = 1;
            F.MoveFromOvestDirection(R, G);
            Point expectedNewRoverPosition = new Point(0, 1);

            Assert.AreEqual(expectedNewRoverPosition, R.Position);
        }
예제 #15
0
        public void MoveFromSudDirection_NewRoverPoint_OutOfGrid_Expected_NewYEqualsZero()
        {
            Foreward  F = new Foreward();
            RoverMars R = new RoverMars('S');

            //cannot happen
            R.Position.X = 1;
            R.Position.Y = 7;
            Grid G = new Grid(5, 5, new FakeObstacleGenerator());

            F.MoveFromSudDirection(R, G);
            Point expectedNewRoverPosition = new Point(1, 0);

            Assert.AreEqual(expectedNewRoverPosition, R.Position);
        }
예제 #16
0
        public void MoveFromSudDirection_NewRoverPoint_OutOfGridValueLessThenZero_Expected_NewYEqualsMaxYOfGrid()
        {
            var       B = new Backward();
            RoverMars R = new RoverMars('N');

            // this case should never happen but this class does not know
            // i give to the rover an impossible point
            R.Position.X = 1;
            R.Position.Y = -2;
            Grid G = new Grid(5, 5, new FakeObstacleGenerator());

            B.MoveFromSudDirection(R, G);
            Point expectedNewRoverPosition = new Point(1, 5);

            Assert.AreEqual(expectedNewRoverPosition, R.Position);
        }
예제 #17
0
        public void MoveFromOvestDirection_MoveRoverInXPluOne()
        {
            Backward B = new Backward();
            //rover orientation is ovest direction, is not responsibility of this class check direction
            RoverMars R = new RoverMars('O');

            //rover actual position is 1,1
            R.Position.X = 1;
            R.Position.Y = 1;
            Grid G = new Grid(5, 5, new FakeObstacleGenerator());

            B.MoveFromOvestDirection(R, G);
            Point expectedNewRoverPosition = new Point(2, 1);

            Assert.AreEqual(expectedNewRoverPosition, R.Position);
        }
예제 #18
0
        public void MoveFromEstDirection_NewRoverPoint_OutOfGridValueLessThenZero_Expected_NewXEqualsMaxXOfGrid()
        {
            Foreward  F = new Foreward();
            RoverMars R = new RoverMars('E');

            // this case should never happen but this class does not know
            // i give to the rover an impossible point
            R.Position.X = -2;
            R.Position.Y = 1;
            Grid G = new Grid(5, 5, new FakeObstacleGenerator());

            F.MoveFromEstDirection(R, G);
            Point expectedNewRoverPosition = new Point(5, 1);

            Assert.AreEqual(expectedNewRoverPosition, R.Position);
        }
예제 #19
0
        static void Main(string[] args)
        {
            ObstacleGenerator generatorProva = new ObstacleGenerator(0);
            //ProvaAManoGeneratore generatorProva = new ProvaAManoGeneratore();
            Grid myProvaGrid = new Grid(0, 0, generatorProva);

            RoverMars myRover = new RoverMars();

            char            commandToInsertInList = 'c';
            List <ICommand> userList = new List <ICommand>();

            Console.WriteLine("Welcome to the program that make you send command to rover in a list" + Environment.NewLine +
                              "Digit F to insert a foreward command;" + Environment.NewLine +
                              "Digit B to insert a backword command;" +
                              Environment.NewLine +
                              "Digit L to insert a left command;" + Environment.NewLine +
                              "Digit R to insert a right command" + Environment.NewLine +
                              "Digit E to send the complete list of command to the rover");

            while (commandToInsertInList != 'E')
            {
                try
                {
                    commandToInsertInList = Convert.ToChar(Console.ReadLine().ToUpper());
                }
                catch (Exception e)
                {
                    commandToInsertInList = 'c';//not valid command-->defalut is the case
                }

                switch (commandToInsertInList)
                {
                case 'F':
                    userList.Add(new Foreward());
                    Console.WriteLine("if you want insert another command or send the list");
                    break;

                case 'B':
                    userList.Add(new Backward());
                    Console.WriteLine("if you want insert another command or send the list");
                    break;

                case 'L':
                    userList.Add(new Left());
                    Console.WriteLine("if you want insert another command or send the list");
                    break;

                case 'R':
                    userList.Add(new Right());
                    Console.WriteLine("if you want insert another command or send the list");
                    break;

                case 'E':
                    Console.WriteLine("The following command have been sent to Rover");
                    Console.ForegroundColor = ConsoleColor.Green;
                    foreach (ICommand c in userList)
                    {
                        Console.WriteLine(c.ToString());
                    }
                    Console.ResetColor();
                    break;

                default:
                    Console.WriteLine("The command is not valid");
                    break;
                }
            }
            Console.WriteLine("The following are the rover movement");
            Move.MoveRover(myRover, myProvaGrid, userList);
            Console.ReadLine();// only to not close terminal
        }