import junit.framework.TestCase;
public class DifferenceDocumentIteratorTest extends TestCase {
public void testdifference() throws IOException {
DocumentIterator minuendIterator = new IntArrayDocumentIterator( new int[] { 0, 1, 2, 3 },
new int[][][] {
{ { 0, 1 } },
{ { 0, 1 }, { 1, 2 }, { 2, 3 } },
{ { 0, 1 }, { 1, 2 }, { 2, 3 } },
{ { 0 } }
} );
DocumentIterator subtrahendIterator = new IntArrayDocumentIterator( new int[] { 1, 2 },
new int[][][] {
{ { 1 } },
{ { 1, 3 } }
} );
DocumentIterator differenceIterator = DifferenceDocumentIterator.getInstance( minuendIterator, subtrahendIterator );
assertTrue( differenceIterator.hasNext() );
assertTrue( differenceIterator.hasNext() ); // To increase coverage
assertEquals( 0, differenceIterator.nextDocument() );
assertEquals( 0, differenceIterator.document() );
assertEquals( Interval.valueOf( 0, 1 ), differenceIterator.intervalIterator().nextInterval() );
assertFalse( differenceIterator.intervalIterator().hasNext() );
assertEquals( 1, differenceIterator.nextDocument() );
assertEquals( 1, differenceIterator.document() );
assertEquals( Interval.valueOf( 2, 3 ), differenceIterator.intervalIterator().nextInterval() );
assertFalse( differenceIterator.intervalIterator().hasNext() );
assertEquals( 2, differenceIterator.nextDocument() );
assertEquals( 2, differenceIterator.document() );
assertEquals( Interval.valueOf( 0, 1 ), differenceIterator.intervalIterator().nextInterval() );
assertEquals( Interval.valueOf( 1, 2 ), differenceIterator.intervalIterator().nextInterval() );
assertEquals( Interval.valueOf( 2, 3 ), differenceIterator.intervalIterator().nextInterval() );
assertFalse( differenceIterator.intervalIterator().hasNext() );
assertEquals( 3, differenceIterator.nextDocument() );
assertEquals( 3, differenceIterator.document() );
assertEquals( Interval.valueOf( 0 ), differenceIterator.intervalIterator().nextInterval() );
assertFalse( differenceIterator.intervalIterator().hasNext() );
assertFalse( differenceIterator.hasNext() ); // To increase coverage
}