Package it.unimi.dsi.mg4j.search

Source Code of it.unimi.dsi.mg4j.search.NotDocumentIteratorTest

package it.unimi.dsi.mg4j.search;

import it.unimi.dsi.mg4j.search.DocumentIterator;
import it.unimi.dsi.mg4j.search.IntervalIterators;
import it.unimi.dsi.mg4j.search.NotDocumentIterator;

import java.io.IOException;

import junit.framework.TestCase;

public class NotDocumentIteratorTest extends TestCase {

  public void testNot() throws IOException {
    DocumentIterator i = new IntArrayDocumentIterator( new int[] { 2, 4, 7 },
        new int[][][] {
        { { 0, 1 }, { 1, 2 } },
        { { 1, 2 } },
        { {} },
        } );
   
    NotDocumentIterator notDocumentIterator = NotDocumentIterator.getInstance( i, 8 );
    assertEquals( 0, notDocumentIterator.nextDocument() );
    assertEquals( 0, notDocumentIterator.document() );
    assertEquals( IntervalIterators.TRUE, notDocumentIterator.intervalIterator() );
    assertEquals( 1, notDocumentIterator.nextDocument() );
    assertEquals( IntervalIterators.TRUE, notDocumentIterator.intervalIterator() );
    assertEquals( 3, notDocumentIterator.nextDocument() );
    assertEquals( IntervalIterators.TRUE, notDocumentIterator.intervalIterator() );
    assertEquals( 5, notDocumentIterator.nextDocument() );
    assertEquals( 5, notDocumentIterator.document() );
    assertEquals( IntervalIterators.TRUE, notDocumentIterator.intervalIterator() );
    assertEquals( 6, notDocumentIterator.nextDocument() );
    assertEquals( IntervalIterators.TRUE, notDocumentIterator.intervalIterator() );
    assertFalse( notDocumentIterator.hasNext() );
    notDocumentIterator.dispose();
  }
 
  public void testSkip() throws IOException {
    DocumentIterator i = new IntArrayDocumentIterator( new int[] { 2, 4, 7 },
        new int[][][] {
        { { 0, 1 }, { 1, 2 } },
        { { 1, 2 } },
        { {} },
        } );
   
    NotDocumentIterator notDocumentIterator = NotDocumentIterator.getInstance( i, 9 );
 
    assertEquals( 3, notDocumentIterator.skipTo( 3 ) );
    assertEquals( IntervalIterators.TRUE, notDocumentIterator.intervalIterator() );
    assertEquals( 3, notDocumentIterator.skipTo( 2 ) );
    assertEquals( 8, notDocumentIterator.skipTo( 8 ) );
    assertEquals( Integer.MAX_VALUE, notDocumentIterator.skipTo( 9 ) );
  }
 
  public void testSkipAtStart() throws IOException {
    DocumentIterator i = new IntArrayDocumentIterator( new int[] { 0, 3 },
        new int[][][] {
        { { 0 } },
        { { 0 } },
        } );
   
    NotDocumentIterator notDocumentIterator = NotDocumentIterator.getInstance( i, 9 );
    notDocumentIterator.hasNext();
    assertEquals( 1, notDocumentIterator.skipTo( 0 ) );
  }
 
}
TOP

Related Classes of it.unimi.dsi.mg4j.search.NotDocumentIteratorTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.