public void parseAndPrintTest(Visitor[] visitors, AstPrinterInterface printer, boolean cmpInput)
      throws IOException, ParseException {
    System.out.println();
    System.out.println("Parser & Print test:");
    System.out.println("  Printer:    " + printer.getClass().getSimpleName());
    System.out.println();

    for (Test test : tests) {

      System.out.println("Testing: " + test.getName());

      ParserInterface p = new FullParser();
      p.addVisitors(Arrays.asList(visitors));

      AstNode r = p.parseArticle(test.getInput(), test.getName());

      StringWriter writer = new StringWriter();
      printer.print(r, writer);
      String result = writer.toString();

      if (cmpInput) {
        Assert.assertEquals(test.getInput(), result);
      } else {
        Assert.assertEquals(test.getResult(), result);
      }
    }

    System.out.println();
  }
Example #2
0
  public static void main(String[] args) {
    ActorWorld world = new ActorWorld();

    // Specify a
    //        Jumper jumper = new Jumper();
    //        world.add(new Location(5, 5), jumper);
    //        world.add(new Location(3, 5), new Rock());

    Test testSpecifyA =
        new Test(
            new JumperInfo[] {
              new JumperInfo(
                  new Location(5, 5), Location.NORTH, new Location(5, 5), Location.NORTHEAST)
            },
            null,
            new Location[] {new Location(3, 5)});

    if (testSpecifyA.getResult()) {
      System.out.println("test passed");
    }

    // Specify b
    //        Jumper jumper = new Jumper();
    //        world.add(new Location(1, 5), jumper);

    // Specify c
    //        Jumper jumper = new Jumper();
    //        world.add(new Location(0, 5), jumper);

    // Specify d
    //        Jumper jumperA = new Jumper(), jumperB = new Jumper(Color.RED);
    //        world.add(new Location(3, 2), jumperA);
    //        world.add(new Location(4, 2), new Rock());
    //        world.add(new Location(5, 2), jumperB);
    //
    //        Jumper jumperC = new Jumper(), jumperD = new Jumper(Color.RED);
    //        jumperC.setDirection(Location.SOUTH);
    //        jumperD.setDirection(Location.SOUTH);
    //        world.add(new Location(5, 5), jumperC);
    //        world.add(new Location(4, 5), new Rock());
    //        world.add(new Location(3, 5), jumperD);
    //
    //        Jumper jumperE = new Jumper(), jumperF = new Jumper(Color.RED);
    //        world.add(new Location(3, 8), jumperE);
    //        world.add(new Location(5, 8), jumperF);

    // Specify e
    //        Jumper jumperA = new Jumper(), jumperB = new Jumper(Color.RED);
    //        world.add(new Location(3, 2), jumperA);
    //        world.add(new Location(4, 2), jumperB);
    //
    //        Jumper jumperC = new Jumper(), jumperD = new Jumper(Color.RED);
    //        jumperC.setDirection(Location.SOUTH);
    //        jumperD.setDirection(Location.SOUTH);
    //        world.add(new Location(4, 5), jumperC);
    //        world.add(new Location(3, 5), jumperD);

    // two Actors in the front
    //        Jumper jumperA = new Jumper();
    //        world.add(new Location(5, 2), jumperA);
    //        world.add(new Location(4, 2), new Flower());
    //        world.add(new Location(3, 2), new Flower());
    //
    //        Jumper jumperB = new Jumper();
    //        world.add(new Location(5, 5), jumperB);
    //        world.add(new Location(4, 5), new Rock());
    //        world.add(new Location(3, 5), new Rock());
    //
    //        Jumper jumperC = new Jumper();
    //        world.add(new Location(5, 8), jumperC);
    //        world.add(new Location(4, 8), new Rock());
    //        world.add(new Location(3, 8), new Flower());

    // near edge
    //        Jumper jumperA = new Jumper();
    //        world.add(new Location(1, 3), jumperA);
    //
    //        Jumper jumperB = new Jumper();
    //        world.add(new Location(0, 6), jumperB);

    world.show();
  }