Ejemplo n.º 1
0
  @Test
  public void createCarriesItem() throws Exception {
    Unit test = w.spawnUnit(false);
    Statement p =
        new Print(
            f.createCarriesItem(
                new Expression<Unit>(Unit.class) {
                  @Override
                  public Unit evaluate() throws NullPointerException {
                    return test;
                  }
                },
                null));

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

    // Check whether task successfully finished
    assertEquals(null, u.getTask());
    assertEquals(0, u.getFaction().getScheduler().getNbTasks());

    new Boulder(w, test);
    advanceTimeFor(w, 0.2);

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

    // Check whether task successfully finished
    assertEquals(null, u.getTask());
    assertEquals(0, u.getFaction().getScheduler().getNbTasks());
  }
Ejemplo n.º 2
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());
  }