001: /*
002: (c) Copyright 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003: All rights reserved - see end of file.
004: $Id: NewRegressionSelector.java,v 1.7 2008/01/02 12:07:04 andy_seaborne Exp $
005: */
006:
007: package com.hp.hpl.jena.regression;
008:
009: import java.util.List;
010:
011: import junit.framework.*;
012:
013: import com.hp.hpl.jena.rdf.model.*;
014: import com.hp.hpl.jena.rdf.model.test.ModelTestBase;
015: import com.hp.hpl.jena.regression.Regression.*;
016:
017: public class NewRegressionSelector extends ModelTestBase {
018: public NewRegressionSelector(String name) {
019: super (name);
020: }
021:
022: public static Test suite() {
023: return new TestSuite(NewRegressionSelector.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 tearDown() {
037: m = null;
038: }
039:
040: public void test9() {
041: Model m = getModel();
042: final int num = 2;
043:
044: Resource subject[] = new Resource[num];
045: Property predicate[] = new Property[num];
046:
047: String suri = "http://aldabaran/test9/s";
048: String puri = "http://aldabaran/test9/";
049:
050: boolean tvBooleans[] = { false, true };
051: long tvLongs[] = { 123, 321 };
052: char tvChars[] = { '@', ';' };
053: double tvDoubles[] = { 123.456, 456.123 };
054: String tvStrings[] = { "test8 testing string 1",
055: "test8 testing string 2" };
056: String langs[] = { "en", "fr" };
057:
058: Literal tvLitObjs[] = {
059: m.createTypedLiteral(new LitTestObjF()),
060: m.createTypedLiteral(new LitTestObjF()) };
061: Resource tvResObjs[] = { m.createResource(new ResTestObjF()),
062: m.createResource(new ResTestObjF()) };
063:
064: for (int i = 0; i < num; i += 1) {
065: subject[i] = m.createResource(suri + i);
066: predicate[i] = m.createProperty(puri + i, "p");
067: }
068:
069: for (int i = 0; i < num; i++) {
070: for (int j = 0; j < num; j++) {
071: m.addLiteral(subject[i], predicate[j], tvBooleans[j]);
072: m.addLiteral(subject[i], predicate[j], tvLongs[j]);
073: m.addLiteral(subject[i], predicate[j], tvChars[j]);
074: m.addLiteral(subject[i], predicate[j], tvDoubles[j]);
075: m.add(subject[i], predicate[j], tvStrings[j]);
076: m.add(subject[i], predicate[j], tvStrings[j], langs[j]);
077: m.add(subject[i], predicate[j], tvLitObjs[j]);
078: m.add(subject[i], predicate[j], tvResObjs[j]);
079: }
080: }
081:
082: StmtIterator it1 = m.listStatements(new SimpleSelector(null,
083: null, (RDFNode) null));
084: List L1 = iteratorToList(it1);
085: assertEquals(num * num * 8, L1.size());
086:
087: StmtIterator it2 = m.listStatements(new SimpleSelector(
088: subject[0], null, (RDFNode) null));
089: List L2 = iteratorToList(it2);
090: for (int i = 0; i < L2.size(); i += 1)
091: assertEquals(subject[0], ((Statement) L2.get(i))
092: .getSubject());
093: assertEquals(num * 8, L2.size());
094:
095: StmtIterator it3 = m.listStatements(new SimpleSelector(null,
096: predicate[1], (RDFNode) null));
097: List L3 = iteratorToList(it3);
098: for (int i = 0; i < L3.size(); i += 1)
099: assertEquals(predicate[1], ((Statement) L3.get(i))
100: .getPredicate());
101: assertEquals(num * 8, L3.size());
102:
103: StmtIterator it4 = m.listStatements(new SimpleSelector(null,
104: null, tvResObjs[1]));
105: List L4 = iteratorToList(it4);
106: for (int i = 0; i < L4.size(); i += 1)
107: assertEquals(tvResObjs[1], ((Statement) L4.get(i))
108: .getObject());
109: assertEquals(2, L4.size());
110:
111: StmtIterator it5 = m.listStatements(new SimpleSelector(null,
112: null, m.createTypedLiteral(false)));
113: List L5 = iteratorToList(it5);
114: for (int i = 0; i < L5.size(); i += 1)
115: assertEquals(false, ((Statement) L5.get(i)).getBoolean());
116: assertEquals(2, L5.size());
117:
118: StmtIterator it6 = m.listStatements(new SimpleSelector(null,
119: null, tvStrings[1], langs[1]));
120: List L6 = iteratorToList(it6);
121: for (int i = 0; i < L6.size(); i += 1)
122: assertEquals(langs[1], ((Statement) L6.get(i))
123: .getLanguage());
124: assertEquals(2, L6.size());
125: }
126: }
127:
128: /*
129: * (c) Copyright 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
130: * All rights reserved.
131: *
132: * Redistribution and use in source and binary forms, with or without
133: * modification, are permitted provided that the following conditions
134: * are met:
135: * 1. Redistributions of source code must retain the above copyright
136: * notice, this list of conditions and the following disclaimer.
137: * 2. Redistributions in binary form must reproduce the above copyright
138: * notice, this list of conditions and the following disclaimer in the
139: * documentation and/or other materials provided with the distribution.
140: * 3. The name of the author may not be used to endorse or promote products
141: * derived from this software without specific prior written permission.
142: *
143: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
144: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
145: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
146: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
147: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
148: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
149: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
150: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
151: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
152: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
153: */
|