001: /*
002: (c) Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003: [See end of file]
004: $Id: testMatch.java,v 1.11 2008/01/02 12:07:04 andy_seaborne Exp $
005: */
006: package com.hp.hpl.jena.regression;
007:
008: import com.hp.hpl.jena.rdf.model.*;
009:
010: import java.util.Random;
011:
012: /**
013: *
014: * @author jjc
015: * @version Release='$Name: $' Revision='$Revision: 1.11 $' Date='$Date: 2008/01/02 12:07:04 $'
016: */
017:
018: public class testMatch extends java.lang.Object {
019: static int QUANTITY = 1;
020: static int DIMENSION = 6;
021:
022: protected static void doTest(GetModel gm1) {
023: new testMatch(0xfab
024: //(int)System.currentTimeMillis()
025: , gm1).test();
026: System.out.println("End testMatch");
027: }
028:
029: private String test;
030: private Random random;
031: private int n = 0;
032: private Model m1, m2;
033: private GetModel gm1, gm2;
034:
035: /** Creates new testMatch */
036: testMatch(int seed, GetModel gm) {
037: test = "testMatch seed=" + seed;
038: random = new Random(seed);
039: this .gm1 = gm;
040: this .gm2 = gm;
041: }
042:
043: void test() {
044: test2HyperCube(DIMENSION, QUANTITY);
045: test4DiHyperCube(DIMENSION, QUANTITY, true);
046: test4DiHyperCube(DIMENSION, QUANTITY, false);
047: test4ToggleHyperCube(DIMENSION, QUANTITY, true);
048: test4ToggleHyperCube(DIMENSION, QUANTITY, false);
049: if (QUANTITY > 5) {
050: test2DiHyperCube(DIMENSION, QUANTITY, true);
051: test2DiHyperCube(DIMENSION, QUANTITY, false);
052: test4HyperCube(DIMENSION, QUANTITY, true);
053: test4HyperCube(DIMENSION, QUANTITY, false);
054: }
055: }
056:
057: private void test2DiHyperCube(int dim, int cnt, boolean type) {
058: try {
059: int sz = 1 << dim;
060: for (int i = 0; i < cnt; i++) {
061: n++;
062: m1 = gm1.get();
063: n++;
064: m2 = gm2.get();
065: int a1, b1;
066: do {
067: a1 = random.nextInt(sz);
068: b1 = random.nextInt(sz);
069: } while (type != DiHyperCube.equal(a1, b1));
070: n++;
071: new DiHyperCube(dim, m1).dupe(a1).dupe(a1).dupe(a1);
072: n++;
073: new DiHyperCube(dim, m2).dupe(b1).dupe(b1).dupe(b1);
074: n++;
075: if (m1.isIsomorphicWith(m2) != type)
076: error();
077: }
078:
079: } catch (Exception e) {
080: error(e);
081: }
082: }
083:
084: private void test4DiHyperCube(int dim, int cnt, boolean type) {
085: try {
086: int sz = 1 << dim;
087: for (int i = 0; i < cnt; i++) {
088: n++;
089: m1 = gm1.get();
090: n++;
091: m2 = gm2.get();
092: int a1, b1, a2, b2;
093: do {
094: a1 = random.nextInt(sz);
095: b1 = random.nextInt(sz);
096: a2 = random.nextInt(sz);
097: b2 = random.nextInt(sz);
098: } while (type != DiHyperCube.equal(a1, a2, b1, b2));
099: n++;
100: new DiHyperCube(dim, m1).dupe(a1).dupe(a1).dupe(a1)
101: .dupe(a2).dupe(a2).dupe(a2);
102: n++;
103: new DiHyperCube(dim, m2).dupe(b1).dupe(b1).dupe(b1)
104: .dupe(b2).dupe(b2).dupe(b2);
105: n++;
106: if (m1.isIsomorphicWith(m2) != type) {
107: System.out.println("(" + a1 + "," + a2 + "),(" + b1
108: + "," + b2 + ")");
109: error();
110: }
111: }
112: } catch (Exception e) {
113: error(e);
114: }
115: }
116:
117: private void test2HyperCube(int dim, int cnt) {
118: try {
119: int sz = 1 << dim;
120:
121: for (int i = 0; i < cnt; i++) {
122: n++;
123: m1 = gm1.get();
124: n++;
125: m2 = gm2.get();
126: int a1, b1;
127: a1 = random.nextInt(sz);
128: b1 = random.nextInt(sz);
129: n++;
130: new HyperCube(dim, m1).dupe(a1).dupe(a1).dupe(a1);
131: n++;
132: new HyperCube(dim, m2).dupe(b1).dupe(b1).dupe(b1);
133: n++;
134: if (!m1.isIsomorphicWith(m2))
135: error();
136: }
137: } catch (Exception e) {
138: error(e);
139: }
140: }
141:
142: private void test4HyperCube(int dim, int cnt, boolean type) {
143: try {
144: int sz = 1 << dim;
145:
146: for (int i = 0; i < cnt; i++) {
147: n++;
148: m1 = gm1.get();
149: n++;
150: m2 = gm2.get();
151: int a1, b1, a2, b2;
152: do {
153: a1 = random.nextInt(sz);
154: b1 = random.nextInt(sz);
155: a2 = random.nextInt(sz);
156: b2 = random.nextInt(sz);
157: } while (type != HyperCube.equal(a1, a2, b1, b2));
158: n++;
159: new HyperCube(dim, m1).dupe(a1).dupe(a1).dupe(a1).dupe(
160: a2).dupe(a2).dupe(a2);
161: n++;
162: new HyperCube(dim, m2).dupe(b1).dupe(b1).dupe(b1).dupe(
163: b2).dupe(b2).dupe(b2);
164: n++;
165: if (m1.isIsomorphicWith(m2) != type) {
166: System.out.println("(" + a1 + "," + a2 + "),(" + b1
167: + "," + b2 + ")");
168: error();
169: }
170: }
171: } catch (Exception e) {
172: error(e);
173: }
174: }
175:
176: private void test4ToggleHyperCube(int dim, int cnt, boolean type) {
177: try {
178: int sz = 1 << dim;
179:
180: for (int i = 0; i < cnt; i++) {
181: n++;
182: m1 = gm1.get();
183: n++;
184: m2 = gm2.get();
185: int a1, b1, a2, b2;
186: do {
187: a1 = random.nextInt(sz);
188: b1 = random.nextInt(sz);
189: a2 = random.nextInt(sz);
190: b2 = random.nextInt(sz);
191: } while (type != HyperCube.equal(a1, a2, b1, b2));
192: n++;
193: new HyperCube(dim, m1).toggle(a1, a2);
194: n++;
195: new HyperCube(dim, m2).toggle(b1, b2);
196: n++;
197: if (m1.isIsomorphicWith(m2) != type) {
198: System.out.println("(" + a1 + "," + a2 + "),(" + b1
199: + "," + b2 + ")");
200: error();
201: }
202: }
203: } catch (Exception e) {
204: error(e);
205: }
206: }
207:
208: private boolean inError = false;
209:
210: private void error() {
211: System.out.println(test + ": failed test "
212: + Integer.toString(n));
213: inError = true;
214: }
215:
216: public void error(Exception e) {
217: System.out.println("Test Failed: " + test + " " + n + " "
218: + e.toString());
219: inError = true;
220: e.printStackTrace();
221: }
222:
223: public boolean getErrors() {
224: return inError;
225: }
226: }
227:
228: /*
229: * (c) Copyright 2001,2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
230: * All rights reserved.
231: *
232: * Redistribution and use in source and binary forms, with or without
233: * modification, are permitted provided that the following conditions
234: * are met:
235: * 1. Redistributions of source code must retain the above copyright
236: * notice, this list of conditions and the following disclaimer.
237: * 2. Redistributions in binary form must reproduce the above copyright
238: * notice, this list of conditions and the following disclaimer in the
239: * documentation and/or other materials provided with the distribution.
240: * 3. The name of the author may not be used to endorse or promote products
241: * derived from this software without specific prior written permission.
242:
243: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
244: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
245: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
246: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
247: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
248: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
249: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
250: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
251: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
252: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
253: *
254: * $Id: testMatch.java,v 1.11 2008/01/02 12:07:04 andy_seaborne Exp $
255: *
256: * testMatch.java
257: *
258: * Created on June 29, 2001, 9:36 PM
259: */
|