Search in sources :

Example 6 with StreamEvaluator

use of org.apache.solr.client.solrj.io.eval.StreamEvaluator in project lucene-solr by apache.

the class NotEvaluatorTest method notOneBooleans.

@Test
public void notOneBooleans() throws Exception {
    StreamEvaluator evaluator = factory.constructEvaluator("not(a)");
    Object result;
    values.clear();
    values.put("a", true);
    result = evaluator.evaluate(new Tuple(values));
    Assert.assertTrue(result instanceof Boolean);
    Assert.assertEquals(false, result);
    values.clear();
    values.put("a", false);
    result = evaluator.evaluate(new Tuple(values));
    Assert.assertTrue(result instanceof Boolean);
    Assert.assertEquals(true, result);
}
Also used : StreamEvaluator(org.apache.solr.client.solrj.io.eval.StreamEvaluator) Tuple(org.apache.solr.client.solrj.io.Tuple) Test(org.junit.Test)

Example 7 with StreamEvaluator

use of org.apache.solr.client.solrj.io.eval.StreamEvaluator in project lucene-solr by apache.

the class PowerEvaluatorTest method powManyFieldsWithSubpows.

@Test
public void powManyFieldsWithSubpows() throws Exception {
    StreamEvaluator evaluator = factory.constructEvaluator("pow(a,pow(b,c))");
    Object result;
    values.clear();
    values.put("a", 8);
    values.put("b", 2);
    values.put("c", 3);
    result = evaluator.evaluate(new Tuple(values));
    Assert.assertTrue(result instanceof Number);
    Assert.assertEquals(BigDecimal.valueOf(Math.pow(8, Math.pow(2, 3))), BigDecimal.valueOf(result instanceof Long ? (long) result : (double) result));
}
Also used : StreamEvaluator(org.apache.solr.client.solrj.io.eval.StreamEvaluator) Tuple(org.apache.solr.client.solrj.io.Tuple) Test(org.junit.Test)

Example 8 with StreamEvaluator

use of org.apache.solr.client.solrj.io.eval.StreamEvaluator in project lucene-solr by apache.

the class RoundEvaluatorTest method noValue.

@Test
public void noValue() throws Exception {
    StreamEvaluator evaluator = factory.constructEvaluator("round(a)");
    values.clear();
    Object result = evaluator.evaluate(new Tuple(values));
    assertNull(result);
}
Also used : StreamEvaluator(org.apache.solr.client.solrj.io.eval.StreamEvaluator) Tuple(org.apache.solr.client.solrj.io.Tuple) Test(org.junit.Test)

Example 9 with StreamEvaluator

use of org.apache.solr.client.solrj.io.eval.StreamEvaluator in project lucene-solr by apache.

the class RoundEvaluatorTest method test.

private void test(Double value) throws IOException {
    StreamEvaluator evaluator = factory.constructEvaluator("round(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 Long);
        Assert.assertEquals(Math.round(value), result);
    }
}
Also used : StreamEvaluator(org.apache.solr.client.solrj.io.eval.StreamEvaluator) Tuple(org.apache.solr.client.solrj.io.Tuple)

Example 10 with StreamEvaluator

use of org.apache.solr.client.solrj.io.eval.StreamEvaluator in project lucene-solr by apache.

the class SineEvaluatorTest method noValue.

@Test
public void noValue() throws Exception {
    StreamEvaluator evaluator = factory.constructEvaluator("sin(a)");
    values.clear();
    Object result = evaluator.evaluate(new Tuple(values));
    assertNull(result);
}
Also used : StreamEvaluator(org.apache.solr.client.solrj.io.eval.StreamEvaluator) Tuple(org.apache.solr.client.solrj.io.Tuple) Test(org.junit.Test)

Aggregations

StreamEvaluator (org.apache.solr.client.solrj.io.eval.StreamEvaluator)137 Tuple (org.apache.solr.client.solrj.io.Tuple)135 Test (org.junit.Test)119 StreamContext (org.apache.solr.client.solrj.io.stream.StreamContext)6 HashMap (java.util.HashMap)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 UUID (java.util.UUID)1 StreamOperation (org.apache.solr.client.solrj.io.ops.StreamOperation)1