Return-Path: X-Original-To: apmail-jena-commits-archive@www.apache.org Delivered-To: apmail-jena-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 26A661078C for ; Fri, 9 Aug 2013 17:48:34 +0000 (UTC) Received: (qmail 49961 invoked by uid 500); 9 Aug 2013 17:48:34 -0000 Delivered-To: apmail-jena-commits-archive@jena.apache.org Received: (qmail 49939 invoked by uid 500); 9 Aug 2013 17:48:33 -0000 Mailing-List: contact commits-help@jena.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@jena.apache.org Delivered-To: mailing list commits@jena.apache.org Received: (qmail 49932 invoked by uid 99); 9 Aug 2013 17:48:33 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 09 Aug 2013 17:48:33 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 09 Aug 2013 17:48:32 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 2C40623888E7; Fri, 9 Aug 2013 17:48:12 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1512418 - in /jena/trunk/jena-arq/src/test/java/com/hp/hpl/jena/sparql/expr: TestFunctions.java TestLeviathanFunctions.java Date: Fri, 09 Aug 2013 17:48:12 -0000 To: commits@jena.apache.org From: rvesse@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20130809174812.2C40623888E7@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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)); + } + +}