001: /*
002: (c) Copyright 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003: All rights reserved - see end of file.
004: $Id: NewRegressionSet.java,v 1.4 2008/01/02 12:07:05 andy_seaborne Exp $
005: */
006:
007: package com.hp.hpl.jena.regression;
008:
009: import com.hp.hpl.jena.rdf.model.*;
010:
011: import junit.framework.*;
012:
013: /**
014: A revamped version of the regression set-operation tests.
015: @author kers
016: */
017: public class NewRegressionSet extends NewRegressionBase {
018: public NewRegressionSet(String name) {
019: super (name);
020: }
021:
022: public static Test suite() {
023: return new TestSuite(NewRegressionSet.class);
024: }
025:
026: protected Model getModel() {
027: return ModelFactory.createDefaultModel();
028: }
029:
030: protected Model m;
031:
032: public void setUp() {
033: m = getModel();
034: }
035:
036: public void testUnion() {
037: Model m1 = getModel();
038: Model m2 = getModel();
039: modelAdd(m1, "a P b; w R x");
040: modelAdd(m2, "w R x; y S z");
041: Model um = m1.union(m2);
042: assertFalse(m1.containsAll(m2));
043: assertFalse(m2.containsAll(m1));
044: assertTrue(um.containsAll(m1));
045: assertTrue(um.containsAll(m2));
046: for (StmtIterator it = um.listStatements(); it.hasNext();) {
047: Statement s = it.nextStatement();
048: assertTrue(m1.contains(s) || m2.contains(s));
049: }
050: for (StmtIterator it = m1.listStatements(); it.hasNext();)
051: assertTrue(um.contains(it.nextStatement()));
052: for (StmtIterator it = m2.listStatements(); it.hasNext();)
053: assertTrue(um.contains(it.nextStatement()));
054: assertTrue(um.containsAll(m1.listStatements()));
055: assertTrue(um.containsAll(m2.listStatements()));
056: }
057:
058: public void testIntersection() {
059: Model m1 = getModel();
060: Model m2 = getModel();
061: modelAdd(m1, "a P b; w R x");
062: modelAdd(m2, "w R x; y S z");
063: Model im = m1.intersection(m2);
064: assertFalse(m1.containsAll(m2));
065: assertFalse(m2.containsAll(m1));
066: assertTrue(m1.containsAll(im));
067: assertTrue(m2.containsAll(im));
068: for (StmtIterator it = im.listStatements(); it.hasNext();) {
069: Statement s = it.nextStatement();
070: assertTrue(m1.contains(s) && m2.contains(s));
071: }
072: for (StmtIterator it = im.listStatements(); it.hasNext();)
073: assertTrue(m1.contains(it.nextStatement()));
074: for (StmtIterator it = im.listStatements(); it.hasNext();)
075: assertTrue(m2.contains(it.nextStatement()));
076: assertTrue(m1.containsAll(im.listStatements()));
077: assertTrue(m2.containsAll(im.listStatements()));
078: }
079:
080: public void testDifference() {
081: Model m1 = getModel();
082: Model m2 = getModel();
083: modelAdd(m1, "a P b; w R x");
084: modelAdd(m2, "w R x; y S z");
085: Model dm = m1.difference(m2);
086: for (StmtIterator it = dm.listStatements(); it.hasNext();) {
087: Statement s = it.nextStatement();
088: assertTrue(m1.contains(s) && !m2.contains(s));
089: }
090: for (StmtIterator it = m1.union(m2).listStatements(); it
091: .hasNext();) {
092: Statement s = it.nextStatement();
093: assertEquals(m1.contains(s) && !m2.contains(s), dm
094: .contains(s));
095: }
096: assertTrue(dm.containsAny(m1));
097: assertTrue(dm.containsAny(m1.listStatements()));
098: assertFalse(dm.containsAny(m2));
099: assertFalse(dm.containsAny(m2.listStatements()));
100: assertTrue(m1.containsAll(dm));
101: }
102: }
103:
104: /*
105: * (c) Copyright 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
106: * All rights reserved.
107: *
108: * Redistribution and use in source and binary forms, with or without
109: * modification, are permitted provided that the following conditions
110: * are met:
111: * 1. Redistributions of source code must retain the above copyright
112: * notice, this list of conditions and the following disclaimer.
113: * 2. Redistributions in binary form must reproduce the above copyright
114: * notice, this list of conditions and the following disclaimer in the
115: * documentation and/or other materials provided with the distribution.
116: * 3. The name of the author may not be used to endorse or promote products
117: * derived from this software without specific prior written permission.
118: *
119: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
120: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
121: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
122: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
123: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
124: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
125: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
126: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
127: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
128: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
129: */
|