@Test public void createIsAlive() throws Exception { Unit test = w.spawnUnit(false); Statement p = new Print( f.createIsAlive( 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 True"); // Check whether task successfully finished assertEquals(null, u.getTask()); assertEquals(0, u.getFaction().getScheduler().getNbTasks()); test.terminate(); advanceTimeFor(w, 0.2); 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()); }
@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()); }