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 20:29:34 GMT
ehatcher    2003/09/20 13:29:34

  Modified:    src/test/org/apache/lucene/search TestRangeQuery.java
  Log:
  test case cleanup - no need to catch unexpected exceptions in test cases, let it fail
  
  Revision  Changes    Path
  1.2       +88 -121   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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestRangeQuery.java	10 Sep 2003 12:22:26 -0000	1.1
  +++ TestRangeQuery.java	20 Sep 2003 20:29:34 -0000	1.2
  @@ -1,11 +1,8 @@
   package org.apache.lucene.search;
   
  -import java.io.IOException;
  -
   import org.apache.lucene.analysis.WhitespaceAnalyzer;
   import org.apache.lucene.document.Document;
   import org.apache.lucene.document.Field;
  -import org.apache.lucene.index.IndexReader;
   import org.apache.lucene.index.IndexWriter;
   import org.apache.lucene.index.Term;
   import org.apache.lucene.store.Directory;
  @@ -14,128 +11,98 @@
   import junit.framework.TestCase;
   
   /**
  - *
    * @author goller
    */
   public class TestRangeQuery extends TestCase {
   
  -    private int docCount = 0;
  +  private int docCount = 0;
   
  -    public TestRangeQuery() {
  -        super();
  -    }
  -
  -    public void testNotInclusive()
  -    {
  -        Directory dir = new RAMDirectory();
  -        IndexWriter writer = null;
  -        Searcher searcher = null;
  -        Query query = new RangeQuery(new Term("content", "A"), new Term("content", "C"),
false);
  -        Hits hits = null;
  -
  -        try {
  -
  -          writer  = new IndexWriter(dir, new WhitespaceAnalyzer(), true);
  -          addDoc(writer, "A");
  -          addDoc(writer, "B");
  -          addDoc(writer, "C");
  -          addDoc(writer, "D");
  -          writer.close();
  -
  -          searcher = new IndexSearcher(dir);
  -          hits = searcher.search(query);
  -          assertEquals(1, hits.length());
  -          searcher.close();
  -
  -          writer  = new IndexWriter(dir, new WhitespaceAnalyzer(), true);
  -          addDoc(writer, "A");
  -          addDoc(writer, "B");
  -          addDoc(writer, "D");
  -          writer.close();
  -
  -          searcher = new IndexSearcher(dir);
  -          hits = searcher.search(query);
  -          assertEquals(1, hits.length());
  -          searcher.close();
  -
  -          writer  = new IndexWriter(dir, new WhitespaceAnalyzer(), false);
  -          addDoc(writer, "C");
  -          writer.close();
  -
  -          searcher = new IndexSearcher(dir);
  -          hits = searcher.search(query);
  -          assertEquals(1, hits.length());
  -          searcher.close();
  -
  -        }
  -        catch (IOException e) {
  -          e.printStackTrace();
  -        }
  -
  -    }
  -
  -    public void testInclusive()
  -    {
  -        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;
  -
  -        try {
  -
  -          writer  = new IndexWriter(dir, new WhitespaceAnalyzer(), true);
  -          addDoc(writer, "A");
  -          addDoc(writer, "B");
  -          addDoc(writer, "C");
  -          addDoc(writer, "D");
  -          writer.close();
  -
  -          searcher = new IndexSearcher(dir);
  -          hits = searcher.search(query);
  -          assertEquals(3, hits.length());
  -          searcher.close();
  -
  -          writer  = new IndexWriter(dir, new WhitespaceAnalyzer(), true);
  -          addDoc(writer, "A");
  -          addDoc(writer, "B");
  -          addDoc(writer, "D");
  -          writer.close();
  -
  -          searcher = new IndexSearcher(dir);
  -          hits = searcher.search(query);
  -          assertEquals(2, hits.length());
  -          searcher.close();
  -
  -          writer  = new IndexWriter(dir, new WhitespaceAnalyzer(), false);
  -          addDoc(writer, "C");
  -          writer.close();
  -
  -          searcher = new IndexSearcher(dir);
  -          hits = searcher.search(query);
  -          assertEquals(3, hits.length());
  -          searcher.close();
  -
  -        }
  -        catch (IOException e) {
  -          e.printStackTrace();
  -        }
  -    }
  -
  -    private void addDoc(IndexWriter writer, String content)
  -    {
  -      Document doc = new Document();
  -
  -      doc.add(Field.Keyword("id","id" + docCount));
  -      doc.add(Field.UnStored("content", content));
  -
  -      try {
  -        writer.addDocument(doc);
  -      }
  -      catch (IOException e) {
  -        e.printStackTrace();
  -      }
  -      docCount++;
  -    }
  +  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();
  +
  +    IndexSearcher searcher = new IndexSearcher(dir);
  +    hits = searcher.search(query);
  +    assertEquals(1, hits.length());
  +    searcher.close();
  +
  +    writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true);
  +    addDoc(writer, "A");
  +    addDoc(writer, "B");
  +    addDoc(writer, "D");
  +    writer.close();
  +
  +    searcher = new IndexSearcher(dir);
  +    hits = searcher.search(query);
  +    assertEquals(1, hits.length());
  +    searcher.close();
  +
  +    writer = new IndexWriter(dir, new WhitespaceAnalyzer(), false);
  +    addDoc(writer, "C");
  +    writer.close();
  +
  +    searcher = new IndexSearcher(dir);
  +    hits = searcher.search(query);
  +    assertEquals(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();
  +
  +    searcher = new IndexSearcher(dir);
  +    hits = searcher.search(query);
  +    assertEquals(3, hits.length());
  +    searcher.close();
  +
  +    writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true);
  +    addDoc(writer, "A");
  +    addDoc(writer, "B");
  +    addDoc(writer, "D");
  +    writer.close();
  +
  +    searcher = new IndexSearcher(dir);
  +    hits = searcher.search(query);
  +    assertEquals(2, hits.length());
  +    searcher.close();
  +
  +    writer = new IndexWriter(dir, new WhitespaceAnalyzer(), false);
  +    addDoc(writer, "C");
  +    writer.close();
  +
  +    searcher = new IndexSearcher(dir);
  +    hits = searcher.search(query);
  +    assertEquals(3, hits.length());
  +    searcher.close();
  +  }
  +
  +  private void addDoc(IndexWriter writer, String content) throws Exception {
  +    Document doc = new Document();
  +
  +    doc.add(Field.Keyword("id", "id" + docCount));
  +    doc.add(Field.UnStored("content", content));
  +
  +    writer.addDocument(doc);
  +    docCount++;
  +  }
   }
   
  
  
  

Mime
View raw message