示例#1
0
  @Test
  public void testEmptyStringStep() {
    Program emptyStringProgram = new Program(emptyString, robot);

    assertEquals(Orientation.RIGHT, robot.getOrientation());
    assertEquals(7300, robot.getAmountOfEnergy(), epsilon);

    emptyStringProgram.step();

    assertEquals(Orientation.RIGHT, robot.getOrientation());
    assertEquals(7300, robot.getAmountOfEnergy(), epsilon);

    emptyStringProgram.step();
    emptyStringProgram.step();
    emptyStringProgram.step();
    emptyStringProgram.step();
    emptyStringProgram.step();
    emptyStringProgram.step();
    emptyStringProgram.step();
    emptyStringProgram.step();
    emptyStringProgram.step();
    emptyStringProgram.step();

    assertEquals(Orientation.RIGHT, robot.getOrientation());
    assertEquals(7300, robot.getAmountOfEnergy(), epsilon);
  }
示例#2
0
  @Test
  public void testMoveStep() {
    robot = new Robot(new Energy(2400, unitOfPower.Ws), Orientation.RIGHT);
    robot.setPosition(Position.newPosition(3, 4, board));

    Program moveProgram = new Program(move, robot);
    robot.setProgram(moveProgram);

    assertEquals(1, Position.newPosition(3, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(4, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(5, 4, board).getElements().size());
    assertEquals(Orientation.RIGHT, robot.getOrientation());
    assertEquals(2400, robot.getAmountOfEnergy(), epsilon);

    moveProgram.step();

    assertEquals(0, Position.newPosition(3, 4, board).getElements().size());
    assertEquals(1, Position.newPosition(4, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(5, 4, board).getElements().size());
    assertEquals(Orientation.RIGHT, robot.getOrientation());
    assertEquals(1900, robot.getAmountOfEnergy(), epsilon);

    moveProgram.step();
    moveProgram.step();
    moveProgram.step();
    moveProgram.step();
    moveProgram.step();
    moveProgram.step();
    moveProgram.step();
    moveProgram.step();
    moveProgram.step();
    moveProgram.step();

    assertEquals(0, Position.newPosition(3, 4, board).getElements().size());
    assertEquals(1, Position.newPosition(4, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(5, 4, board).getElements().size());
    assertEquals(Orientation.RIGHT, robot.getOrientation());
    assertEquals(1900, robot.getAmountOfEnergy(), epsilon);
  }
示例#3
0
  @Test
  public void testWhileInSeqToString() {
    Program whileInSeqProgram = new Program(whileinseq, robot);

    assertTrue(whileinseq.equals(whileInSeqProgram.toString()));
  }
示例#4
0
  @Test
  public void testWhileInSeqStep() {
    robot = new Robot(new Energy(2400, unitOfPower.Ws), Orientation.RIGHT);
    robot.setPosition(Position.newPosition(3, 4, board));

    Program whileInSeqProgram = new Program(whileinseq, robot);
    robot.setProgram(whileInSeqProgram);

    assertEquals(1, Position.newPosition(3, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(4, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(5, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(6, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(7, 4, board).getElements().size());
    assertEquals(Orientation.RIGHT, robot.getOrientation());
    assertEquals(2400, robot.getAmountOfEnergy(), epsilon);

    whileInSeqProgram.step();

    assertEquals(0, Position.newPosition(3, 4, board).getElements().size());
    assertEquals(1, Position.newPosition(4, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(5, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(6, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(7, 4, board).getElements().size());
    assertEquals(Orientation.RIGHT, robot.getOrientation());
    assertEquals(1900, robot.getAmountOfEnergy(), epsilon);

    whileInSeqProgram.step();

    assertEquals(0, Position.newPosition(3, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(4, 4, board).getElements().size());
    assertEquals(1, Position.newPosition(5, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(6, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(7, 4, board).getElements().size());
    assertEquals(Orientation.RIGHT, robot.getOrientation());
    assertEquals(1400, robot.getAmountOfEnergy(), epsilon);

    whileInSeqProgram.step();

    assertEquals(0, Position.newPosition(3, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(4, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(5, 4, board).getElements().size());
    assertEquals(1, Position.newPosition(6, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(7, 4, board).getElements().size());
    assertEquals(Orientation.RIGHT, robot.getOrientation());
    assertEquals(900, robot.getAmountOfEnergy(), epsilon);

    whileInSeqProgram.step();

    assertEquals(0, Position.newPosition(3, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(4, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(5, 4, board).getElements().size());
    assertEquals(1, Position.newPosition(6, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(7, 4, board).getElements().size());
    assertEquals(Orientation.DOWN, robot.getOrientation());
    assertEquals(800, robot.getAmountOfEnergy(), epsilon);

    whileInSeqProgram.step();

    assertEquals(0, Position.newPosition(3, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(4, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(5, 4, board).getElements().size());
    assertEquals(1, Position.newPosition(6, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(7, 4, board).getElements().size());
    assertEquals(Orientation.DOWN, robot.getOrientation());
    assertEquals(800, robot.getAmountOfEnergy(), epsilon);

    whileInSeqProgram.step();
    whileInSeqProgram.step();
    whileInSeqProgram.step();
    whileInSeqProgram.step();
    whileInSeqProgram.step();
    whileInSeqProgram.step();
    whileInSeqProgram.step();
    whileInSeqProgram.step();
    whileInSeqProgram.step();
    whileInSeqProgram.step();

    assertEquals(0, Position.newPosition(3, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(4, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(5, 4, board).getElements().size());
    assertEquals(1, Position.newPosition(6, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(7, 4, board).getElements().size());
    assertEquals(Orientation.DOWN, robot.getOrientation());
    assertEquals(800, robot.getAmountOfEnergy(), epsilon);
  }
示例#5
0
  @Test
  public void testMoveToString() {
    Program moveProgram = new Program(move, robot);

    assertTrue(move.equals(moveProgram.toString()));
  }
示例#6
0
  @Test
  public void testGumpToString() {
    Program gumpProgram = new Program(gump, robot);

    assertTrue(gump.equals(gumpProgram.toString()));
  }
示例#7
0
  @Test
  public void testExampleInOneLineToString() {
    Program exampleInOneLineProgram = new Program(exampleinoneline, robot);

    assertTrue(example.equals(exampleInOneLineProgram.toString()));
  }
示例#8
0
  @Test
  public void testExampleInOneLineStep() {
    robot = new Robot(new Energy(3900, unitOfPower.Ws), Orientation.RIGHT);
    robot.setPosition(Position.newPosition(3, 4, board));

    Program exampleInOneLineProgram = new Program(example, robot);
    robot.setProgram(exampleInOneLineProgram);

    assertEquals(1, Position.newPosition(3, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(4, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(4, 5, board).getElements().size());
    assertEquals(0, Position.newPosition(3, 5, board).getElements().size());
    assertEquals(Orientation.RIGHT, robot.getOrientation());
    assertEquals(3900, robot.getAmountOfEnergy(), epsilon);

    exampleInOneLineProgram.step();

    assertEquals(0, Position.newPosition(3, 4, board).getElements().size());
    assertEquals(1, Position.newPosition(4, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(4, 5, board).getElements().size());
    assertEquals(0, Position.newPosition(3, 5, board).getElements().size());
    assertEquals(Orientation.RIGHT, robot.getOrientation());
    assertEquals(3400, robot.getAmountOfEnergy(), epsilon);

    exampleInOneLineProgram.step();

    assertEquals(0, Position.newPosition(3, 4, board).getElements().size());
    assertEquals(1, Position.newPosition(4, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(4, 5, board).getElements().size());
    assertEquals(0, Position.newPosition(3, 5, board).getElements().size());
    assertEquals(Orientation.DOWN, robot.getOrientation());
    assertEquals(3300, robot.getAmountOfEnergy(), epsilon);

    exampleInOneLineProgram.step();

    assertEquals(0, Position.newPosition(3, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(4, 4, board).getElements().size());
    assertEquals(1, Position.newPosition(4, 5, board).getElements().size());
    assertEquals(0, Position.newPosition(3, 5, board).getElements().size());
    assertEquals(Orientation.DOWN, robot.getOrientation());
    assertEquals(2800, robot.getAmountOfEnergy(), epsilon);

    exampleInOneLineProgram.step();

    assertEquals(0, Position.newPosition(3, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(4, 4, board).getElements().size());
    assertEquals(1, Position.newPosition(4, 5, board).getElements().size());
    assertEquals(0, Position.newPosition(3, 5, board).getElements().size());
    assertEquals(Orientation.LEFT, robot.getOrientation());
    assertEquals(2700, robot.getAmountOfEnergy(), epsilon);

    exampleInOneLineProgram.step();

    assertEquals(0, Position.newPosition(3, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(4, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(4, 5, board).getElements().size());
    assertEquals(1, Position.newPosition(3, 5, board).getElements().size());
    assertEquals(Orientation.LEFT, robot.getOrientation());
    assertEquals(2200, robot.getAmountOfEnergy(), epsilon);

    exampleInOneLineProgram.step();

    assertEquals(0, Position.newPosition(3, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(4, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(4, 5, board).getElements().size());
    assertEquals(1, Position.newPosition(3, 5, board).getElements().size());
    assertEquals(Orientation.UP, robot.getOrientation());
    assertEquals(2100, robot.getAmountOfEnergy(), epsilon);

    exampleInOneLineProgram.step();

    assertEquals(1, Position.newPosition(3, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(4, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(4, 5, board).getElements().size());
    assertEquals(0, Position.newPosition(3, 5, board).getElements().size());
    assertEquals(Orientation.UP, robot.getOrientation());
    assertEquals(1600, robot.getAmountOfEnergy(), epsilon);

    exampleInOneLineProgram.step();

    assertEquals(1, Position.newPosition(3, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(4, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(4, 5, board).getElements().size());
    assertEquals(0, Position.newPosition(3, 5, board).getElements().size());
    assertEquals(Orientation.RIGHT, robot.getOrientation());
    assertEquals(1500, robot.getAmountOfEnergy(), epsilon);

    exampleInOneLineProgram.step();

    assertEquals(0, Position.newPosition(3, 4, board).getElements().size());
    assertEquals(1, Position.newPosition(4, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(4, 5, board).getElements().size());
    assertEquals(0, Position.newPosition(3, 5, board).getElements().size());
    assertEquals(Orientation.RIGHT, robot.getOrientation());
    assertEquals(1000, robot.getAmountOfEnergy(), epsilon);

    exampleInOneLineProgram.step();

    assertEquals(0, Position.newPosition(3, 4, board).getElements().size());
    assertEquals(1, Position.newPosition(4, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(4, 5, board).getElements().size());
    assertEquals(0, Position.newPosition(3, 5, board).getElements().size());
    assertEquals(Orientation.DOWN, robot.getOrientation());
    assertEquals(900, robot.getAmountOfEnergy(), epsilon);

    exampleInOneLineProgram.step();
    exampleInOneLineProgram.step();
    exampleInOneLineProgram.step();
    exampleInOneLineProgram.step();
    exampleInOneLineProgram.step();
    exampleInOneLineProgram.step();
    exampleInOneLineProgram.step();
    exampleInOneLineProgram.step();
    exampleInOneLineProgram.step();
    exampleInOneLineProgram.step();

    assertEquals(0, Position.newPosition(3, 4, board).getElements().size());
    assertEquals(1, Position.newPosition(4, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(4, 5, board).getElements().size());
    assertEquals(0, Position.newPosition(3, 5, board).getElements().size());
    assertEquals(Orientation.DOWN, robot.getOrientation());
    assertEquals(900, robot.getAmountOfEnergy(), epsilon);

    exampleInOneLineProgram.step();

    assertEquals(0, Position.newPosition(3, 4, board).getElements().size());
    assertEquals(1, Position.newPosition(4, 4, board).getElements().size());
    assertEquals(0, Position.newPosition(4, 5, board).getElements().size());
    assertEquals(0, Position.newPosition(3, 5, board).getElements().size());
    assertEquals(Orientation.DOWN, robot.getOrientation());
    assertEquals(900, robot.getAmountOfEnergy(), epsilon);
  }
示例#9
0
  @Test
  public void testExample4SpaceExtraNewLinesToString() {
    Program example4SpaceExtraNewLinesProgram = new Program(example4spaceextranewlines, robot);

    assertTrue(example.equals(example4SpaceExtraNewLinesProgram.toString()));
  }
示例#10
0
  @Test
  public void testCowboyStep() {
    robot = new Robot(new Energy(15700, unitOfPower.Ws), Orientation.RIGHT);
    robot.setPosition(Position.newPosition(3, 4, board));
    board.putElement(
        Position.newPosition(3, 2, board),
        new Robot(new Energy(5000, unitOfPower.Ws), Orientation.LEFT));
    board.putElement(
        Position.newPosition(5, 4, board),
        new Robot(new Energy(5000, unitOfPower.Ws), Orientation.LEFT));
    board.putElement(
        Position.newPosition(3, 6, board),
        new Robot(new Energy(5000, unitOfPower.Ws), Orientation.LEFT));

    Program cowboyProgram = new Program(cowboy, robot);
    robot.setProgram(cowboyProgram);

    assertEquals(4, board.getElementsOf(Robot.class).size());
    assertEquals(Orientation.RIGHT, robot.getOrientation());
    assertEquals(15700, robot.getAmountOfEnergy(), epsilon);

    cowboyProgram.step();

    assertEquals(4, board.getElementsOf(Robot.class).size());
    assertEquals(Orientation.RIGHT, robot.getOrientation());
    assertEquals(14700, robot.getAmountOfEnergy(), epsilon);

    cowboyProgram.step();

    assertEquals(4, board.getElementsOf(Robot.class).size());
    assertEquals(Orientation.RIGHT, robot.getOrientation());
    assertEquals(13700, robot.getAmountOfEnergy(), epsilon);

    cowboyProgram.step();

    assertEquals(4, board.getElementsOf(Robot.class).size());
    assertEquals(Orientation.RIGHT, robot.getOrientation());
    assertEquals(12700, robot.getAmountOfEnergy(), epsilon);

    cowboyProgram.step();

    assertEquals(4, board.getElementsOf(Robot.class).size());
    assertEquals(Orientation.RIGHT, robot.getOrientation());
    assertEquals(11700, robot.getAmountOfEnergy(), epsilon);

    cowboyProgram.step();

    assertEquals(3, board.getElementsOf(Robot.class).size());
    assertEquals(Orientation.RIGHT, robot.getOrientation());
    assertEquals(10700, robot.getAmountOfEnergy(), epsilon);

    cowboyProgram.step();

    assertEquals(3, board.getElementsOf(Robot.class).size());
    assertEquals(Orientation.DOWN, robot.getOrientation());
    assertEquals(10600, robot.getAmountOfEnergy(), epsilon);

    cowboyProgram.step();

    assertEquals(3, board.getElementsOf(Robot.class).size());
    assertEquals(Orientation.DOWN, robot.getOrientation());
    assertEquals(9600, robot.getAmountOfEnergy(), epsilon);

    cowboyProgram.step();

    assertEquals(3, board.getElementsOf(Robot.class).size());
    assertEquals(Orientation.DOWN, robot.getOrientation());
    assertEquals(8600, robot.getAmountOfEnergy(), epsilon);

    cowboyProgram.step();

    assertEquals(3, board.getElementsOf(Robot.class).size());
    assertEquals(Orientation.DOWN, robot.getOrientation());
    assertEquals(7600, robot.getAmountOfEnergy(), epsilon);

    cowboyProgram.step();

    assertEquals(3, board.getElementsOf(Robot.class).size());
    assertEquals(Orientation.DOWN, robot.getOrientation());
    assertEquals(6600, robot.getAmountOfEnergy(), epsilon);

    cowboyProgram.step();

    assertEquals(2, board.getElementsOf(Robot.class).size());
    assertEquals(Orientation.DOWN, robot.getOrientation());
    assertEquals(5600, robot.getAmountOfEnergy(), epsilon);

    cowboyProgram.step();

    assertEquals(2, board.getElementsOf(Robot.class).size());
    assertEquals(Orientation.LEFT, robot.getOrientation());
    assertEquals(5500, robot.getAmountOfEnergy(), epsilon);

    cowboyProgram.step();

    assertEquals(2, board.getElementsOf(Robot.class).size());
    assertEquals(Orientation.UP, robot.getOrientation());
    assertEquals(5400, robot.getAmountOfEnergy(), epsilon);

    cowboyProgram.step();
    cowboyProgram.step();
    cowboyProgram.step();
    cowboyProgram.step();
    cowboyProgram.step();

    assertEquals(1, board.getElementsOf(Robot.class).size());
    assertEquals(Orientation.UP, robot.getOrientation());
    assertEquals(400, robot.getAmountOfEnergy(), epsilon);

    cowboyProgram.step();
    cowboyProgram.step();
    cowboyProgram.step();
    cowboyProgram.step();

    assertEquals(1, board.getElementsOf(Robot.class).size());
    assertEquals(Orientation.UP, robot.getOrientation());
    assertEquals(0, robot.getAmountOfEnergy(), epsilon);

    cowboyProgram.step();
    cowboyProgram.step();
    cowboyProgram.step();
    cowboyProgram.step();
    cowboyProgram.step();
    cowboyProgram.step();
    cowboyProgram.step();
    cowboyProgram.step();
    cowboyProgram.step();
    cowboyProgram.step();

    assertEquals(1, board.getElementsOf(Robot.class).size());
    assertEquals(Orientation.UP, robot.getOrientation());
    assertEquals(0, robot.getAmountOfEnergy(), epsilon);
  }
示例#11
0
  @Test
  public void testExampleToString() {
    Program exampleProgram = new Program(example, robot);

    assertTrue(example.equals(exampleProgram.toString()));
  }
示例#12
0
  @Test
  public void testEmptyStringToString() {
    Program emptyStringProgram = new Program(emptyString, robot);

    assertTrue(emptyString.equals(emptyStringProgram.toString()));
  }
示例#13
0
  @Test
  public void testCowboyToString() {
    Program cowboyProgram = new Program(cowboy, robot);

    assertTrue(cowboy.equals(cowboyProgram.toString()));
  }