Exemplo n.º 1
0
 @Test(expected = IllegalArgumentException.class)
 public void createWhileIllegal() throws IllegalArgumentException {
   f.createWhile(
       new HerePosition(),
       new Print(new True()),
       null); // Dit gaat wel, maar gaat illegalArgumentException throwen
 }
Exemplo n.º 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());
  }
Exemplo n.º 3
0
  @Test
  public void createBreak() throws Exception {
    Expression<Boolean> condition = f.createTrue(null);
    Statement body = f.createIf(new CarriesItem(new This()), f.createBreak(null), null, null);
    Statement stmt = f.createWhile(condition, body, null);

    runStatementFor(u, stmt, 0.2);

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

    new Boulder(w, u);

    advanceTimeFor(w, 0.2);

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