IfBlock implements Block { @Override public PieceCount getPieceCount() { PieceCount thenCount = thenBlock.getPieceCount(); PieceCount elseCount = elseBlock.getPieceCount(); return thenCount.equals(elseCount) ? thenCount : PieceCount.createUnknownCount(); } IfBlock(
      Supplier<Boolean> condition, Block thenBlock, Block elseBlock);  IfBlock(Supplier<Boolean> condition, Block thenBlock); @Override Iterator<AbstractPiece> iterator(); @Override void forAllPossiblePieces(Consumer<AbstractPiece> consumer); @Override PieceCount getPieceCount(); @Override String toString();  }
@Test public void testIfBlockThen() throws Exception { Piece piece1 = new Piece(); Piece piece2 = new Piece(); Block ifBlock = new IfBlock( TRUE_SUPPLIER, new SequenceBlock(piece1, piece2) ); BlockTestingUtils.testIndependence( Arrays.asList(piece1, piece2), ifBlock); Assert.assertFalse(ifBlock.getPieceCount().isKnown()); }
@Test public void testIfBlockElse() throws Exception { Piece piece1 = new Piece(); Piece piece2 = new Piece(); Block ifBlock = new IfBlock( FALSE_SUPPLIER, new EmptyBlock(), new SequenceBlock(piece1, piece2) ); BlockTestingUtils.testIndependence( Arrays.asList(piece1, piece2), ifBlock); Assert.assertFalse(ifBlock.getPieceCount().isKnown()); }
@Test public void testIfNestedInRepeat() throws Exception { Piece piece1 = new Piece(); Piece piece2 = new Piece(); Block ifBlock = new IfBlock( TRUE_SUPPLIER, new SequenceBlock(piece1, piece2) ); BlockTestingUtils.testNestedRepeatBlock( Arrays.asList(piece1, piece2), ifBlock); Assert.assertFalse(ifBlock.getPieceCount().isKnown()); }
@Test public void testIfThenElsePieceCount() { Piece piece1 = new Piece(); Piece piece2 = new Piece(); Block ifBlock = new IfBlock( TRUE_SUPPLIER, piece1, piece2 ); Assert.assertTrue(ifBlock.getPieceCount().isKnown()); Assert.assertEquals(1, ifBlock.getPieceCount().getCount()); }