mirror of https://github.com/apache/lucene.git
LUCENE-5207: more tests
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene5207@1523357 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
bafedad9c9
commit
2f73532d52
|
@ -111,6 +111,44 @@ public class TestDemoExpressions extends LuceneTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
/** tests same binding used more than once in an expression */
|
||||
public void testTwoOfSameBinding() throws Exception {
|
||||
Expression expr = JavascriptCompiler.compile("_score + _score");
|
||||
|
||||
SimpleBindings bindings = new SimpleBindings();
|
||||
bindings.add(new SortField("_score", SortField.Type.SCORE));
|
||||
|
||||
Sort sort = new Sort(expr.getSortField(bindings, true));
|
||||
Query query = new TermQuery(new Term("body", "contents"));
|
||||
TopFieldDocs td = searcher.search(query, null, 3, sort, true, true);
|
||||
for (int i = 0; i < 3; i++) {
|
||||
FieldDoc d = (FieldDoc) td.scoreDocs[i];
|
||||
float expected = 2*d.score;
|
||||
float actual = ((Double)d.fields[0]).floatValue();
|
||||
assertEquals(expected, actual, CheckHits.explainToleranceDelta(expected, actual));
|
||||
}
|
||||
}
|
||||
|
||||
/** tests expression referring to another expression */
|
||||
public void testExpressionRefersToExpression() throws Exception {
|
||||
Expression expr1 = JavascriptCompiler.compile("_score");
|
||||
Expression expr2 = JavascriptCompiler.compile("2*expr1");
|
||||
|
||||
SimpleBindings bindings = new SimpleBindings();
|
||||
bindings.add(new SortField("_score", SortField.Type.SCORE));
|
||||
bindings.add("expr1", expr1);
|
||||
|
||||
Sort sort = new Sort(expr2.getSortField(bindings, true));
|
||||
Query query = new TermQuery(new Term("body", "contents"));
|
||||
TopFieldDocs td = searcher.search(query, null, 3, sort, true, true);
|
||||
for (int i = 0; i < 3; i++) {
|
||||
FieldDoc d = (FieldDoc) td.scoreDocs[i];
|
||||
float expected = 2*d.score;
|
||||
float actual = ((Double)d.fields[0]).floatValue();
|
||||
assertEquals(expected, actual, CheckHits.explainToleranceDelta(expected, actual));
|
||||
}
|
||||
}
|
||||
|
||||
/** tests huge amounts of variables in the expression */
|
||||
public void testLotsOfBindings() throws Exception {
|
||||
doTestLotsOfBindings(Byte.MAX_VALUE-1);
|
||||
|
|
|
@ -304,6 +304,10 @@ public class TestJavascriptOperations extends LuceneTestCase {
|
|||
assertEvaluatesTo("0x1", 1);
|
||||
assertEvaluatesTo("0xF", 15);
|
||||
assertEvaluatesTo("0x1234ABCDEF", 78193085935L);
|
||||
assertEvaluatesTo("1 << 0x1", 1 << 0x1);
|
||||
assertEvaluatesTo("1 << 0xA", 1 << 0xA);
|
||||
assertEvaluatesTo("0x1 << 2", 0x1 << 2);
|
||||
assertEvaluatesTo("0xA << 2", 0xA << 2);
|
||||
}
|
||||
|
||||
public void testHexConst2() throws Exception {
|
||||
|
@ -318,5 +322,10 @@ public class TestJavascriptOperations extends LuceneTestCase {
|
|||
assertEvaluatesTo("01", 1);
|
||||
assertEvaluatesTo("010", 8);
|
||||
assertEvaluatesTo("0123456777", 21913087);
|
||||
assertEvaluatesTo("1 << 01", 1 << 01);
|
||||
assertEvaluatesTo("1 << 010", 1 << 010);
|
||||
assertEvaluatesTo("01 << 2", 01 << 2);
|
||||
assertEvaluatesTo("010 << 2", 010 << 2);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue