use of org.apache.solr.client.solrj.io.eval.StreamEvaluator in project lucene-solr by apache.
the class SquareRootEvaluatorTest method test.
private void test(Double value) throws IOException {
StreamEvaluator evaluator = factory.constructEvaluator("sqrt(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.sqrt(value), result);
}
}
use of org.apache.solr.client.solrj.io.eval.StreamEvaluator in project lucene-solr by apache.
the class SubtractEvaluatorTest method subTwoFieldWithNulls.
@Test
public void subTwoFieldWithNulls() throws Exception {
StreamEvaluator evaluator = factory.constructEvaluator("sub(a,b)");
Object result;
values.clear();
result = evaluator.evaluate(new Tuple(values));
Assert.assertNull(result);
}
use of org.apache.solr.client.solrj.io.eval.StreamEvaluator in project lucene-solr by apache.
the class SubtractEvaluatorTest method subTwoFieldsWithValues.
@Test
public void subTwoFieldsWithValues() throws Exception {
StreamEvaluator evaluator = factory.constructEvaluator("sub(a,b)");
Object result;
values.clear();
values.put("a", 1);
values.put("b", 2);
result = evaluator.evaluate(new Tuple(values));
Assert.assertTrue(result instanceof Long);
Assert.assertEquals(-1L, result);
values.clear();
values.put("a", 1.1);
values.put("b", 2);
result = evaluator.evaluate(new Tuple(values));
Assert.assertTrue(result instanceof Double);
Assert.assertEquals(-.9D, result);
values.clear();
values.put("a", 1.1);
values.put("b", 2.1);
result = evaluator.evaluate(new Tuple(values));
Assert.assertTrue(result instanceof Long);
Assert.assertEquals(-1L, result);
}
use of org.apache.solr.client.solrj.io.eval.StreamEvaluator in project lucene-solr by apache.
the class SubtractEvaluatorTest method subManyFieldsWithSubsubs.
@Test
public void subManyFieldsWithSubsubs() throws Exception {
StreamEvaluator evaluator = factory.constructEvaluator("sub(a,b,sub(c,d))");
Object result;
values.clear();
values.put("a", 1);
values.put("b", 2);
values.put("c", 3);
values.put("d", 4);
result = evaluator.evaluate(new Tuple(values));
Assert.assertTrue(result instanceof Long);
Assert.assertEquals(0L, result);
values.clear();
values.put("a", 123456789123456789L);
values.put("b", 123456789123456789L);
values.put("c", 123456789123456789L);
values.put("d", 123456789123456789L);
result = evaluator.evaluate(new Tuple(values));
Assert.assertTrue(result instanceof Long);
Assert.assertEquals(0L, result);
}
use of org.apache.solr.client.solrj.io.eval.StreamEvaluator in project lucene-solr by apache.
the class LessThanEqualToEvaluatorTest method lteTwoIntegers.
@Test
public void lteTwoIntegers() throws Exception {
StreamEvaluator evaluator = factory.constructEvaluator("lte(a,b)");
Object result;
values.clear();
values.put("a", 1);
values.put("b", 1);
result = evaluator.evaluate(new Tuple(values));
Assert.assertTrue(result instanceof Boolean);
Assert.assertEquals(true, result);
values.clear();
values.put("a", 1);
values.put("b", 1.0);
result = evaluator.evaluate(new Tuple(values));
Assert.assertTrue(result instanceof Boolean);
Assert.assertEquals(true, result);
values.clear();
values.put("a", 1.0);
values.put("b", 1);
result = evaluator.evaluate(new Tuple(values));
Assert.assertTrue(result instanceof Boolean);
Assert.assertEquals(true, result);
values.clear();
values.put("a", 1);
values.put("b", 2);
result = evaluator.evaluate(new Tuple(values));
Assert.assertTrue(result instanceof Boolean);
Assert.assertEquals(true, result);
values.clear();
values.put("a", -1);
values.put("b", -1);
result = evaluator.evaluate(new Tuple(values));
Assert.assertTrue(result instanceof Boolean);
Assert.assertEquals(true, result);
values.clear();
values.put("a", 1);
values.put("b", 2.0);
result = evaluator.evaluate(new Tuple(values));
Assert.assertTrue(result instanceof Boolean);
Assert.assertEquals(true, result);
values.clear();
values.put("a", 1.0);
values.put("b", 2);
result = evaluator.evaluate(new Tuple(values));
Assert.assertTrue(result instanceof Boolean);
Assert.assertEquals(true, result);
values.clear();
values.put("a", 2);
values.put("b", 1);
result = evaluator.evaluate(new Tuple(values));
Assert.assertTrue(result instanceof Boolean);
Assert.assertEquals(false, result);
values.clear();
values.put("a", 2);
values.put("b", 1.0);
result = evaluator.evaluate(new Tuple(values));
Assert.assertTrue(result instanceof Boolean);
Assert.assertEquals(false, result);
values.clear();
values.put("a", 2.0);
values.put("b", 1);
result = evaluator.evaluate(new Tuple(values));
Assert.assertTrue(result instanceof Boolean);
Assert.assertEquals(false, result);
values.clear();
values.put("a", 3);
values.put("b", 2);
result = evaluator.evaluate(new Tuple(values));
Assert.assertTrue(result instanceof Boolean);
Assert.assertEquals(false, result);
values.clear();
values.put("a", -1);
values.put("b", -2);
result = evaluator.evaluate(new Tuple(values));
Assert.assertTrue(result instanceof Boolean);
Assert.assertEquals(false, result);
values.clear();
values.put("a", -2);
values.put("b", -1);
result = evaluator.evaluate(new Tuple(values));
Assert.assertTrue(result instanceof Boolean);
Assert.assertEquals(true, result);
values.clear();
values.put("a", 3);
values.put("b", 2.0);
result = evaluator.evaluate(new Tuple(values));
Assert.assertTrue(result instanceof Boolean);
Assert.assertEquals(false, result);
values.clear();
values.put("a", 3.0);
values.put("b", 2);
result = evaluator.evaluate(new Tuple(values));
Assert.assertTrue(result instanceof Boolean);
Assert.assertEquals(false, result);
}
Aggregations