use of org.apache.solr.client.solrj.io.eval.StreamEvaluator in project lucene-solr by apache.
the class TemporalEvaluatorsTest method testInvalidExpression.
@Test
public void testInvalidExpression() throws Exception {
StreamEvaluator evaluator;
try {
evaluator = factory.constructEvaluator("week()");
StreamContext streamContext = new StreamContext();
evaluator.setStreamContext(streamContext);
assertTrue(false);
} catch (IOException e) {
assertTrue(e.getCause().getCause().getMessage().contains("Invalid expression week()"));
}
try {
evaluator = factory.constructEvaluator("week(a, b)");
StreamContext streamContext = new StreamContext();
evaluator.setStreamContext(streamContext);
assertTrue(false);
} catch (IOException e) {
assertTrue(e.getCause().getCause().getMessage().contains("expecting one value but found 2"));
}
try {
evaluator = factory.constructEvaluator("Week()");
StreamContext streamContext = new StreamContext();
evaluator.setStreamContext(streamContext);
assertTrue(false);
} catch (IOException e) {
assertTrue(e.getMessage().contains("Invalid evaluator expression Week() - function 'Week' is unknown"));
}
}
use of org.apache.solr.client.solrj.io.eval.StreamEvaluator in project lucene-solr by apache.
the class OrEvaluatorTest method orTwoBooleans.
@Test
public void orTwoBooleans() throws Exception {
StreamEvaluator evaluator = factory.constructEvaluator("or(a,b)");
Object result;
values.clear();
values.put("a", true);
values.put("b", true);
result = evaluator.evaluate(new Tuple(values));
Assert.assertTrue(result instanceof Boolean);
Assert.assertEquals(true, result);
values.clear();
values.put("a", true);
values.put("b", false);
result = evaluator.evaluate(new Tuple(values));
Assert.assertTrue(result instanceof Boolean);
Assert.assertEquals(true, result);
values.clear();
values.put("a", false);
values.put("b", true);
result = evaluator.evaluate(new Tuple(values));
Assert.assertTrue(result instanceof Boolean);
Assert.assertEquals(true, result);
values.clear();
values.put("a", false);
values.put("b", false);
result = evaluator.evaluate(new Tuple(values));
Assert.assertTrue(result instanceof Boolean);
Assert.assertEquals(false, result);
}
use of org.apache.solr.client.solrj.io.eval.StreamEvaluator in project lucene-solr by apache.
the class OrEvaluatorTest method orWithSubAndsBooleans.
@Test
public void orWithSubAndsBooleans() throws Exception {
StreamEvaluator evaluator = factory.constructEvaluator("or(a,or(b,c))");
Object result;
values.clear();
values.put("a", true);
values.put("b", true);
values.put("c", true);
result = evaluator.evaluate(new Tuple(values));
Assert.assertTrue(result instanceof Boolean);
Assert.assertEquals(true, result);
values.clear();
values.put("a", true);
values.put("b", true);
values.put("c", false);
result = evaluator.evaluate(new Tuple(values));
Assert.assertTrue(result instanceof Boolean);
Assert.assertEquals(true, result);
values.clear();
values.put("a", true);
values.put("b", false);
values.put("c", false);
result = evaluator.evaluate(new Tuple(values));
Assert.assertTrue(result instanceof Boolean);
Assert.assertEquals(true, result);
values.clear();
values.put("a", false);
values.put("b", true);
values.put("c", false);
result = evaluator.evaluate(new Tuple(values));
Assert.assertTrue(result instanceof Boolean);
Assert.assertEquals(true, result);
values.clear();
values.put("a", false);
values.put("b", false);
values.put("c", false);
result = evaluator.evaluate(new Tuple(values));
Assert.assertTrue(result instanceof Boolean);
Assert.assertEquals(false, result);
}
use of org.apache.solr.client.solrj.io.eval.StreamEvaluator in project lucene-solr by apache.
the class PowerEvaluatorTest method powTwoFieldWithNulls.
@Test
public void powTwoFieldWithNulls() throws Exception {
StreamEvaluator evaluator = factory.constructEvaluator("pow(a,b)");
values.clear();
Assert.assertNull(evaluator.evaluate(new Tuple(values)));
}
use of org.apache.solr.client.solrj.io.eval.StreamEvaluator in project lucene-solr by apache.
the class PowerEvaluatorTest method powTwoFieldsWithValues.
@Test
public void powTwoFieldsWithValues() throws Exception {
StreamEvaluator evaluator = factory.constructEvaluator("pow(a,b)");
Object result;
values.clear();
values.put("a", 2);
values.put("b", 5);
result = evaluator.evaluate(new Tuple(values));
Assert.assertTrue(result instanceof Number);
Assert.assertEquals(BigDecimal.valueOf(Math.pow(2, 5)), BigDecimal.valueOf(result instanceof Long ? (long) result : (double) result));
values.clear();
values.put("a", 1.1);
values.put("b", 2);
result = evaluator.evaluate(new Tuple(values));
Assert.assertTrue(result instanceof Number);
Assert.assertEquals(Math.pow(1.1, 2), result);
values.clear();
values.put("a", 1.1);
values.put("b", 2.1);
result = evaluator.evaluate(new Tuple(values));
Assert.assertTrue(result instanceof Number);
Assert.assertEquals(Math.pow(1.1, 2.1), result);
values.clear();
values.put("a", -1.1);
values.put("b", 2.1);
result = evaluator.evaluate(new Tuple(values));
Assert.assertTrue(Double.isNaN((double) result));
values.clear();
values.put("a", 1.1);
values.put("b", -2.1);
result = evaluator.evaluate(new Tuple(values));
Assert.assertTrue(result instanceof Number);
Assert.assertEquals(Math.pow(1.1, -2.1), result);
values.clear();
values.put("a", -1.1);
values.put("b", -2.1);
result = evaluator.evaluate(new Tuple(values));
Assert.assertTrue(Double.isNaN((double) result));
}
Aggregations