You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ab...@apache.org on 2017/04/03 18:45:50 UTC
[44/52] [abbrv] lucene-solr:jira/solr-9959: SOLR-10356: Adds basic
math streaming evaluators
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/674ce4e8/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/eval/CubedRootEvaluatorTest.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/eval/CubedRootEvaluatorTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/eval/CubedRootEvaluatorTest.java
new file mode 100644
index 0000000..0a7f3de
--- /dev/null
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/eval/CubedRootEvaluatorTest.java
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.client.solrj.io.stream.eval;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.lucene.util.LuceneTestCase;
+import org.apache.solr.client.solrj.io.Tuple;
+import org.apache.solr.client.solrj.io.eval.CubedRootEvaluator;
+import org.apache.solr.client.solrj.io.eval.StreamEvaluator;
+import org.apache.solr.client.solrj.io.stream.expr.StreamFactory;
+import org.junit.Test;
+
+import junit.framework.Assert;
+
+public class CubedRootEvaluatorTest extends LuceneTestCase {
+
+ StreamFactory factory;
+ Map<String, Object> values;
+
+ public CubedRootEvaluatorTest() {
+ super();
+
+ factory = new StreamFactory()
+ .withFunctionName("cbrt", CubedRootEvaluator.class);
+ values = new HashMap<String,Object>();
+ }
+
+ private void test(Double value) throws IOException{
+ StreamEvaluator evaluator = factory.constructEvaluator("cbrt(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.cbrt(value), result);
+ }
+ }
+
+ @Test
+ public void oneField() throws Exception{
+ test(90D);
+ test(45D);
+ test(12.4D);
+ test(-45D);
+ }
+
+ @Test(expected = IOException.class)
+ public void noField() throws Exception{
+ factory.constructEvaluator("cbrt()");
+ }
+
+ @Test(expected = IOException.class)
+ public void twoFields() throws Exception{
+ factory.constructEvaluator("cbrt(a,b)");
+ }
+
+ @Test
+ public void noValue() throws Exception{
+ StreamEvaluator evaluator = factory.constructEvaluator("cbrt(a)");
+
+ values.clear();
+ Object result = evaluator.evaluate(new Tuple(values));
+ assertNull(result);
+ }
+ @Test
+ public void nullValue() throws Exception{
+ test(null);
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/674ce4e8/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/eval/FloorEvaluatorTest.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/eval/FloorEvaluatorTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/eval/FloorEvaluatorTest.java
new file mode 100644
index 0000000..0fbf16d
--- /dev/null
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/eval/FloorEvaluatorTest.java
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.client.solrj.io.stream.eval;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.lucene.util.LuceneTestCase;
+import org.apache.solr.client.solrj.io.Tuple;
+import org.apache.solr.client.solrj.io.eval.FloorEvaluator;
+import org.apache.solr.client.solrj.io.eval.StreamEvaluator;
+import org.apache.solr.client.solrj.io.stream.expr.StreamFactory;
+import org.junit.Test;
+
+import junit.framework.Assert;
+
+public class FloorEvaluatorTest extends LuceneTestCase {
+
+ StreamFactory factory;
+ Map<String, Object> values;
+
+ public FloorEvaluatorTest() {
+ super();
+
+ factory = new StreamFactory()
+ .withFunctionName("floor", FloorEvaluator.class);
+ values = new HashMap<String,Object>();
+ }
+
+ @Test
+ public void floorOneField() throws Exception{
+ StreamEvaluator evaluator = factory.constructEvaluator("floor(a)");
+ Object result;
+
+ values.clear();
+ values.put("a", 1);
+ result = evaluator.evaluate(new Tuple(values));
+ Assert.assertTrue(result instanceof Long);
+ Assert.assertEquals(1L, result);
+
+ values.clear();
+ values.put("a", 1.1);
+ result = evaluator.evaluate(new Tuple(values));
+ Assert.assertTrue(result instanceof Long);
+ Assert.assertEquals(1L, result);
+
+ values.clear();
+ values.put("a", -1.1);
+ result = evaluator.evaluate(new Tuple(values));
+ Assert.assertTrue(result instanceof Long);
+ Assert.assertEquals(-2L, result);
+ }
+
+ @Test(expected = IOException.class)
+ public void floorNoField() throws Exception{
+ factory.constructEvaluator("floor()");
+ }
+
+ @Test(expected = IOException.class)
+ public void floorTwoFields() throws Exception{
+ factory.constructEvaluator("floor(a,b)");
+ }
+
+ @Test
+ public void floorNoValue() throws Exception{
+ StreamEvaluator evaluator = factory.constructEvaluator("floor(a)");
+
+ values.clear();
+ Object result = evaluator.evaluate(new Tuple(values));
+ assertNull(result);
+ }
+ @Test
+ public void floorNullValue() throws Exception{
+ StreamEvaluator evaluator = factory.constructEvaluator("floor(a)");
+
+ values.clear();
+ values.put("a", null);
+ Object result = evaluator.evaluate(new Tuple(values));
+ assertNull(result);
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/674ce4e8/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/eval/HyperbolicCosineEvaluatorTest.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/eval/HyperbolicCosineEvaluatorTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/eval/HyperbolicCosineEvaluatorTest.java
new file mode 100644
index 0000000..7847f30
--- /dev/null
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/eval/HyperbolicCosineEvaluatorTest.java
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.client.solrj.io.stream.eval;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.lucene.util.LuceneTestCase;
+import org.apache.solr.client.solrj.io.Tuple;
+import org.apache.solr.client.solrj.io.eval.HyperbolicCosineEvaluator;
+import org.apache.solr.client.solrj.io.eval.StreamEvaluator;
+import org.apache.solr.client.solrj.io.stream.expr.StreamFactory;
+import org.junit.Test;
+
+import junit.framework.Assert;
+
+public class HyperbolicCosineEvaluatorTest extends LuceneTestCase {
+
+ StreamFactory factory;
+ Map<String, Object> values;
+
+ public HyperbolicCosineEvaluatorTest() {
+ super();
+
+ factory = new StreamFactory()
+ .withFunctionName("cosh", HyperbolicCosineEvaluator.class);
+ values = new HashMap<String,Object>();
+ }
+
+ private void test(Double value) throws IOException{
+ StreamEvaluator evaluator = factory.constructEvaluator("cosh(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.cosh(value), result);
+ }
+ }
+
+ @Test
+ public void oneField() throws Exception{
+ test(90D);
+ test(45D);
+ test(12.4D);
+ test(-45D);
+ }
+
+ @Test(expected = IOException.class)
+ public void noField() throws Exception{
+ factory.constructEvaluator("cosh()");
+ }
+
+ @Test(expected = IOException.class)
+ public void twoFields() throws Exception{
+ factory.constructEvaluator("cosh(a,b)");
+ }
+
+ @Test
+ public void noValue() throws Exception{
+ StreamEvaluator evaluator = factory.constructEvaluator("cosh(a)");
+
+ values.clear();
+ Object result = evaluator.evaluate(new Tuple(values));
+ assertNull(result);
+ }
+ @Test
+ public void nullValue() throws Exception{
+ test(null);
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/674ce4e8/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/eval/HyperbolicSineEvaluatorTest.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/eval/HyperbolicSineEvaluatorTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/eval/HyperbolicSineEvaluatorTest.java
new file mode 100644
index 0000000..22733cc
--- /dev/null
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/eval/HyperbolicSineEvaluatorTest.java
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.client.solrj.io.stream.eval;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.lucene.util.LuceneTestCase;
+import org.apache.solr.client.solrj.io.Tuple;
+import org.apache.solr.client.solrj.io.eval.HyperbolicSineEvaluator;
+import org.apache.solr.client.solrj.io.eval.StreamEvaluator;
+import org.apache.solr.client.solrj.io.stream.expr.StreamFactory;
+import org.junit.Test;
+
+import junit.framework.Assert;
+
+public class HyperbolicSineEvaluatorTest extends LuceneTestCase {
+
+ StreamFactory factory;
+ Map<String, Object> values;
+
+ public HyperbolicSineEvaluatorTest() {
+ super();
+
+ factory = new StreamFactory()
+ .withFunctionName("sinh", HyperbolicSineEvaluator.class);
+ values = new HashMap<String,Object>();
+ }
+
+ private void test(Double value) throws IOException{
+ StreamEvaluator evaluator = factory.constructEvaluator("sinh(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.sinh(value), result);
+ }
+ }
+
+ @Test
+ public void oneField() throws Exception{
+ test(90D);
+ test(45D);
+ test(12.4D);
+ test(-45D);
+ }
+
+ @Test(expected = IOException.class)
+ public void noField() throws Exception{
+ factory.constructEvaluator("sinh()");
+ }
+
+ @Test(expected = IOException.class)
+ public void twoFields() throws Exception{
+ factory.constructEvaluator("sinh(a,b)");
+ }
+
+ @Test
+ public void noValue() throws Exception{
+ StreamEvaluator evaluator = factory.constructEvaluator("sinh(a)");
+
+ values.clear();
+ Object result = evaluator.evaluate(new Tuple(values));
+ assertNull(result);
+ }
+ @Test
+ public void nullValue() throws Exception{
+ test(null);
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/674ce4e8/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/eval/HyperbolicTangentEvaluatorTest.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/eval/HyperbolicTangentEvaluatorTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/eval/HyperbolicTangentEvaluatorTest.java
new file mode 100644
index 0000000..e526a08
--- /dev/null
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/eval/HyperbolicTangentEvaluatorTest.java
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.client.solrj.io.stream.eval;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.lucene.util.LuceneTestCase;
+import org.apache.solr.client.solrj.io.Tuple;
+import org.apache.solr.client.solrj.io.eval.HyperbolicTangentEvaluator;
+import org.apache.solr.client.solrj.io.eval.StreamEvaluator;
+import org.apache.solr.client.solrj.io.stream.expr.StreamFactory;
+import org.junit.Test;
+
+import junit.framework.Assert;
+
+public class HyperbolicTangentEvaluatorTest extends LuceneTestCase {
+
+ StreamFactory factory;
+ Map<String, Object> values;
+
+ public HyperbolicTangentEvaluatorTest() {
+ super();
+
+ factory = new StreamFactory()
+ .withFunctionName("tanh", HyperbolicTangentEvaluator.class);
+ values = new HashMap<String,Object>();
+ }
+
+ private void test(Double value) throws IOException{
+ StreamEvaluator evaluator = factory.constructEvaluator("tanh(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.tanh(value), result);
+ }
+ }
+
+ @Test
+ public void oneField() throws Exception{
+ test(90D);
+ test(45D);
+ test(12.4D);
+ test(-45D);
+ }
+
+ @Test(expected = IOException.class)
+ public void noField() throws Exception{
+ factory.constructEvaluator("tanh()");
+ }
+
+ @Test(expected = IOException.class)
+ public void twoFields() throws Exception{
+ factory.constructEvaluator("tanh(a,b)");
+ }
+
+ @Test
+ public void noValue() throws Exception{
+ StreamEvaluator evaluator = factory.constructEvaluator("tanh(a)");
+
+ values.clear();
+ Object result = evaluator.evaluate(new Tuple(values));
+ assertNull(result);
+ }
+ @Test
+ public void nullValue() throws Exception{
+ test(null);
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/674ce4e8/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/eval/ModuloEvaluatorTest.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/eval/ModuloEvaluatorTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/eval/ModuloEvaluatorTest.java
new file mode 100644
index 0000000..436763b
--- /dev/null
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/eval/ModuloEvaluatorTest.java
@@ -0,0 +1,164 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for multitional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.client.solrj.io.stream.eval;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.lucene.util.LuceneTestCase;
+import org.apache.solr.client.solrj.io.Tuple;
+import org.apache.solr.client.solrj.io.eval.ModuloEvaluator;
+import org.apache.solr.client.solrj.io.eval.StreamEvaluator;
+import org.apache.solr.client.solrj.io.stream.expr.StreamFactory;
+import org.junit.Test;
+
+import junit.framework.Assert;
+
+public class ModuloEvaluatorTest extends LuceneTestCase {
+
+ StreamFactory factory;
+ Map<String, Object> values;
+
+ public ModuloEvaluatorTest() {
+ super();
+
+ factory = new StreamFactory()
+ .withFunctionName("mod", ModuloEvaluator.class);
+ values = new HashMap<String,Object>();
+ }
+
+ @Test
+ public void modTwoFieldsWithValues() throws Exception{
+ StreamEvaluator evaluator = factory.constructEvaluator("mod(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(Long.valueOf(1 % 2), 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(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 Double);
+ Assert.assertEquals(1.1 % 2.1, result);
+ }
+
+ @Test(expected = IOException.class)
+ public void modOneField() throws Exception{
+ factory.constructEvaluator("mod(a)");
+ }
+
+ @Test(expected = IOException.class)
+ public void modTwoFieldWithNulls() throws Exception{
+ StreamEvaluator evaluator = factory.constructEvaluator("mod(a,b)");
+
+ values.clear();
+ evaluator.evaluate(new Tuple(values));
+ }
+
+ @Test(expected = IOException.class)
+ public void modTwoFieldsWithNullDenominator() throws Exception{
+ StreamEvaluator evaluator = factory.constructEvaluator("mod(a,b)");
+
+ values.clear();
+ values.put("a", 1);
+ evaluator.evaluate(new Tuple(values));
+ }
+
+ @Test(expected = IOException.class)
+ public void modTwoFieldsWithNullNumerator() throws Exception{
+ StreamEvaluator evaluator = factory.constructEvaluator("mod(a,b)");
+
+ values.clear();
+ values.put("b", 1);
+ evaluator.evaluate(new Tuple(values));
+ }
+
+
+ @Test(expected = IOException.class)
+ public void modTwoFieldsWithMissingDenominator() throws Exception{
+ StreamEvaluator evaluator = factory.constructEvaluator("mod(a,b)");
+
+ values.clear();
+ values.put("a", 1);
+ evaluator.evaluate(new Tuple(values));
+ }
+
+ @Test(expected = IOException.class)
+ public void modTwoFieldsWithMissingNumerator() throws Exception{
+ StreamEvaluator evaluator = factory.constructEvaluator("mod(a,b)");
+
+ values.clear();
+ values.put("b", 1);
+ evaluator.evaluate(new Tuple(values));
+ }
+
+
+ @Test(expected = IOException.class)
+ public void modManyFieldsWithValues() throws Exception{
+ factory.constructEvaluator("mod(a,b,c,d)");
+ }
+
+ @Test
+ public void modManyFieldsWithSubmods() throws Exception{
+ StreamEvaluator evaluator = factory.constructEvaluator("mod(a,mod(b,c))");
+ Object result;
+
+ values.clear();
+ values.put("a", 1);
+ values.put("b", 2);
+ values.put("c", 9);
+ result = evaluator.evaluate(new Tuple(values));
+ Assert.assertTrue(result instanceof Long);
+ Assert.assertEquals(Long.valueOf(1 % (2 % 9)), result);
+ }
+
+ @Test(expected = IOException.class)
+ public void modByZero() throws Exception{
+ StreamEvaluator evaluator = factory.constructEvaluator("mod(a,b)");
+
+ values.clear();
+ values.put("a", 1);
+ values.put("b", 0);
+ evaluator.evaluate(new Tuple(values));
+ }
+
+ @Test
+ public void modZeroByValue() throws Exception{
+ StreamEvaluator evaluator = factory.constructEvaluator("mod(a,b)");
+ Object result;
+
+ values.clear();
+ values.put("a", 0);
+ values.put("b", 2);
+ result = evaluator.evaluate(new Tuple(values));
+ Assert.assertTrue(result instanceof Long);
+ Assert.assertEquals(0L, result);
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/674ce4e8/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/eval/PowerEvaluatorTest.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/eval/PowerEvaluatorTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/eval/PowerEvaluatorTest.java
new file mode 100644
index 0000000..5efa7a4
--- /dev/null
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/eval/PowerEvaluatorTest.java
@@ -0,0 +1,119 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for multitional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.client.solrj.io.stream.eval;
+
+import java.io.IOException;
+import java.math.BigDecimal;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.lucene.util.LuceneTestCase;
+import org.apache.solr.client.solrj.io.Tuple;
+import org.apache.solr.client.solrj.io.eval.PowerEvaluator;
+import org.apache.solr.client.solrj.io.eval.StreamEvaluator;
+import org.apache.solr.client.solrj.io.stream.expr.StreamFactory;
+import org.junit.Test;
+
+import junit.framework.Assert;
+
+public class PowerEvaluatorTest extends LuceneTestCase {
+
+ StreamFactory factory;
+ Map<String, Object> values;
+
+ public PowerEvaluatorTest() {
+ super();
+
+ factory = new StreamFactory()
+ .withFunctionName("pow", PowerEvaluator.class);
+ values = new HashMap<String,Object>();
+ }
+
+ @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));
+ }
+
+ @Test(expected = IOException.class)
+ public void powOneField() throws Exception{
+ factory.constructEvaluator("pow(a)");
+ }
+
+ @Test
+ public void powTwoFieldWithNulls() throws Exception{
+ StreamEvaluator evaluator = factory.constructEvaluator("pow(a,b)");
+
+ values.clear();
+ Assert.assertNull(evaluator.evaluate(new Tuple(values)));
+ }
+
+ @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));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/674ce4e8/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/eval/RoundEvaluatorTest.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/eval/RoundEvaluatorTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/eval/RoundEvaluatorTest.java
new file mode 100644
index 0000000..8851b3c
--- /dev/null
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/eval/RoundEvaluatorTest.java
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.client.solrj.io.stream.eval;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.lucene.util.LuceneTestCase;
+import org.apache.solr.client.solrj.io.Tuple;
+import org.apache.solr.client.solrj.io.eval.RoundEvaluator;
+import org.apache.solr.client.solrj.io.eval.StreamEvaluator;
+import org.apache.solr.client.solrj.io.stream.expr.StreamFactory;
+import org.junit.Test;
+
+import junit.framework.Assert;
+
+public class RoundEvaluatorTest extends LuceneTestCase {
+
+ StreamFactory factory;
+ Map<String, Object> values;
+
+ public RoundEvaluatorTest() {
+ super();
+
+ factory = new StreamFactory()
+ .withFunctionName("round", RoundEvaluator.class);
+ values = new HashMap<String,Object>();
+ }
+
+ 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);
+ }
+ }
+
+ @Test
+ public void oneField() throws Exception{
+ test(90D);
+ test(45.555555D);
+ test(12.4D);
+ test(-.4D);
+ test(-0D);
+ test(-0.0235D);
+ test(-12.44444446D);
+ test(-45.23D);
+ }
+
+ @Test(expected = IOException.class)
+ public void noField() throws Exception{
+ factory.constructEvaluator("round()");
+ }
+
+ @Test(expected = IOException.class)
+ public void twoFields() throws Exception{
+ factory.constructEvaluator("round(a,b)");
+ }
+
+ @Test
+ public void noValue() throws Exception{
+ StreamEvaluator evaluator = factory.constructEvaluator("round(a)");
+
+ values.clear();
+ Object result = evaluator.evaluate(new Tuple(values));
+ assertNull(result);
+ }
+ @Test
+ public void nullValue() throws Exception{
+ test(null);
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/674ce4e8/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/eval/SineEvaluatorTest.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/eval/SineEvaluatorTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/eval/SineEvaluatorTest.java
new file mode 100644
index 0000000..8f8a9eb
--- /dev/null
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/eval/SineEvaluatorTest.java
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.client.solrj.io.stream.eval;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.lucene.util.LuceneTestCase;
+import org.apache.solr.client.solrj.io.Tuple;
+import org.apache.solr.client.solrj.io.eval.SineEvaluator;
+import org.apache.solr.client.solrj.io.eval.StreamEvaluator;
+import org.apache.solr.client.solrj.io.stream.expr.StreamFactory;
+import org.junit.Test;
+
+import junit.framework.Assert;
+
+public class SineEvaluatorTest extends LuceneTestCase {
+
+ StreamFactory factory;
+ Map<String, Object> values;
+
+ public SineEvaluatorTest() {
+ super();
+
+ factory = new StreamFactory()
+ .withFunctionName("sin", SineEvaluator.class);
+ values = new HashMap<String,Object>();
+ }
+
+ private void test(Double value) throws IOException{
+ StreamEvaluator evaluator = factory.constructEvaluator("sin(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.sin(value), result);
+ }
+ }
+
+ @Test
+ public void oneField() throws Exception{
+ test(90D);
+ test(45D);
+ test(12.4D);
+ test(-45D);
+ }
+
+ @Test(expected = IOException.class)
+ public void noField() throws Exception{
+ factory.constructEvaluator("sin()");
+ }
+
+ @Test(expected = IOException.class)
+ public void twoFields() throws Exception{
+ factory.constructEvaluator("sin(a,b)");
+ }
+
+ @Test
+ public void noValue() throws Exception{
+ StreamEvaluator evaluator = factory.constructEvaluator("sin(a)");
+
+ values.clear();
+ Object result = evaluator.evaluate(new Tuple(values));
+ assertNull(result);
+ }
+ @Test
+ public void nullValue() throws Exception{
+ test(null);
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/674ce4e8/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/eval/SquareRootEvaluatorTest.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/eval/SquareRootEvaluatorTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/eval/SquareRootEvaluatorTest.java
new file mode 100644
index 0000000..733a8f7
--- /dev/null
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/eval/SquareRootEvaluatorTest.java
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.client.solrj.io.stream.eval;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.lucene.util.LuceneTestCase;
+import org.apache.solr.client.solrj.io.Tuple;
+import org.apache.solr.client.solrj.io.eval.SquareRootEvaluator;
+import org.apache.solr.client.solrj.io.eval.StreamEvaluator;
+import org.apache.solr.client.solrj.io.stream.expr.StreamFactory;
+import org.junit.Test;
+
+import junit.framework.Assert;
+
+public class SquareRootEvaluatorTest extends LuceneTestCase {
+
+ StreamFactory factory;
+ Map<String, Object> values;
+
+ public SquareRootEvaluatorTest() {
+ super();
+
+ factory = new StreamFactory()
+ .withFunctionName("sqrt", SquareRootEvaluator.class);
+ values = new HashMap<String,Object>();
+ }
+
+ 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);
+ }
+ }
+
+ @Test
+ public void oneField() throws Exception{
+ test(90D);
+ test(45D);
+ test(12.4D);
+ test(-45D);
+ }
+
+ @Test(expected = IOException.class)
+ public void noField() throws Exception{
+ factory.constructEvaluator("sqrt()");
+ }
+
+ @Test(expected = IOException.class)
+ public void twoFields() throws Exception{
+ factory.constructEvaluator("sqrt(a,b)");
+ }
+
+ @Test
+ public void noValue() throws Exception{
+ StreamEvaluator evaluator = factory.constructEvaluator("sqrt(a)");
+
+ values.clear();
+ Object result = evaluator.evaluate(new Tuple(values));
+ assertNull(result);
+ }
+ @Test
+ public void nullValue() throws Exception{
+ test(null);
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/674ce4e8/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/eval/TangentEvaluatorTest.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/eval/TangentEvaluatorTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/eval/TangentEvaluatorTest.java
new file mode 100644
index 0000000..ab0fbef
--- /dev/null
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/eval/TangentEvaluatorTest.java
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.client.solrj.io.stream.eval;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.lucene.util.LuceneTestCase;
+import org.apache.solr.client.solrj.io.Tuple;
+import org.apache.solr.client.solrj.io.eval.StreamEvaluator;
+import org.apache.solr.client.solrj.io.eval.TangentEvaluator;
+import org.apache.solr.client.solrj.io.stream.expr.StreamFactory;
+import org.junit.Test;
+
+import junit.framework.Assert;
+
+public class TangentEvaluatorTest extends LuceneTestCase {
+
+ StreamFactory factory;
+ Map<String, Object> values;
+
+ public TangentEvaluatorTest() {
+ super();
+
+ factory = new StreamFactory()
+ .withFunctionName("tan", TangentEvaluator.class);
+ values = new HashMap<String,Object>();
+ }
+
+ private void test(Double value) throws IOException{
+ StreamEvaluator evaluator = factory.constructEvaluator("tan(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.tan(value), result);
+ }
+ }
+
+ @Test
+ public void oneField() throws Exception{
+ test(90D);
+ test(45D);
+ test(12.4D);
+ test(-45D);
+ }
+
+ @Test(expected = IOException.class)
+ public void noField() throws Exception{
+ factory.constructEvaluator("tan()");
+ }
+
+ @Test(expected = IOException.class)
+ public void twoFields() throws Exception{
+ factory.constructEvaluator("tan(a,b)");
+ }
+
+ @Test
+ public void noValue() throws Exception{
+ StreamEvaluator evaluator = factory.constructEvaluator("tan(a)");
+
+ values.clear();
+ Object result = evaluator.evaluate(new Tuple(values));
+ assertNull(result);
+ }
+ @Test
+ public void nullValue() throws Exception{
+ test(null);
+ }
+}