예제 #1
0
  @Test
  public void createIf() throws Exception {
    Expression<Boolean> condition = f.createCarriesItem(f.createThis(null), null);
    Statement ifBody = f.createWork(new LiteralPosition(1, 0, 0), null);
    Statement elseBody = f.createMoveTo(new LiteralPosition(0, 1, 0), null);
    Statement stmt = f.createIf(condition, ifBody, elseBody, null);

    new Boulder(w, u);
    runStatementFor(u, stmt, 1 + 500 / u.getStrength());

    // Check whether ifBody is executed:
    assertEquals(new Vector(0, 0, 0), u.getPosition().getCubeCoordinates());
    assertFalse(u.isCarryingBoulder());
    // Check whether task successfully finished
    assertEquals(null, u.getTask());
    assertEquals(0, u.getFaction().getScheduler().getNbTasks());

    u.stopDefaultBehaviour();

    runStatementFor(u, stmt, 2);

    // Check whether elseBody is executed:
    assertEquals(new Vector(0, 1, 0), u.getPosition().getCubeCoordinates());
    assertFalse(u.isCarryingBoulder());
    // Check whether task successfully finished
    assertEquals(null, u.getTask());
    assertEquals(0, u.getFaction().getScheduler().getNbTasks());
  }
예제 #2
0
 @Test
 public void createPositionOf() throws Exception {
   Expression<Unit> unit = f.createThis(null);
   Expression<Vector> pos = f.createPositionOf(unit, null);
   Statement stmt = f.createPrint(pos, null);
   runStatementFor(u, stmt, 0.1);
   System.out.println("The above test should print" + u.getPosition());
 }
예제 #3
0
  @Test
  public void createHerePosition() throws Exception {
    Statement p = new Print(f.createHerePosition(null));

    runStatementFor(u, p, 0.2);
    System.out.println("The above should print " + u.getPosition());

    // Check whether task successfully finished
    assertEquals(null, u.getTask());
    assertEquals(0, u.getFaction().getScheduler().getNbTasks());
  }
예제 #4
0
  @Test
  public void createMoveTo() throws Exception {
    Statement move = f.createMoveTo(new LiteralPosition(0, 1, 0), null);

    runStatementFor(u, move, 2);

    // Check whether task successfully finished
    assertEquals(null, u.getTask());
    assertEquals(0, u.getFaction().getScheduler().getNbTasks());
    assertEquals(new Vector(0, 1, 0), u.getPosition().getCubeCoordinates());
  }
예제 #5
0
  @Test
  public void createIsPassable() throws Exception {
    Expression<Boolean> condition = f.createIsPassable(new LiteralPosition(1, 0, 0), null);
    Statement ifBody = new MoveTo(new LiteralPosition(1, 0, 0));
    Statement stmt = f.createIf(condition, ifBody, null, null);

    runStatementFor(u, stmt, 2);

    // Check whether task successfully finished
    assertEquals(null, u.getTask());
    assertEquals(0, u.getFaction().getScheduler().getNbTasks());
    assertEquals(new Vector(1, 0, 0), u.getPosition().getCubeCoordinates());
  }
예제 #6
0
  @Test
  public void createFollow() throws Exception {
    Statement follow = f.createFollow(new Any(), null);

    Unit test = new Unit(w, "Test", new Vector(2, 2, 0));

    runStatementFor(u, follow, 6);

    // Check whether task successfully finished
    assertEquals(null, u.getTask());
    assertEquals(0, u.getFaction().getScheduler().getNbTasks());
    assertTrue(
        w.getNeighbouringCubesPositions(u.getPosition().getCubeCoordinates())
            .contains(new Vector(2, 2, 0)));
  }