1 package org.apache.lucene.search; 2 3 18 19 import junit.framework.TestCase; 20 import org.apache.lucene.analysis.WhitespaceAnalyzer; 21 22 public class TestQueryTermVector extends TestCase { 23 24 25 public TestQueryTermVector(String s) { 26 super(s); 27 } 28 29 protected void setUp() { 30 } 31 32 protected void tearDown() { 33 34 } 35 36 public void testConstructor() { 37 String [] queryTerm = {"foo", "bar", "foo", "again", "foo", "bar", "go", "go", "go"}; 38 String [] gold = {"again", "bar", "foo", "go"}; 40 int [] goldFreqs = {1, 2, 3, 3}; 41 QueryTermVector result = new QueryTermVector(queryTerm); 42 assertTrue(result != null); 43 String [] terms = result.getTerms(); 44 assertTrue(terms.length == 4); 45 int [] freq = result.getTermFrequencies(); 46 assertTrue(freq.length == 4); 47 checkGold(terms, gold, freq, goldFreqs); 48 result = new QueryTermVector(null); 49 assertTrue(result.getTerms().length == 0); 50 51 result = new QueryTermVector("foo bar foo again foo bar go go go", new WhitespaceAnalyzer()); 52 assertTrue(result != null); 53 terms = result.getTerms(); 54 assertTrue(terms.length == 4); 55 freq = result.getTermFrequencies(); 56 assertTrue(freq.length == 4); 57 checkGold(terms, gold, freq, goldFreqs); 58 } 59 60 private void checkGold(String [] terms, String [] gold, int[] freq, int[] goldFreqs) { 61 for (int i = 0; i < terms.length; i++) { 62 assertTrue(terms[i].equals(gold[i])); 63 assertTrue(freq[i] == goldFreqs[i]); 64 } 65 } 66 } 67 | Popular Tags |