lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ehatc...@apache.org
Subject cvs commit: jakarta-lucene/src/test/org/apache/lucene/search TestRangeQuery.java
Date Sat, 20 Sep 2003 21:12:41 GMT
ehatcher    2003/09/20 14:12:41

  Modified:    src/test/org/apache/lucene/search TestRangeQuery.java
  Log:
  streamlining test case a bit
  
  Revision  Changes    Path
  1.3       +41 -53    jakarta-lucene/src/test/org/apache/lucene/search/TestRangeQuery.java
  
  Index: TestRangeQuery.java
  ===================================================================
  RCS file: /home/cvs/jakarta-lucene/src/test/org/apache/lucene/search/TestRangeQuery.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TestRangeQuery.java	20 Sep 2003 20:29:34 -0000	1.2
  +++ TestRangeQuery.java	20 Sep 2003 21:12:41 -0000	1.3
  @@ -5,10 +5,10 @@
   import org.apache.lucene.document.Field;
   import org.apache.lucene.index.IndexWriter;
   import org.apache.lucene.index.Term;
  -import org.apache.lucene.store.Directory;
   import org.apache.lucene.store.RAMDirectory;
   
   import junit.framework.TestCase;
  +import java.io.IOException;
   
   /**
    * @author goller
  @@ -16,86 +16,74 @@
   public class TestRangeQuery extends TestCase {
   
     private int docCount = 0;
  +  private RAMDirectory dir;
   
  -  public void testExclusive() throws Exception {
  -    Directory dir = new RAMDirectory();
  -    Query query = new RangeQuery(new Term("content", "A"), new Term("content", "C"), false);
  -    Hits hits = null;
  -
  -    IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true);
  -    addDoc(writer, "A");
  -    addDoc(writer, "B");
  -    addDoc(writer, "C");
  -    addDoc(writer, "D");
  -    writer.close();
  +  public void setUp() {
  +    dir = new RAMDirectory();
  +  }
   
  +  public void testExclusive() throws Exception {
  +    Query query = new RangeQuery(new Term("content", "A"),
  +                                 new Term("content", "C"),
  +                                 false);
  +    initializeIndex(new String[] {"A", "B", "C", "D"});
       IndexSearcher searcher = new IndexSearcher(dir);
  -    hits = searcher.search(query);
  -    assertEquals(1, hits.length());
  +    Hits hits = searcher.search(query);
  +    assertEquals("A,B,C,D, only B in range", 1, hits.length());
       searcher.close();
   
  -    writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true);
  -    addDoc(writer, "A");
  -    addDoc(writer, "B");
  -    addDoc(writer, "D");
  -    writer.close();
  -
  +    initializeIndex(new String[] {"A", "B", "D"});
       searcher = new IndexSearcher(dir);
       hits = searcher.search(query);
  -    assertEquals(1, hits.length());
  +    assertEquals("A,B,D, only B in range", 1, hits.length());
       searcher.close();
   
  -    writer = new IndexWriter(dir, new WhitespaceAnalyzer(), false);
  -    addDoc(writer, "C");
  -    writer.close();
  -
  +    addDoc("C");
       searcher = new IndexSearcher(dir);
       hits = searcher.search(query);
  -    assertEquals(1, hits.length());
  +    assertEquals("C added, still only B in range", 1, hits.length());
       searcher.close();
     }
   
     public void testInclusive() throws Exception {
  -    Directory dir = new RAMDirectory();
  -    IndexWriter writer = null;
  -    Searcher searcher = null;
  -    Query query = new RangeQuery(new Term("content", "A"), new Term("content", "C"), true);
  -    Hits hits = null;
  -
  -    writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true);
  -    addDoc(writer, "A");
  -    addDoc(writer, "B");
  -    addDoc(writer, "C");
  -    addDoc(writer, "D");
  -    writer.close();
  +    Query query = new RangeQuery(new Term("content", "A"),
  +                                 new Term("content", "C"),
  +                                 true);
   
  +    initializeIndex(new String[]{"A", "B", "C", "D"});
  +    IndexSearcher searcher = new IndexSearcher(dir);
  +    Hits hits = searcher.search(query);
  +    assertEquals("A,B,C,D - A,B,C in range", 3, hits.length());
  +    searcher.close();
  +
  +    initializeIndex(new String[]{"A", "B", "D"});
       searcher = new IndexSearcher(dir);
       hits = searcher.search(query);
  -    assertEquals(3, hits.length());
  +    assertEquals("A,B,D - A and B in range", 2, hits.length());
       searcher.close();
   
  -    writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true);
  -    addDoc(writer, "A");
  -    addDoc(writer, "B");
  -    addDoc(writer, "D");
  -    writer.close();
  -
  +    addDoc("C");
       searcher = new IndexSearcher(dir);
       hits = searcher.search(query);
  -    assertEquals(2, hits.length());
  +    assertEquals("C added - A, B, C in range", 3, hits.length());
       searcher.close();
  +  }
   
  -    writer = new IndexWriter(dir, new WhitespaceAnalyzer(), false);
  -    addDoc(writer, "C");
  +  private void initializeIndex(String[] values) throws IOException {
  +    IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true);
  +    for (int i = 0; i < values.length; i++) {
  +      insertDoc(writer, values[i]);
  +    }
       writer.close();
  +  }
   
  -    searcher = new IndexSearcher(dir);
  -    hits = searcher.search(query);
  -    assertEquals(3, hits.length());
  -    searcher.close();
  +  private void addDoc(String content) throws IOException {
  +    IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), false);
  +    insertDoc(writer, content);
  +    writer.close();
     }
   
  -  private void addDoc(IndexWriter writer, String content) throws Exception {
  +  private void insertDoc(IndexWriter writer, String content) throws IOException {
       Document doc = new Document();
   
       doc.add(Field.Keyword("id", "id" + docCount));
  
  
  

Mime
View raw message