Beispiel #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());
  }
Beispiel #2
0
  @Test
  public void createWhile() throws Exception {
    // new While(new HerePosition(),new Print(new True()));// Dit lukt niet
    new While(new False(), new Print(new False()));

    Expression<Boolean> condition = f.createIsAlive(f.createAny(null), null);
    Statement body = f.createPrint(new LiteralPosition(0, 0, 0), null);
    Statement whileStmt = f.createWhile(condition, body, null);

    Unit test = w.spawnUnit(false);

    runStatementFor(u, whileStmt, 0.1, 0.01); // No exceptions

    // Task is still running:
    assertTrue(u.getTask() != null);
    assertEquals(1, u.getFaction().getScheduler().getNbTasks());

    test.terminate();

    advanceTimeFor(w, 0.1, 0.01);

    // Check whether task successfully finished
    assertEquals(null, u.getTask());
    assertEquals(0, u.getFaction().getScheduler().getNbTasks());
  }
Beispiel #3
0
  @Test
  public void createBoulderPosition() throws Exception {
    Statement p = new Print(f.createBoulderPosition(null));

    new Boulder(w, w.getCube(new Vector(1, 0, 0)));

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

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

    new Boulder(w, w.getCube(new Vector(1, 0, 0)));

    runStatementFor(u, work, 1 + 500 / u.getStrength());

    // Check whether task successfully finished
    assertEquals(null, u.getTask());
    assertEquals(0, u.getFaction().getScheduler().getNbTasks());
    assertTrue(u.isCarryingBoulder());
  }
Beispiel #5
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)));
  }