FileDocCategorySizeDatePackage
EdgeNGramTokenizerTest.javaAPI DocApache Lucene 2.1.02790Wed Feb 14 10:46:26 GMT 2007org.apache.lucene.analysis.ngram

EdgeNGramTokenizerTest

public class EdgeNGramTokenizerTest extends TestCase
Tests {@link EdgeNGramTokenizer} for correctness.
author
Otis Gospodnetic

Fields Summary
private StringReader
input
Constructors Summary
Methods Summary
public voidsetUp()

        input = new StringReader("abcde");
    
public voidtestBackUnigram()

        EdgeNGramTokenizer tokenizer = new EdgeNGramTokenizer(input, EdgeNGramTokenizer.Side.BACK, 1);
        Token token = null;
        token = tokenizer.next();
        assertEquals("(e,4,5)", token.toString());
        token = tokenizer.next();
        assertNull(token);
    
public voidtestFrontUnigram()

        EdgeNGramTokenizer tokenizer = new EdgeNGramTokenizer(input, EdgeNGramTokenizer.Side.FRONT, 1);
        Token token = null;
        token = tokenizer.next();
        assertEquals("(a,0,1)", token.toString());
        token = tokenizer.next();
        assertNull(token);
    
public voidtestInvalidInput()

        boolean gotException = false;
        try {        
            new EdgeNGramTokenizer(input, EdgeNGramTokenizer.Side.FRONT, 0);
        } catch (IllegalArgumentException e) {
            gotException = true;
        }
        assertTrue(gotException);
    
public voidtestInvalidInput2()

        boolean gotException = false;
        try {        
            new EdgeNGramTokenizer(input, EdgeNGramTokenizer.Side.FRONT, -1);
        } catch (IllegalArgumentException e) {
            gotException = true;
        }
        assertTrue(gotException);
    
public voidtestOversizedNgrams()

        EdgeNGramTokenizer tokenizer = new EdgeNGramTokenizer(input, EdgeNGramTokenizer.Side.FRONT, 6);
        Token token = null;
        token = tokenizer.next();
        assertNull(token);