コード例 #1
0
ファイル: TaskFactoryTest.java プロジェクト: dcbr/HillBillies
  @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());
  }
コード例 #2
0
ファイル: TaskFactoryTest.java プロジェクト: dcbr/HillBillies
  @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());
  }
コード例 #3
0
ファイル: TaskFactoryTest.java プロジェクト: dcbr/HillBillies
  @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());
  }
コード例 #4
0
ファイル: TaskFactoryTest.java プロジェクト: dcbr/HillBillies
 @Test
 public void createFriend() throws Exception {
   Faction fact = u.getFaction();
   Unit u2 = new Unit(w);
   while (fact != u2.getFaction()) u2 = new Unit(w);
   Expression<Unit> unit = f.createFriend(null);
   Statement stmt = f.createPrint(unit, null);
   runStatementFor(u, stmt, 0.1);
   System.out.println("The above test should print" + u2);
 }
コード例 #5
0
ファイル: TaskFactoryTest.java プロジェクト: dcbr/HillBillies
  @Test
  public void createAssignment() throws Exception {
    Statement a = f.createAssignment("assignment", new True(), null);

    runStatementFor(u, a, 0.2); // No exceptions

    // Check whether task successfully finished
    assertEquals(null, u.getTask());
    assertEquals(0, u.getFaction().getScheduler().getNbTasks());
  }
コード例 #6
0
ファイル: TaskFactoryTest.java プロジェクト: dcbr/HillBillies
  @Test
  public void createNextToPosition() throws Exception {
    Statement p = new Print(f.createNextToPosition(new PositionOfUnit(new This()), null));

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

    // Check whether task successfully finished
    assertEquals(null, u.getTask());
    assertEquals(0, u.getFaction().getScheduler().getNbTasks());
  }
コード例 #7
0
ファイル: TaskFactoryTest.java プロジェクト: dcbr/HillBillies
  @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());
  }
コード例 #8
0
ファイル: TaskFactoryTest.java プロジェクト: dcbr/HillBillies
  @Test
  public void createPrint() throws Exception {
    Statement print = f.createPrint(new True(), null);

    runStatementFor(u, print, 0.2);
    System.out.println("True should be printed.");

    // Check whether task successfully finished
    assertEquals(null, u.getTask());
    assertEquals(0, u.getFaction().getScheduler().getNbTasks());
  }
コード例 #9
0
ファイル: TaskFactoryTest.java プロジェクト: dcbr/HillBillies
  @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());
  }
コード例 #10
0
ファイル: TaskFactoryTest.java プロジェクト: dcbr/HillBillies
  @Test
  public void createSequence() throws Exception {
    Statement sequence =
        f.createSequence(Arrays.asList(new Print(new True()), new Print(new False())), null);

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

    // Check whether task successfully finished
    assertEquals(null, u.getTask());
    assertEquals(0, u.getFaction().getScheduler().getNbTasks());
  }
コード例 #11
0
ファイル: TaskFactoryTest.java プロジェクト: dcbr/HillBillies
  @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());
  }
コード例 #12
0
ファイル: TaskFactoryTest.java プロジェクト: dcbr/HillBillies
  @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());
  }
コード例 #13
0
ファイル: TaskFactoryTest.java プロジェクト: dcbr/HillBillies
  @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());
  }
コード例 #14
0
ファイル: TaskFactoryTest.java プロジェクト: dcbr/HillBillies
  @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)));
  }
コード例 #15
0
ファイル: TaskFactoryTest.java プロジェクト: dcbr/HillBillies
  @Test
  public void createReadVariable() throws Exception {
    Statement stmt =
        f.createSequence(
            Arrays.asList(
                f.createAssignment("w", new True(), null),
                new Print(f.createReadVariable("w", null))),
            null);

    runStatementFor(u, stmt, 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());
  }
コード例 #16
0
ファイル: TaskFactoryTest.java プロジェクト: dcbr/HillBillies
  @Test
  public void createAttack() throws Exception {
    Statement attack = f.createAttack(new Any(), null);

    Unit defender = new Unit(w, "Defender", new Vector(1, 0, 0));

    runStatementFor(u, attack, 0.1, 0.1);

    assertTrue(u.isAttacking());

    advanceTimeFor(w, 1.2);

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