Package com.hp.jena.net.deploy.functions.test

Source Code of com.hp.jena.net.deploy.functions.test.TestJena2Builtins

/* 
  (c) Copyright 2009 Hewlett-Packard Development Company, LP
  [See end of file]
  $Id$
*/
package com.hp.jena.net.deploy.functions.test;

import static com.hp.hpl.jena.graph.test.GraphTestBase.*;
import static com.hp.jena.ymris.yast.expr.Expr.*;
import static org.junit.Assert.assertEquals;

import java.util.ArrayList;

import org.junit.Test;

import com.hp.hpl.jena.graph.Node;
import com.hp.hpl.jena.reasoner.rulesys.Functor;
import com.hp.hpl.jena.reasoner.rulesys.Functor.FunctorDatatype;
import com.hp.jena.ymris.deploy.functions.*;
import com.hp.jena.ymris.deploy.reasoner.*;
import com.hp.jena.ymris.util.Pair;
import com.hp.jena.ymris.yast.*;
import com.hp.jena.ymris.yast.expr.*;

/**
   These tests test that roughly the Jena2Builtins HowTo gets enough right
   answers to assure connection with the jena2 rulesys builtins, and that
   the plumbing connects up the contexts and environments.
*/
public class TestJena2Builtins
    {
    protected final DirectInferenceGraph g = xxx();

    private DirectInferenceGraph xxx()
        {
        ArrayList<Pair<String, YNode>> prefixes = new ArrayList<Pair<String, YNode>>();
        ArrayList<Rule> rules = new ArrayList<Rule>();
        Prolog prolog = new Prolog( (YNode) null, prefixes );
        DirectReasoner r = new DirectReasoner( new RuleSet( prolog, rules ) );
        return new DirectInferenceGraph( r, graphWith( "" ) );
        }
   
    protected final HowTo h = new Jena2Builtins( new YmrisContext( g ) );
   
    @Test public void testNotEqual()
        {
        Operation r = h.operationNamed( "notEqual" );
        assertEquals( NODE_TRUE, r.evalValue( nodeArray( "x y" ) ) );
        assertEquals( NODE_FALSE, r.evalValue( nodeArray( "x x" ) ) );
        }
   
    @Test public void testEqual()
        {
        Operation r = h.operationNamed( "equal" );
        assertEquals( NODE_TRUE, r.evalValue( nodeArray( "x x" ) ) );
        assertEquals( NODE_FALSE, r.evalValue( nodeArray( "x y" ) ) );
        }
   
    @Test public void testIsBNode()
        {
        Operation r = h.operationNamed( "isBNode" );
        assertEquals( NODE_FALSE, r.evalValue( nodeArray( "x" ) ) );
        assertEquals( NODE_FALSE, r.evalValue( nodeArray( "1" ) ) );
        assertEquals( NODE_TRUE, r.evalValue( nodeArray( "_blank" ) ) );
        }   
   
    @Test public void testNotBNode()
        {
        Operation r = h.operationNamed( "notBNode" );
        assertEquals( NODE_TRUE, r.evalValue( nodeArray( "x" ) ) );
        assertEquals( NODE_TRUE, r.evalValue( nodeArray( "1" ) ) );
        assertEquals( NODE_FALSE, r.evalValue( nodeArray( "_blank" ) ) );
        }
   
    @Test public void testIsLiteral()
        {
        Operation r = h.operationNamed( "isLiteral" );
        assertEquals( NODE_FALSE, r.evalValue( nodeArray( "x" ) ) );
        assertEquals( NODE_TRUE, r.evalValue( nodeArray( "1" ) ) );
        assertEquals( NODE_TRUE, r.evalValue( nodeArray( "'x'en" ) ) );
        assertEquals( NODE_TRUE, r.evalValue( nodeArray( "'y'xsd:yes" ) ) );
        assertEquals( NODE_FALSE, r.evalValue( nodeArray( "_blank" ) ) );
        }
   
    @Test public void testNotLiteral()
        {
        Operation r = h.operationNamed( "notLiteral" );
        assertEquals( NODE_TRUE, r.evalValue( nodeArray( "x" ) ) );
        assertEquals( NODE_FALSE, r.evalValue( nodeArray( "1" ) ) );
        assertEquals( NODE_FALSE, r.evalValue( nodeArray( "'x'en" ) ) );
        assertEquals( NODE_FALSE, r.evalValue( nodeArray( "'y'xsd:yes" ) ) );
        assertEquals( NODE_TRUE, r.evalValue( nodeArray( "_blank" ) ) );
        }
   
    @Test public void testGreaterThan()
        {
        Operation r = h.operationNamed( "greaterThan" );
        assertEquals( NODE_TRUE, r.evalValue( nodeArray( "3 1" ) ) );
        assertEquals( NODE_FALSE, r.evalValue( nodeArray( "1 1" ) ) );
        assertEquals( NODE_FALSE, r.evalValue( nodeArray( "1 3" ) ) );
        assertEquals( NODE_TRUE, r.evalValue( nodeArray( "1 '-1'xsd:int" ) ) );
        assertEquals( NODE_FALSE, r.evalValue( nodeArray( "'hell' 'hello'" ) ) );
        }
   
    @Test public void testGreaterOrEqual()
        {
        Operation r = h.operationNamed( "ge" );
        assertEquals( NODE_TRUE, r.evalValue( nodeArray( "3 1" ) ) );
        assertEquals( NODE_TRUE, r.evalValue( nodeArray( "1 1" ) ) );
        assertEquals( NODE_FALSE, r.evalValue( nodeArray( "1 3" ) ) );
        assertEquals( NODE_TRUE, r.evalValue( nodeArray( "1 '-1'xsd:int" ) ) );
        assertEquals( NODE_FALSE, r.evalValue( nodeArray( "'hell' 'hello'" ) ) );
        }
   
    @Test public void testLessThan()
        {
        Operation r = h.operationNamed( "lessThan" );
        assertEquals( NODE_TRUE, r.evalValue( nodeArray( "1 3" ) ) );
        assertEquals( NODE_FALSE, r.evalValue( nodeArray( "1 1" ) ) );
        assertEquals( NODE_FALSE, r.evalValue( nodeArray( "3 1" ) ) );
        assertEquals( NODE_TRUE, r.evalValue( nodeArray( "'-1'xsd:int 1" ) ) );
        assertEquals( NODE_FALSE, r.evalValue( nodeArray( "'hell' 'hello'" ) ) );
        }
   
    @Test public void testLessOrEqual()
        {
        Operation r = h.operationNamed( "le" );
        assertEquals( NODE_TRUE, r.evalValue( nodeArray( "1 3" ) ) );
        assertEquals( NODE_TRUE, r.evalValue( nodeArray( "1 1" ) ) );
        assertEquals( NODE_FALSE, r.evalValue( nodeArray( "3 1" ) ) );
        assertEquals( NODE_TRUE, r.evalValue( nodeArray( "'-1'xsd:int 1" ) ) );
        assertEquals( NODE_FALSE, r.evalValue( nodeArray( "'hell' 'hello'" ) ) );
        }
   
    @Test public void testIsFunctor()
        {
        Operation r = h.operationNamed( "isFunctor" );
        Functor f = new Functor( "f", new ArrayList<Node>() );
        Node functorNode = Node.createUncachedLiteral( f, "", FunctorDatatype.theFunctorDatatype );
        assertEquals( NODE_FALSE, r.evalValuenodeArray( "17" ) ) );
        assertEquals( NODE_FALSE, r.evalValuenodeArray( "spoo" ) ) );
        assertEquals( NODE_FALSE, r.evalValuenodeArray( "_blank" ) ) );
        assertEquals( NODE_TRUE, r.evalValuenew Node[] { functorNode } ) );
        }
   
    @Test public void testNotFunctor()
        {
        Operation r = h.operationNamed( "notFunctor" );
        Functor f = new Functor( "f", new ArrayList<Node>() );
        Node functorNode = Node.createUncachedLiteral( f, "", FunctorDatatype.theFunctorDatatype );
        assertEquals( NODE_TRUE, r.evalValuenodeArray( "17" ) ) );
        assertEquals( NODE_TRUE, r.evalValuenodeArray( "spoo" ) ) );
        assertEquals( NODE_TRUE, r.evalValuenodeArray( "_blank" ) ) );
        assertEquals( NODE_FALSE, r.evalValuenew Node[] { functorNode } ) );
        }
   
    @Test public void testListContains()
        {
        Operation r = h.operationNamed( "listContains" );
        graphAdd( g, "_x rdf:first 'v'; _x rdf:rest rdf:nil" );
        assertEquals( NODE_TRUE, r.evalValue( nodeArray( "_x 'v'" ) ) );
        assertEquals( NODE_FALSE, r.evalValue( nodeArray( "_x 'u'" ) ) );
        }
    }


/*
    (c) Copyright 2009 Hewlett-Packard Development Company, LP
    All rights reserved.

    Redistribution and use in source and binary forms, with or without
    modification, are permitted provided that the following conditions
    are met:

    1. Redistributions of source code must retain the above copyright
       notice, this list of conditions and the following disclaimer.

    2. Redistributions in binary form must reproduce the above copyright
       notice, this list of conditions and the following disclaimer in the
       documentation and/or other materials provided with the distribution.

    3. The name of the author may not be used to endorse or promote products
       derived from this software without specific prior written permission.

    THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
    IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
    OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
    IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
    INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
    NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
    THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ 
TOP

Related Classes of com.hp.jena.net.deploy.functions.test.TestJena2Builtins

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.