001: /*
002: (c) Copyright 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003: All rights reserved - see end of file.
004: $Id: NewRegressionContainerMethods.java,v 1.5 2008/01/02 12:07:04 andy_seaborne Exp $
005: */
006:
007: package com.hp.hpl.jena.regression;
008:
009: import com.hp.hpl.jena.rdf.model.*;
010: import com.hp.hpl.jena.regression.Regression.ResTestObjF;
011: import com.hp.hpl.jena.vocabulary.RDF;
012:
013: public abstract class NewRegressionContainerMethods extends
014: NewRegressionBase {
015: public NewRegressionContainerMethods(String name) {
016: super (name);
017: }
018:
019: protected Model getModel() {
020: return ModelFactory.createDefaultModel();
021: }
022:
023: protected Model m;
024: protected Resource r;
025:
026: public void setUp() {
027: m = getModel();
028: r = m.createResource();
029: }
030:
031: protected abstract Container createContainer();
032:
033: protected abstract Resource getContainerType();
034:
035: public void testEmptyContainer() {
036: Container c = createContainer();
037: assertTrue(m.contains(c, RDF.type, getContainerType()));
038: assertEquals(0, c.size());
039: assertFalse(c.contains(tvBoolean));
040: assertFalse(c.contains(tvByte));
041: assertFalse(c.contains(tvShort));
042: assertFalse(c.contains(tvInt));
043: assertFalse(c.contains(tvLong));
044: assertFalse(c.contains(tvChar));
045: assertFalse(c.contains(tvFloat));
046: assertFalse(c.contains(tvString));
047: }
048:
049: public void testFillingContainer() {
050: Container c = createContainer();
051: String lang = "fr";
052: Literal tvLiteral = m.createLiteral("test 12 string 2");
053: Resource tvResObj = m.createResource(new ResTestObjF());
054: c.add(tvBoolean);
055: assertTrue(c.contains(tvBoolean));
056: c.add(tvByte);
057: assertTrue(c.contains(tvByte));
058: c.add(tvShort);
059: assertTrue(c.contains(tvShort));
060: c.add(tvInt);
061: assertTrue(c.contains(tvInt));
062: c.add(tvLong);
063: assertTrue(c.contains(tvLong));
064: c.add(tvChar);
065: assertTrue(c.contains(tvChar));
066: c.add(tvFloat);
067: assertTrue(c.contains(tvFloat));
068: c.add(tvString);
069: assertTrue(c.contains(tvString));
070: c.add(tvString, lang);
071: assertTrue(c.contains(tvString, lang));
072: c.add(tvLiteral);
073: assertTrue(c.contains(tvLiteral));
074: c.add(tvResObj);
075: assertTrue(c.contains(tvResObj));
076: c.add(tvLitObj);
077: assertTrue(c.contains(tvLitObj));
078: assertEquals(12, c.size());
079: }
080:
081: public void testContainerOfIntegers() {
082: int num = 10;
083: Container c = createContainer();
084: for (int i = 0; i < num; i += 1)
085: c.add(i);
086: assertEquals(num, c.size());
087: NodeIterator it = c.iterator();
088: for (int i = 0; i < num; i += 1)
089: assertEquals(i, ((Literal) it.nextNode()).getInt());
090: assertFalse(it.hasNext());
091: }
092:
093: public void testContainerOfIntegersRemovingA() {
094: boolean[] retain = { true, true, true, false, false, false,
095: false, false, true, true };
096: testContainerOfIntegersWithRemoving(retain);
097: }
098:
099: public void testContainerOfIntegersRemovingB() {
100: boolean[] retain = { false, true, true, false, false, false,
101: false, false, true, false };
102: testContainerOfIntegersWithRemoving(retain);
103: }
104:
105: public void testContainerOfIntegersRemovingC() {
106: boolean[] retain = { false, false, false, false, false, false,
107: false, false, false, false };
108: testContainerOfIntegersWithRemoving(retain);
109: }
110:
111: protected void testContainerOfIntegersWithRemoving(boolean[] retain) {
112: final int num = retain.length;
113: boolean[] found = new boolean[num];
114: Container c = createContainer();
115: for (int i = 0; i < num; i += 1)
116: c.add(i);
117: NodeIterator it = c.iterator();
118: for (int i = 0; i < num; i += 1) {
119: it.nextNode();
120: if (retain[i] == false)
121: it.remove();
122: }
123: NodeIterator s = c.iterator();
124: while (s.hasNext()) {
125: int v = ((Literal) s.nextNode()).getInt();
126: assertFalse(found[v]);
127: found[v] = true;
128: }
129: for (int i = 0; i < num; i += 1)
130: assertEquals("element " + i, retain[i], found[i]);
131: }
132: }
133:
134: /*
135: * (c) Copyright 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
136: * All rights reserved.
137: *
138: * Redistribution and use in source and binary forms, with or without
139: * modification, are permitted provided that the following conditions
140: * are met:
141: * 1. Redistributions of source code must retain the above copyright
142: * notice, this list of conditions and the following disclaimer.
143: * 2. Redistributions in binary form must reproduce the above copyright
144: * notice, this list of conditions and the following disclaimer in the
145: * documentation and/or other materials provided with the distribution.
146: * 3. The name of the author may not be used to endorse or promote products
147: * derived from this software without specific prior written permission.
148: *
149: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
150: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
151: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
152: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
153: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
154: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
155: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
156: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
157: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
158: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
159: */
|