Пример #1
0
  @Test
  public void testGetListLawnMowerWithLongInstruction() throws Exception {

    List<Paire<List<Instruction>, LawnMower>> listLawnMowerWithInstruction =
        parser.getListLawnMowerWithInstruction();

    assertThat(listLawnMowerWithInstruction).hasSize(2);
    assertThat(listLawnMowerWithInstruction.get(0).getLeftElement())
        .containsSequence(
            Instruction.G,
            Instruction.A,
            Instruction.G,
            Instruction.A,
            Instruction.G,
            Instruction.A,
            Instruction.G,
            Instruction.A,
            Instruction.A);
    assertThat(listLawnMowerWithInstruction.get(1).getLeftElement())
        .containsSequence(
            Instruction.A,
            Instruction.A,
            Instruction.D,
            Instruction.A,
            Instruction.A,
            Instruction.D,
            Instruction.A,
            Instruction.D,
            Instruction.D,
            Instruction.A);
  }
Пример #2
0
  @Test
  public void testGetListLawnMowerWithShortInstruction() throws Exception {

    inputDataList = Lists.newArrayList("5 5", "1 1 N", "A");
    parser = new MowItNowParser(inputDataList);

    List<Paire<List<Instruction>, LawnMower>> listLawnMowerWithInstruction =
        parser.getListLawnMowerWithInstruction();

    assertThat(listLawnMowerWithInstruction).hasSize(1);
    assertThat(listLawnMowerWithInstruction.get(0).getLeftElement())
        .containsSequence(Instruction.A);
  }
Пример #3
0
  public void execute(final Reader in, final PrintStream out)
      throws ParseException, HandlerException {

    parser.parse(
        in,
        new MowItNowHandler() {

          private Grid grid;
          private Mower mower;

          @Override
          public void order(Order order) throws HandlerException {
            try {
              mower = executor.execute(grid, mower, order);
            } catch (ExecutionException e) {
              throw new HandlerException(e);
            }
          }

          @Override
          public void endMower() throws HandlerException {
            out.println(MowItNowApp.this.toString(mower));
          }

          @Override
          public void end() {}

          @Override
          public void beginMower(Mower mower) {
            this.mower = mower;
          }

          @Override
          public void begin(Grid grid) {
            this.grid = grid;
          }
        });
  }
Пример #4
0
  @Test
  public void testGetArea() throws Exception {

    assertThat(parser.getArea()).isEqualsToByComparingFields(new Area(5, 5));
  }