1 6 package com.hp.hpl.jena.regression; 7 8 import com.hp.hpl.jena.rdf.model.*; 9 10 import java.util.Random ; 11 16 17 public class testMatch extends java.lang.Object { 18 static int QUANTITY = 1; 19 static int DIMENSION = 6; 20 protected static void doTest(GetModel gm1) { 21 new testMatch(0xfab 22 , gm1).test(); 24 System.out.println("End testMatch"); 25 } 26 27 private String test; 28 private Random random; 29 private int n = 0; 30 private Model m1, m2; 31 private GetModel gm1, gm2; 32 33 34 testMatch(int seed, GetModel gm) { 35 test = "testMatch seed=" + seed; 36 random = new Random (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 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 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 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 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 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 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 265 | Popular Tags |