Author: rvesse
Date: Fri Aug 9 17:48:11 2013
New Revision: 1512418
URL: http://svn.apache.org/r1512418
Log:
Initial unit tests for Leviathan extension functions (JENA-507)
Added:
jena/trunk/jena-arq/src/test/java/com/hp/hpl/jena/sparql/expr/TestLeviathanFunctions.java
Modified:
jena/trunk/jena-arq/src/test/java/com/hp/hpl/jena/sparql/expr/TestFunctions.java
Modified:
jena/trunk/jena-arq/src/test/java/com/hp/hpl/jena/sparql/expr/TestFunctions.java
URL:
http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/test/java/com/hp/hpl/jena/sparql/expr/TestFunctions.java?rev=1512418&r1=1512417&r2=1512418&view=diff
==============================================================================
---
jena/trunk/jena-arq/src/test/java/com/hp/hpl/jena/sparql/expr/TestFunctions.java
(original)
+++
jena/trunk/jena-arq/src/test/java/com/hp/hpl/jena/sparql/expr/TestFunctions.java
Fri Aug 9 17:48:11 2013
@@ -226,9 +226,6 @@ public class TestFunctions
E_BNode
*/
- //@Test public void
-
-
private void test(String exprStr, NodeValue result)
{
Expr expr = ExprUtils.parse(exprStr) ;
Added:
jena/trunk/jena-arq/src/test/java/com/hp/hpl/jena/sparql/expr/TestLeviathanFunctions.java
URL:
http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/test/java/com/hp/hpl/jena/sparql/expr/TestLeviathanFunctions.java?rev=1512418&view=auto
==============================================================================
---
jena/trunk/jena-arq/src/test/java/com/hp/hpl/jena/sparql/expr/TestLeviathanFunctions.java
(added)
+++
jena/trunk/jena-arq/src/test/java/com/hp/hpl/jena/sparql/expr/TestLeviathanFunctions.java
Fri Aug 9 17:48:11 2013
@@ -0,0 +1,115 @@
+/*
+ * 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 com.hp.hpl.jena.sparql.expr;
+
+import com.hp.hpl.jena.graph.Node;
+import com.hp.hpl.jena.graph.NodeFactory;
+import com.hp.hpl.jena.query.ARQ;
+import com.hp.hpl.jena.shared.PrefixMapping;
+import com.hp.hpl.jena.shared.impl.PrefixMappingImpl;
+import com.hp.hpl.jena.sparql.ARQConstants;
+import com.hp.hpl.jena.sparql.expr.Expr;
+import com.hp.hpl.jena.sparql.expr.ExprEvalException;
+import com.hp.hpl.jena.sparql.expr.NodeValue;
+import com.hp.hpl.jena.sparql.function.FunctionEnvBase;
+import com.hp.hpl.jena.sparql.function.library.leviathan.LeviathanConstants;
+import com.hp.hpl.jena.sparql.serializer.SerializationContext;
+import com.hp.hpl.jena.sparql.util.ExprUtils;
+import com.hp.hpl.jena.sparql.util.FmtUtils;
+import com.hp.hpl.jena.sparql.util.NodeFactoryExtra;
+
+import org.apache.jena.atlas.junit.BaseTest;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class TestLeviathanFunctions extends BaseTest {
+
+ static boolean warnOnBadLexicalForms = true;
+
+ @BeforeClass
+ public static void beforeClass() {
+ warnOnBadLexicalForms = NodeValue.VerboseWarnings;
+ NodeValue.VerboseWarnings = false;
+ }
+
+ @AfterClass
+ public static void afterClass() {
+ NodeValue.VerboseWarnings = warnOnBadLexicalForms;
+ }
+
+ private static PrefixMapping pmap = new PrefixMappingImpl();
+ private static SerializationContext serContext = new
SerializationContext(false);
+
+ static {
+ pmap.setNsPrefixes(ARQConstants.getGlobalPrefixMap());
+ pmap.setNsPrefix("lfn",
LeviathanConstants.LeviathanFunctionLibraryURI);
+ }
+
+ @Test
+ public void sq_01() {
+ test("lfn:sq(2)", "4");
+ }
+
+ @Test
+ public void sq_02() {
+ test("lfn:sq(3)", "9");
+ }
+
+ @Test
+ public void sq_03() {
+ test("lfn:sq(0.5)", "0.25");
+ }
+
+ @Test
+ public void cube_01() {
+ test("lfn:cube(2)", "8");
+ }
+
+ @Test
+ public void cube_02() {
+ test("lfn:cube(3)", "27");
+ }
+
+ @Test
+ public void cube_03() {
+ test("lfn:cube(0.5)", "0.125");
+ }
+
+ @Test
+ public void e_01() {
+ test("lfn:e(2)", NodeFactoryExtra.doubleToNode(Math.exp(2d)));
+ }
+
+ private static void test(String string, String result) {
+ Node r = NodeFactoryExtra.parseNode(result);
+ test(string, r);
+ }
+
+ private static void test(String string, Node result) {
+ Expr expr = ExprUtils.parse(string, pmap);
+ NodeValue nv = expr.eval(null, new FunctionEnvBase());
+ NodeValue nvr = NodeValue.makeNode(result);
+
+ // Note that we don't test lexical form because we can get mismatches
+ // between how things like doubles are expressed
+ assertTrue("Not same value: Expected: " + nvr + " : Actual = " + nv,
NodeValue.sameAs(nvr, nv));
+ }
+
+}