Exemplo n.º 1
0
 public void CreateRover()
 {
     //Arrange
                                         rover rover = new rover();
                                         //Assert
                                         Assert.IsNotNull(rover);
 }
Exemplo n.º 2
0
 public void testSetcoodX()
 {
     //Arrange
                                         rover rover = new rover();
                                         //Act
                                         rover.setcoodX(10);
                                         //Assert
                                         Assert.IsTrue(rover.getcoodX() == 10);
 }
Exemplo n.º 3
0
 public void testGetposition()
 {
     //Arrange
                                     rover rover = new rover();
                                     //Act
                                     rover.getposition();
                                     //Assert
                                     Assert.AreEqual(rover.getposition(), null);
 }
Exemplo n.º 4
0
 public void testGetcoodY()
 {
     //Arrange
                                     rover rover = new rover();
                                     //Act
                                     int output = rover.getcoodY();
                                     //Assert
                                     Assert.AreEqual(output, 0);
 }
Exemplo n.º 5
0
        public static void Main(String [] args)
        {
            //Creating Objects from class
                                rover rover = new rover() ;
                                plateau plateau = new plateau () ;
                                movement movement = new movement () ;
                                constant constant = new constant() ;

                                //user input plateau size X
                                while(true){
                                    Console.WriteLine(constant.plateauXlength);
                                try{
                                    int plateausizeX = int.Parse(Console.ReadLine());
                                    plateau.setplateauXlength(plateausizeX);
                                    break;
                                }catch(FormatException ){
                                    Console.WriteLine("Enter a valid Plateau length for its X Length");
                            }
                        }

                                //user input plateau size Y
                                while(true){
                                   Console.WriteLine(constant.plateauYlength);
                                try{
                                    int plateausizeY = int.Parse(Console.ReadLine());
                                    plateau.setplateauYlength(plateausizeY);
                                    break;
                                }catch(FormatException  ){
                                    Console.WriteLine("Enter a valid Plateau length for its Y Length");
                            }
                        }

                              do{

                                //user input coordinate X of rover
                                while(true){
                                    Console.WriteLine(constant.messageroverX);
                                try{
                                    int xaxis = int.Parse(Console.ReadLine());
                                    if(xaxis == movement.CodX){
                                        Console.WriteLine("a Rover is already in the position");
                                    }else{

                                    if(xaxis > plateau.getplateauXlength() ){
                                        Console.WriteLine("Out of bound");
                                    }else{

                                    rover.setcoodX(xaxis);
                                    break;
                                    }}
                                }catch(FormatException  ){
                                    Console.WriteLine("Invalid X-Coordinate");
                                }
                            }

                                //user input from user for Coordinate Y for the rover
                                while(true){
                                    Console.WriteLine(constant.messageroverY);
                                try{
                                    int yaxis = int.Parse(Console.ReadLine());
                                    if(yaxis == movement.CodY){
                                      Console.WriteLine("a Rover is already in the position");
                                    }else{

                                     if(yaxis > plateau.getplateauYlength() ){
                                     Console.WriteLine("Out of bound");
                                     }else{
                                    rover.setcoodY(yaxis);
                                    break;
                                     }}
                                }catch(FormatException  ){
                                    Console.WriteLine("Invalid Y-Coordinate");
                            }
                        }

                                //user input where the rover is facing
                                while(true){
                          Console.WriteLine(constant.roverdirection);
                                    String roverfacing = Console.ReadLine();
                                    if( roverfacing.Equals("N")||roverfacing.Equals("S")||roverfacing.Equals("E")||roverfacing.Equals("W")){
                                    rover.setposition(roverfacing);
                                    break;
                                }else{
                                   Console.WriteLine("Enter Valid Position (i.e) N,S,E,W");
                            }
                        }

                                //rover movement on the plateau
                                movement.move(rover, plateau);

                                //wish to send another rover
                                Console.WriteLine("Do you want to send another rover on Mars? (yes/no)");
                              }while(Console.ReadLine().Equals("yes"));
        }
Exemplo n.º 6
0
 public void testSetcoodXAbnormal()
 {
     //Arrange
                                     rover rover = new rover();
                                     //Act
                                     rover.setcoodX(999999999);
                                     //Assert
                                     Assert.IsTrue(rover.getcoodX() == 999999999);
 }
Exemplo n.º 7
0
 public void testSetposition()
 {
     //Arrange
                                         rover rover = new rover();
                                         //Act
                                         rover.setposition("N");
                                         //Assert
                                         Assert.IsTrue(rover.getposition() == "N");
 }
