SOLR-2762: Adding more unit tests, but can't reproduce or figure out where off-by-one could happen here.

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1171066 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Dawid Weiss 2011-09-15 12:07:51 +00:00
parent 318911200d
commit e83e9dfbf3
1 changed files with 32 additions and 3 deletions

View File

@ -43,6 +43,12 @@ public class FSTLookupTest extends LuceneTestCase {
public void setUp() throws Exception {
super.setUp();
lookup = new FSTLookup();
lookup.build(new TermFreqArrayIterator(evalKeys()));
}
private TermFreq[] evalKeys() {
final TermFreq[] keys = new TermFreq[] {
tf("one", 0.5f),
tf("oneness", 1),
@ -61,9 +67,7 @@ public class FSTLookupTest extends LuceneTestCase {
tf("fourty", 1),
tf("xo", 1),
};
lookup = new FSTLookup();
lookup.build(new TermFreqArrayIterator(keys));
return keys;
}
public void testExactMatchHighPriority() throws Exception {
@ -76,6 +80,31 @@ public class FSTLookupTest extends LuceneTestCase {
"oneness/1.0");
}
public void testRequestedCount() throws Exception {
// 'one' is promoted after collecting two higher ranking results.
assertMatchEquals(lookup.lookup("one", true, 2),
"one/0.0",
"oneness/1.0");
// 'one' is at the top after collecting all alphabetical results.
assertMatchEquals(lookup.lookup("one", false, 2),
"one/0.0",
"oneness/1.0");
lookup = new FSTLookup(10, false);
lookup.build(new TermFreqArrayIterator(evalKeys()));
// 'one' is not promoted after collecting two higher ranking results.
assertMatchEquals(lookup.lookup("one", true, 2),
"oneness/1.0",
"onerous/1.0");
// 'one' is at the top after collecting all alphabetical results.
assertMatchEquals(lookup.lookup("one", false, 2),
"one/0.0",
"oneness/1.0");
}
public void testMiss() throws Exception {
assertMatchEquals(lookup.lookup("xyz", true, 1));
}