001: /*
002: (c) Copyright 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP, all rights reserved.
003: [See end of file]
004: $Id: TestDisjointUnion.java,v 1.7 2008/01/02 12:07:21 andy_seaborne Exp $
005: */
006: package com.hp.hpl.jena.graph.compose.test;
007:
008: import junit.framework.TestSuite;
009:
010: import com.hp.hpl.jena.graph.Graph;
011: import com.hp.hpl.jena.graph.compose.DisjointUnion;
012: import com.hp.hpl.jena.graph.test.GraphTestBase;
013:
014: /**
015: TestDisjointUnion - test that DisjointUnion works, as well as we can.
016: @author kers
017: */
018: public class TestDisjointUnion extends GraphTestBase {
019: public TestDisjointUnion(String name) {
020: super (name);
021: }
022:
023: public static TestSuite suite() {
024: return new TestSuite(TestDisjointUnion.class);
025: }
026:
027: public void testEmptyUnion() {
028: DisjointUnion du = new DisjointUnion(Graph.emptyGraph,
029: Graph.emptyGraph);
030: assertEquals(true, du.isEmpty());
031: }
032:
033: public void testLeftUnion() {
034: Graph g = graphWith("");
035: testSingleComponent(g, new DisjointUnion(g, Graph.emptyGraph));
036: }
037:
038: public void testRightUnion() {
039: Graph g = graphWith("");
040: testSingleComponent(g, new DisjointUnion(Graph.emptyGraph, g));
041: }
042:
043: protected void testSingleComponent(Graph g, DisjointUnion du) {
044: graphAdd(g, "x R y; a P b; x Q b");
045: assertIsomorphic(g, du);
046: graphAdd(g, "roses growOn you");
047: assertIsomorphic(g, du);
048: g.delete(triple("a P b"));
049: assertIsomorphic(g, du);
050: }
051:
052: public void testBothComponents() {
053: Graph L = graphWith(""), R = graphWith("");
054: Graph du = new DisjointUnion(L, R);
055: assertIsomorphic(Graph.emptyGraph, du);
056: L.add(triple("x P y"));
057: assertIsomorphic(graphWith("x P y"), du);
058: R.add(triple("A rdf:type Route"));
059: assertIsomorphic(graphWith("x P y; A rdf:type Route"), du);
060: }
061:
062: public void testRemoveBoth() {
063: Graph L = graphWith("x R y; a P b"), R = graphWith("x R y; p Q r");
064: Graph du = new DisjointUnion(L, R);
065: du.delete(triple("x R y"));
066: assertIsomorphic(graphWith("a P b"), L);
067: assertIsomorphic(graphWith("p Q r"), R);
068: }
069:
070: public void testAddLeftOnlyIfNecessary() {
071: Graph L = graphWith(""), R = graphWith("x R y");
072: Graph du = new DisjointUnion(L, R);
073: graphAdd(du, "x R y");
074: assertEquals(true, L.isEmpty());
075: graphAdd(du, " a P b");
076: assertIsomorphic(graphWith("a P b"), L);
077: assertIsomorphic(graphWith("x R y"), R);
078: }
079: }
080:
081: /*
082: (c) Copyright 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
083: All rights reserved.
084:
085: Redistribution and use in source and binary forms, with or without
086: modification, are permitted provided that the following conditions
087: are met:
088:
089: 1. Redistributions of source code must retain the above copyright
090: notice, this list of conditions and the following disclaimer.
091:
092: 2. Redistributions in binary form must reproduce the above copyright
093: notice, this list of conditions and the following disclaimer in the
094: documentation and/or other materials provided with the distribution.
095:
096: 3. The name of the author may not be used to endorse or promote products
097: derived from this software without specific prior written permission.
098:
099: THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
100: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
101: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
102: IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
103: INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
104: NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
105: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
106: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
107: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
108: THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
109: */
|