use of org.apache.solr.client.solrj.io.eval.StreamEvaluator in project lucene-solr by apache.
the class CompoundEvaluatorTest method compoundTest.
@Test
public void compoundTest() throws Exception {
StreamEvaluator evaluator = factory.constructEvaluator("add(mult(a,b),if(gt(c,d),e,f),g)");
Object result;
values.clear();
values.put("a", 10);
values.put("b", -3);
values.put("c", "foo");
values.put("d", "bar");
values.put("e", 9);
values.put("f", 2);
values.put("g", 5);
result = evaluator.evaluate(new Tuple(values));
Assert.assertTrue(result instanceof Long);
Assert.assertEquals(-16L, result);
values.clear();
values.put("a", .1);
values.put("b", -3);
values.put("c", "foo");
values.put("d", "bar");
values.put("e", 9);
values.put("f", 2);
values.put("g", 5);
result = evaluator.evaluate(new Tuple(values));
Assert.assertTrue(result instanceof Double);
Assert.assertEquals(13.7, result);
}
use of org.apache.solr.client.solrj.io.eval.StreamEvaluator in project lucene-solr by apache.
the class ConversionEvaluatorsTest method testFunction.
public void testFunction(String expression, Number expected) throws Exception {
StreamEvaluator evaluator = factory.constructEvaluator(expression);
StreamContext streamContext = new StreamContext();
evaluator.setStreamContext(streamContext);
Object result = evaluator.evaluate(new Tuple(values));
assertTrue(result instanceof Number);
assertEquals(expected, result);
}
use of org.apache.solr.client.solrj.io.eval.StreamEvaluator in project lucene-solr by apache.
the class ConversionEvaluatorsTest method testInvalidExpression.
@Test
public void testInvalidExpression() throws Exception {
StreamEvaluator evaluator;
try {
evaluator = factory.constructEvaluator("convert(inches)");
StreamContext streamContext = new StreamContext();
evaluator.setStreamContext(streamContext);
assertTrue(false);
} catch (IOException e) {
assertTrue(e.getCause().getCause().getMessage().contains("Invalid expression convert(inches) - expecting 3 value but found 1"));
}
try {
evaluator = factory.constructEvaluator("convert(inches, yards, 3)");
StreamContext streamContext = new StreamContext();
evaluator.setStreamContext(streamContext);
Tuple tuple = new Tuple(new HashMap());
evaluator.evaluate(tuple);
assertTrue(false);
} catch (IOException e) {
assertTrue(e.getCause().getCause().getMessage().contains("No conversion available from INCHES to YARDS"));
}
}
use of org.apache.solr.client.solrj.io.eval.StreamEvaluator in project lucene-solr by apache.
the class CosineEvaluatorTest method noValue.
@Test
public void noValue() throws Exception {
StreamEvaluator evaluator = factory.constructEvaluator("cos(a)");
values.clear();
Object result = evaluator.evaluate(new Tuple(values));
assertNull(result);
}
use of org.apache.solr.client.solrj.io.eval.StreamEvaluator in project lucene-solr by apache.
the class CosineEvaluatorTest method test.
private void test(Double value) throws IOException {
StreamEvaluator evaluator = factory.constructEvaluator("cos(a)");
values.clear();
values.put("a", value);
Object result = evaluator.evaluate(new Tuple(values));
if (null == value) {
Assert.assertNull(result);
} else {
Assert.assertTrue(result instanceof Double);
Assert.assertEquals(Math.cos(value), result);
}
}
Aggregations