KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > regression > testMatch


1 /*
2     (c) Copyright 2001, 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
3     [See end of file]
4     $Id: testMatch.java,v 1.8 2005/02/21 12:18:40 andy_seaborne Exp $
5 */

6 package com.hp.hpl.jena.regression;
7
8 import com.hp.hpl.jena.rdf.model.*;
9
10 import java.util.Random JavaDoc;
11 /**
12  *
13  * @author jjc
14  * @version Release='$Name: $' Revision='$Revision: 1.8 $' Date='$Date: 2005/02/21 12:18:40 $'
15  */

16
17 public class testMatch extends java.lang.Object JavaDoc {
18     static int QUANTITY = 1;
19     static int DIMENSION = 6;
20     protected static void doTest(GetModel gm1) {
21         new testMatch(0xfab
22         //(int)System.currentTimeMillis()
23
, gm1).test();
24         System.out.println("End testMatch");
25     }
26
27     private String JavaDoc test;
28     private Random JavaDoc random;
29     private int n = 0;
30     private Model m1, m2;
31     private GetModel gm1, gm2;
32
33     /** Creates new testMatch */
34     testMatch(int seed, GetModel gm) {
35         test = "testMatch seed=" + seed;
36         random = new Random JavaDoc(seed);
37         this.gm1 = gm;
38         this.gm2 = gm;
39     }
40     
41     void test() {
42         test2HyperCube(DIMENSION, QUANTITY);
43         test4DiHyperCube(DIMENSION, QUANTITY, true);
44         test4DiHyperCube(DIMENSION, QUANTITY, false);
45         test4ToggleHyperCube(DIMENSION, QUANTITY, true);
46         test4ToggleHyperCube(DIMENSION, QUANTITY, false);
47         if (QUANTITY > 5) {
48             test2DiHyperCube(DIMENSION, QUANTITY, true);
49             test2DiHyperCube(DIMENSION, QUANTITY, false);
50             test4HyperCube(DIMENSION, QUANTITY, true);
51             test4HyperCube(DIMENSION, QUANTITY, false);
52         }
53     }
54     
55     private void test2DiHyperCube(int dim, int cnt, boolean type) {
56         try {
57             int sz = 1 << dim;
58             for (int i = 0; i < cnt; i++) {
59                 n++;
60                 m1 = gm1.get();
61                 n++;
62                 m2 = gm2.get();
63                 int a1, b1;
64                 do {
65                     a1 = random.nextInt(sz);
66                     b1 = random.nextInt(sz);
67                 } while (type != DiHyperCube.equal(a1, b1));
68                 n++;
69                 new DiHyperCube(dim, m1).dupe(a1).dupe(a1).dupe(a1);
70                 n++;
71                 new DiHyperCube(dim, m2).dupe(b1).dupe(b1).dupe(b1);
72                 n++;
73                 if (m1.isIsomorphicWith(m2) != type)
74                     error();
75             }
76
77         } catch (Exception JavaDoc e) {
78             error(e);
79         }
80     }
81     
82     private void test4DiHyperCube(int dim, int cnt, boolean type) {
83         try {
84             int sz = 1 << dim;
85             for (int i = 0; i < cnt; i++) {
86                 n++;
87                 m1 = gm1.get();
88                 n++;
89                 m2 = gm2.get();
90                 int a1, b1, a2, b2;
91                 do {
92                     a1 = random.nextInt(sz);
93                     b1 = random.nextInt(sz);
94                     a2 = random.nextInt(sz);
95                     b2 = random.nextInt(sz);
96                 } while (type != DiHyperCube.equal(a1, a2, b1, b2));
97                 n++;
98                 new DiHyperCube(dim, m1).dupe(a1).dupe(a1).dupe(a1).dupe(
99                     a2).dupe(
100                     a2).dupe(
101                     a2);
102                 n++;
103                 new DiHyperCube(dim, m2).dupe(b1).dupe(b1).dupe(b1).dupe(
104                     b2).dupe(
105                     b2).dupe(
106                     b2);
107                 n++;
108                 if (m1.isIsomorphicWith(m2) != type) {
109                     System.out.println(
110                         "(" + a1 + "," + a2 + "),(" + b1 + "," + b2 + ")");
111                     error();
112                 }
113             }
114         } catch (Exception JavaDoc e) {
115             error(e);
116         }
117     }
118
119     private void test2HyperCube(int dim, int cnt) {
120         try {
121             int sz = 1 << dim;
122
123             for (int i = 0; i < cnt; i++) {
124                 n++;
125                 m1 = gm1.get();
126                 n++;
127                 m2 = gm2.get();
128                 int a1, b1;
129                 a1 = random.nextInt(sz);
130                 b1 = random.nextInt(sz);
131                 n++;
132                 new HyperCube(dim, m1).dupe(a1).dupe(a1).dupe(a1);
133                 n++;
134                 new HyperCube(dim, m2).dupe(b1).dupe(b1).dupe(b1);
135                 n++;
136                 if (!m1.isIsomorphicWith(m2))
137                     error();
138             }
139         } catch (Exception JavaDoc e) {
140             error(e);
141         }
142     }
143     
144     private void test4HyperCube(int dim, int cnt, boolean type) {
145         try {
146             int sz = 1 << dim;
147
148             for (int i = 0; i < cnt; i++) {
149                 n++;
150                 m1 = gm1.get();
151                 n++;
152                 m2 = gm2.get();
153                 int a1, b1, a2, b2;
154                 do {
155                     a1 = random.nextInt(sz);
156                     b1 = random.nextInt(sz);
157                     a2 = random.nextInt(sz);
158                     b2 = random.nextInt(sz);
159                 } while (type != HyperCube.equal(a1, a2, b1, b2));
160                 n++;
161                 new HyperCube(dim, m1).dupe(a1).dupe(a1).dupe(a1).dupe(
162                     a2).dupe(
163                     a2).dupe(
164                     a2);
165                 n++;
166                 new HyperCube(dim, m2).dupe(b1).dupe(b1).dupe(b1).dupe(
167                     b2).dupe(
168                     b2).dupe(
169                     b2);
170                 n++;
171                 if (m1.isIsomorphicWith(m2) != type) {
172                     System.out.println(
173                         "(" + a1 + "," + a2 + "),(" + b1 + "," + b2 + ")");
174                     error();
175                 }
176             }
177         } catch (Exception JavaDoc e) {
178             error(e);
179         }
180     }
181     
182     private void test4ToggleHyperCube(int dim, int cnt, boolean type) {
183         try {
184             int sz = 1 << dim;
185
186             for (int i = 0; i < cnt; i++) {
187                 n++;
188                 m1 = gm1.get();
189                 n++;
190                 m2 = gm2.get();
191                 int a1, b1, a2, b2;
192                 do {
193                     a1 = random.nextInt(sz);
194                     b1 = random.nextInt(sz);
195                     a2 = random.nextInt(sz);
196                     b2 = random.nextInt(sz);
197                 } while (type != HyperCube.equal(a1, a2, b1, b2));
198                 n++;
199                 new HyperCube(dim, m1).toggle(a1, a2);
200                 n++;
201                 new HyperCube(dim, m2).toggle(b1, b2);
202                 n++;
203                 if (m1.isIsomorphicWith(m2) != type) {
204                     System.out.println(
205                         "(" + a1 + "," + a2 + "),(" + b1 + "," + b2 + ")");
206                     error();
207                 }
208             }
209         } catch (Exception JavaDoc e) {
210             error(e);
211         }
212     }
213     
214     private boolean inError = false;
215     
216     private void error() {
217         System.out.println(test + ": failed test " + Integer.toString(n));
218         inError = true;
219     }
220     
221     public void error(Exception JavaDoc e) {
222         System.out.println(
223             "Test Failed: " + test + " " + n + " " + e.toString());
224         inError = true;
225         e.printStackTrace();
226     }
227     
228     public boolean getErrors() {
229         return inError;
230     }
231 }
232
233 /*
234  * (c) Copyright 2001,2003, 2004, 2005 Hewlett-Packard Development Company, LP
235  * All rights reserved.
236  *
237  * Redistribution and use in source and binary forms, with or without
238  * modification, are permitted provided that the following conditions
239  * are met:
240  * 1. Redistributions of source code must retain the above copyright
241  * notice, this list of conditions and the following disclaimer.
242  * 2. Redistributions in binary form must reproduce the above copyright
243  * notice, this list of conditions and the following disclaimer in the
244  * documentation and/or other materials provided with the distribution.
245  * 3. The name of the author may not be used to endorse or promote products
246  * derived from this software without specific prior written permission.
247
248  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
249  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
250  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
251  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
252  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
253  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
254  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
255  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
256  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
257  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
258  *
259  * $Id: testMatch.java,v 1.8 2005/02/21 12:18:40 andy_seaborne Exp $
260  *
261  * testMatch.java
262  *
263  * Created on June 29, 2001, 9:36 PM
264  */

265
Popular Tags