Exemplo n.º 8
0
 public void testSetcoodXAbnormalSymbol()
 {
     //Arrange
                                             rover rover = new rover();
                                             //Act
                                             int a = int.Parse("#%$^&^%$^%");
                                             rover.setcoodX(a);
                                             //Assert
                                             Assert.IsTrue(rover.getcoodX() == a);
 }
Exemplo n.º 9
0
 public void testSetcoodXAbnormalString()
 {
     //Arrange
                                             rover rover = new rover () ;
                                             //Act
                                             int a =int.Parse("abc") ;
                                             rover.setcoodX(a);
                                             //Assert
                                             Assert.IsTrue( rover.getcoodX()== a);
 }
Exemplo n.º 10
0
 public void testSetcoodXAbnormalIsNull()
 {
     //Arrange
                                         rover rover = new rover();
                                         //Act
                                         int a = int.Parse("");
                                         rover.setcoodX(a);
                                         //Assert
                                         Assert.IsTrue(rover.getcoodX().Equals(a));
 }
Exemplo n.º 11
0
        public void move(rover rover,plateau plateau)
        {
            //Call the values x , y , and position thr rover is facing by creating an their objects

                                    int coordinateXrover = rover.getcoodX();
                                    int coordinateYrover = rover.getcoodY();
                                    CodX = coordinateXrover;
                                    CodY = coordinateYrover ;
                                    String roverfacingposition = rover.getposition();

                                    //Call the values of the plateau
                                    int lengthXplateau = plateau.getplateauXlength();
                                    int lengthYplateau = plateau.getplateauYlength();

                                    //declare a boolean that will contain TRUE or FALSE to be use in a while loop
                                    Boolean stop = false ;

                                    loop:while( stop != true){

                                    //continue to prompt user to enter command till stop is not equal to true
                                    Console.WriteLine("Enter your Command");
                                    String command = Console.ReadLine();

                                    //switch statment to check values 1 by 1
                                    switch(command){

                                                                  case "M" :
                                                                  {   if(roverfacingposition.Equals("N")){
                                                                                    if(coordinateYrover < lengthYplateau ){
                                                                                       coordinateYrover++;
                                                                                       }else{
                                                                                       Console.WriteLine("Error out of bound");
                                                                                            }

                                                                                }else if(roverfacingposition.Equals("E")){
                                                                                    if(coordinateXrover < lengthXplateau){
                                                                                            coordinateXrover++;
                                                                                        }else{
                                                                                                Console.WriteLine("Error out of bound");
                                                                                             }

                                                                                 }else if(roverfacingposition.Equals("S")){
                                                                                     if(coordinateYrover > 0 ){
                                                                                         coordinateYrover -- ;
                                                                                        }else{
                                                                                                Console.WriteLine("Error out of bound");
                                                                                             }
                                                                                 }else if(roverfacingposition.Equals("W")){
                                                                                      if(coordinateXrover > 0 )
                                                                                          coordinateXrover -- ;
                                                                                          }else{
                                                                                               Console.WriteLine("Error out of bound");
                                                                                               }

                                                                                 break ;
                                                                                }

                                                                  case "L": {            if(roverfacingposition.Equals("N")){
                                                                                        roverfacingposition = "W" ;
                                                                                        }else if(roverfacingposition.Equals("E")){
                                                                                        roverfacingposition = "N" ;
                                                                                        }else if(roverfacingposition.Equals("S")){
                                                                                        roverfacingposition = "E" ;
                                                                                        }else if(roverfacingposition.Equals("W")){
                                                                                        roverfacingposition = "S" ;
                                                                                        }

                                                                                    break ;
                                                                  }

                                                                  case "R":          {    if(roverfacingposition.Equals("N")){
                                                                                        roverfacingposition = "E" ;
                                                                                        }else if(roverfacingposition.Equals("E")){
                                                                                        roverfacingposition = "S" ;
                                                                                        }else if(roverfacingposition.Equals("S")){
                                                                                        roverfacingposition = "W" ;
                                                                                        }else if(roverfacingposition.Equals("W")){
                                                                                        roverfacingposition = "N" ;
                                                                                        }

                                                                                         break ;
                                                                                     }

                                                                  case "Q":
                                                                                 {
                                                                                     stop = true;
                                                                                     goto loop;

                                                                                 }

                                                                  default :  Console.WriteLine("Enter valid Command(i.e) Either R or L or M " );
                                                                                 break;
                                                                }

                                                       Console.WriteLine("rover is @ point (" +coordinateXrover+ ","+coordinateYrover+ " and facing "+roverfacingposition+" )");

                                                        }
        }