KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > graph > compose > test > TestDisjointUnion


1 /*
2   (c) Copyright 2004, 2005 Hewlett-Packard Development Company, LP, all rights reserved.
3   [See end of file]
4   $Id: TestDisjointUnion.java,v 1.4 2005/02/21 11:52:07 andy_seaborne Exp $
5 */

6 package com.hp.hpl.jena.graph.compose.test;
7
8 import junit.framework.TestSuite;
9
10 import com.hp.hpl.jena.graph.Graph;
11 import com.hp.hpl.jena.graph.compose.DisjointUnion;
12 import com.hp.hpl.jena.graph.test.GraphTestBase;
13
14 /**
15      TestDisjointUnion - test that DisjointUnion works, as well as we can.
16      @author kers
17 */

18 public class TestDisjointUnion extends GraphTestBase
19     {
20     public TestDisjointUnion( String JavaDoc name )
21         { super( name ); }
22     
23     public static TestSuite suite()
24         { return new TestSuite( TestDisjointUnion.class ); }
25     
26     public void testEmptyUnion()
27         {
28         DisjointUnion du = new DisjointUnion( Graph.emptyGraph, Graph.emptyGraph );
29         assertEquals( true, du.isEmpty() );
30         }
31     
32     public void testLeftUnion()
33         {
34         Graph g = graphWith( "" );
35         testSingleComponent( g, new DisjointUnion( g, Graph.emptyGraph ) );
36         }
37     
38     public void testRightUnion()
39         {
40         Graph g = graphWith( "" );
41         testSingleComponent( g, new DisjointUnion( Graph.emptyGraph, g ) );
42         }
43
44     protected void testSingleComponent( Graph g, DisjointUnion du )
45         {
46         graphAdd( g, "x R y; a P b; x Q b" );
47         assertIsomorphic( g, du );
48         graphAdd( g, "roses growOn you" );
49         assertIsomorphic( g, du );
50         g.delete( triple( "a P b" ) );
51         assertIsomorphic( g, du );
52         }
53     
54     public void testBothComponents()
55         {
56         Graph L = graphWith( "" ), R = graphWith( "" );
57         Graph du = new DisjointUnion( L, R );
58         assertIsomorphic( Graph.emptyGraph, du );
59         L.add( triple( "x P y" ) );
60         assertIsomorphic( graphWith( "x P y" ), du );
61         R.add( triple( "A rdf:type Route" ) );
62         assertIsomorphic( graphWith( "x P y; A rdf:type Route" ), du );
63         }
64     
65     public void testRemoveBoth()
66         {
67         Graph L = graphWith( "x R y; a P b" ), R = graphWith( "x R y; p Q r" );
68         Graph du = new DisjointUnion( L, R );
69         du.delete( triple( "x R y" ) );
70         assertIsomorphic( graphWith( "a P b" ), L );
71         assertIsomorphic( graphWith( "p Q r" ), R );
72         }
73     
74     public void testAddLeftOnlyIfNecessary()
75         {
76         Graph L = graphWith( "" ), R = graphWith( "x R y" );
77         Graph du = new DisjointUnion( L, R );
78         graphAdd( du, "x R y" );
79         assertEquals( true, L.isEmpty() );
80         graphAdd( du, " a P b" );
81         assertIsomorphic( graphWith( "a P b" ), L );
82         assertIsomorphic( graphWith( "x R y" ), R );
83         }
84     }
85
86
87 /*
88     (c) Copyright 2004, 2005 Hewlett-Packard Development Company, LP
89     All rights reserved.
90     
91     Redistribution and use in source and binary forms, with or without
92     modification, are permitted provided that the following conditions
93     are met:
94     
95     1. Redistributions of source code must retain the above copyright
96        notice, this list of conditions and the following disclaimer.
97     
98     2. Redistributions in binary form must reproduce the above copyright
99        notice, this list of conditions and the following disclaimer in the
100        documentation and/or other materials provided with the distribution.
101     
102     3. The name of the author may not be used to endorse or promote products
103        derived from this software without specific prior written permission.
104     
105     THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
106     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
107     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
108     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
109     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
110     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
111     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
112     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
113     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
114     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
115 */
Popular Tags