コード例 #1
0
 @Test
 public void testParseCorrect() {
   try {
     testInstruction.parse("turn " + Rotation.LEFT);
     testInstruction.parse("girar " + Rotation.LEFT);
   } catch (WrongInstructionFormatException e) {
     fail("ERROR: A correct instruction throws an exception");
   }
 }
コード例 #2
0
 @Test
 public void testWronginstruction() {
   try {
     testInstruction.parse("gira left");
     fail("ERROR: A wrong instruction (gira left) does not throw an exception");
   } catch (WrongInstructionFormatException e) {
     // If we catch the exception then the parsing is correct
   }
 }
コード例 #3
0
 @Test
 public void testWrongParameter() {
   try {
     testInstruction.parse("turn izda");
     fail("ERROR: A turn instruction with a wrong parameter does not throw an exception");
   } catch (WrongInstructionFormatException e) {
     // If we catch the exception then the parsing is correct
   }
 }
コード例 #4
0
 @Test
 public void testGetHelp() {
   String help = testInstruction.getHelp();
   help.toUpperCase();
   assertTrue(
       "ERROR: getHelp returns a description which does not contain the word TURN",
       help.contains("TURN"));
   assertTrue(
       "ERROR: getHelp returns a description which does not contain the word GIRAR",
       help.contains("GIRAR"));
 }
コード例 #5
0
  @Test
  public void testTurnCorrect() {
    try {
      testInstruction = testInstruction.parse("turn right");
      testInstruction.configureContext(testEngine, testNavModule, null);
      testInstruction.execute();
      assertEquals(
          "ERROR: The robot is not heading to the correct direction after a turn instruction",
          Direction.EAST,
          testNavModule.getCurrentHeading());
      testInstruction = testInstruction.parse("turn left");
      testInstruction.configureContext(testEngine, testNavModule, null);
      testInstruction.execute();
      assertEquals(
          "ERROR: The robot is not heading to the correct direction after a turn instruction",
          Direction.NORTH,
          testNavModule.getCurrentHeading());

    } catch (WrongInstructionFormatException e) {
      fail("ERROR: parse throws an exception with a correct instruction");
    } catch (InstructionExecutionException e) {
      fail("ERROR: execute throws an exception when the action is correct");
    }
  }