1 32 33 package com.jeantessier.metrics; 34 35 import junit.framework.*; 36 37 import org.apache.log4j.*; 38 39 public class TestStatisticalMeasurementWithMetrics extends TestCase { 40 private Metrics m1; 41 private Metrics m2; 42 private Metrics m3; 43 private Metrics m4; 44 private Metrics m5; 45 private Metrics m6; 46 private Metrics m7; 47 private Metrics m8; 48 49 private Metrics c1; 50 private Metrics c2; 51 private Metrics c3; 52 private Metrics c4; 53 54 private Metrics g1; 55 private Metrics g2; 56 57 private Metrics p; 58 59 protected void setUp() throws Exception { 60 Logger.getLogger(getClass()).info("Starting test: " + getName()); 61 62 m1 = new Metrics("a.A.a"); 63 m2 = new Metrics("a.A.b"); 64 m3 = new Metrics("a.B.a"); 65 m4 = new Metrics("a.B.b"); 66 m5 = new Metrics("b.A.a"); 67 m6 = new Metrics("b.A.b"); 68 m7 = new Metrics("b.B.a"); 69 m8 = new Metrics("b.B.b"); 70 71 m1.track("001", new CounterMeasurement(null, null, null)); 72 m1.track("011", new CounterMeasurement(null, null, null)); 73 m1.track("101", new CounterMeasurement(null, null, null)); 74 m1.track("111", new CounterMeasurement(null, null, null)); 75 m2.track("001", new CounterMeasurement(null, null, null)); 76 m2.track("011", new CounterMeasurement(null, null, null)); 77 m2.track("101", new CounterMeasurement(null, null, null)); 78 m2.track("111", new CounterMeasurement(null, null, null)); 79 m3.track("001", new CounterMeasurement(null, null, null)); 80 m3.track("011", new CounterMeasurement(null, null, null)); 81 m3.track("101", new CounterMeasurement(null, null, null)); 82 m3.track("111", new CounterMeasurement(null, null, null)); 83 m4.track("001", new CounterMeasurement(null, null, null)); 84 m4.track("011", new CounterMeasurement(null, null, null)); 85 m4.track("101", new CounterMeasurement(null, null, null)); 86 m4.track("111", new CounterMeasurement(null, null, null)); 87 m5.track("001", new CounterMeasurement(null, null, null)); 88 m5.track("011", new CounterMeasurement(null, null, null)); 89 m5.track("101", new CounterMeasurement(null, null, null)); 90 m5.track("111", new CounterMeasurement(null, null, null)); 91 m6.track("001", new CounterMeasurement(null, null, null)); 92 m6.track("011", new CounterMeasurement(null, null, null)); 93 m6.track("101", new CounterMeasurement(null, null, null)); 94 m6.track("111", new CounterMeasurement(null, null, null)); 95 m7.track("001", new CounterMeasurement(null, null, null)); 96 m7.track("011", new CounterMeasurement(null, null, null)); 97 m7.track("101", new CounterMeasurement(null, null, null)); 98 m7.track("111", new CounterMeasurement(null, null, null)); 99 m8.track("001", new CounterMeasurement(null, null, null)); 100 m8.track("011", new CounterMeasurement(null, null, null)); 101 m8.track("101", new CounterMeasurement(null, null, null)); 102 m8.track("111", new CounterMeasurement(null, null, null)); 103 104 m1.addToMeasurement("001", 1); 105 m1.addToMeasurement("011", 1); 106 m1.addToMeasurement("101", 1); 107 m1.addToMeasurement("111", 1); 108 m2.addToMeasurement("001", 1); 109 m2.addToMeasurement("011", 1); 110 m2.addToMeasurement("101", 1); 111 m2.addToMeasurement("111", 1); 112 m3.addToMeasurement("001", 1); 113 m3.addToMeasurement("011", 1); 114 m3.addToMeasurement("101", 1); 115 m3.addToMeasurement("111", 1); 116 m4.addToMeasurement("001", 1); 117 m4.addToMeasurement("011", 1); 118 m4.addToMeasurement("101", 1); 119 m4.addToMeasurement("111", 1); 120 m5.addToMeasurement("001", 1); 121 m5.addToMeasurement("011", 1); 122 m5.addToMeasurement("101", 1); 123 m5.addToMeasurement("111", 1); 124 m6.addToMeasurement("001", 1); 125 m6.addToMeasurement("011", 1); 126 m6.addToMeasurement("101", 1); 127 m6.addToMeasurement("111", 1); 128 m7.addToMeasurement("001", 1); 129 m7.addToMeasurement("011", 1); 130 m7.addToMeasurement("101", 1); 131 m7.addToMeasurement("111", 1); 132 m8.addToMeasurement("001", 1); 133 m8.addToMeasurement("011", 1); 134 m8.addToMeasurement("101", 1); 135 m8.addToMeasurement("111", 1); 136 137 c1 = new Metrics("a.A"); 138 c2 = new Metrics("a.B"); 139 c3 = new Metrics("b.A"); 140 c4 = new Metrics("b.B"); 141 142 c1.track("010", new CounterMeasurement(null, null, null)); 143 c1.track("011", new CounterMeasurement(null, null, null)); 144 c1.track("110", new CounterMeasurement(null, null, null)); 145 c1.track("111", new CounterMeasurement(null, null, null)); 146 c2.track("010", new CounterMeasurement(null, null, null)); 147 c2.track("011", new CounterMeasurement(null, null, null)); 148 c2.track("110", new CounterMeasurement(null, null, null)); 149 c2.track("111", new CounterMeasurement(null, null, null)); 150 c3.track("010", new CounterMeasurement(null, null, null)); 151 c3.track("011", new CounterMeasurement(null, null, null)); 152 c3.track("110", new CounterMeasurement(null, null, null)); 153 c3.track("111", new CounterMeasurement(null, null, null)); 154 c4.track("010", new CounterMeasurement(null, null, null)); 155 c4.track("011", new CounterMeasurement(null, null, null)); 156 c4.track("110", new CounterMeasurement(null, null, null)); 157 c4.track("111", new CounterMeasurement(null, null, null)); 158 159 c1.addToMeasurement("010", 10); 160 c1.addToMeasurement("011", 10); 161 c1.addToMeasurement("110", 10); 162 c1.addToMeasurement("111", 10); 163 c2.addToMeasurement("010", 10); 164 c2.addToMeasurement("011", 10); 165 c2.addToMeasurement("110", 10); 166 c2.addToMeasurement("111", 10); 167 c3.addToMeasurement("010", 10); 168 c3.addToMeasurement("011", 10); 169 c3.addToMeasurement("110", 10); 170 c3.addToMeasurement("111", 10); 171 c4.addToMeasurement("010", 10); 172 c4.addToMeasurement("011", 10); 173 c4.addToMeasurement("110", 10); 174 c4.addToMeasurement("111", 10); 175 176 c1.addSubMetrics(m1); 177 c1.addSubMetrics(m2); 178 c2.addSubMetrics(m3); 179 c2.addSubMetrics(m4); 180 c3.addSubMetrics(m5); 181 c3.addSubMetrics(m6); 182 c4.addSubMetrics(m7); 183 c4.addSubMetrics(m8); 184 185 g1 = new Metrics("a"); 186 g2 = new Metrics("b"); 187 188 g1.track("100", new CounterMeasurement(null, null, null)); 189 g1.track("101", new CounterMeasurement(null, null, null)); 190 g1.track("110", new CounterMeasurement(null, null, null)); 191 g1.track("111", new CounterMeasurement(null, null, null)); 192 g2.track("100", new CounterMeasurement(null, null, null)); 193 g2.track("101", new CounterMeasurement(null, null, null)); 194 g2.track("110", new CounterMeasurement(null, null, null)); 195 g2.track("111", new CounterMeasurement(null, null, null)); 196 197 g1.addToMeasurement("100", 100); 198 g1.addToMeasurement("101", 100); 199 g1.addToMeasurement("110", 100); 200 g1.addToMeasurement("111", 100); 201 g2.addToMeasurement("100", 100); 202 g2.addToMeasurement("101", 100); 203 g2.addToMeasurement("110", 100); 204 g2.addToMeasurement("111", 100); 205 206 g1.addSubMetrics(c1); 207 g1.addSubMetrics(c2); 208 g2.addSubMetrics(c3); 209 g2.addSubMetrics(c4); 210 211 p = new Metrics("test"); 212 213 p.addSubMetrics(g1); 214 p.addSubMetrics(g2); 215 } 216 217 protected void tearDown() throws Exception { 218 Logger.getLogger(getClass()).info("End of " + getName()); 219 } 220 221 public void testProject() { 222 StatisticalMeasurement m000 = new StatisticalMeasurement(null, p, "000"); 223 StatisticalMeasurement m001 = new StatisticalMeasurement(null, p, "001"); 224 StatisticalMeasurement m010 = new StatisticalMeasurement(null, p, "010"); 225 StatisticalMeasurement m011 = new StatisticalMeasurement(null, p, "011"); 226 StatisticalMeasurement m100 = new StatisticalMeasurement(null, p, "100"); 227 StatisticalMeasurement m101 = new StatisticalMeasurement(null, p, "101"); 228 StatisticalMeasurement m110 = new StatisticalMeasurement(null, p, "110"); 229 StatisticalMeasurement m111 = new StatisticalMeasurement(null, p, "111"); 230 231 assertEquals("000", 0, m000.getNbDataPoints()); 232 assertEquals("001", 8, m001.getNbDataPoints()); 233 assertEquals("010", 4, m010.getNbDataPoints()); 234 assertEquals("011", 4, m011.getNbDataPoints()); 235 assertEquals("100", 2, m100.getNbDataPoints()); 236 assertEquals("101", 2, m101.getNbDataPoints()); 237 assertEquals("110", 2, m110.getNbDataPoints()); 238 assertEquals("111", 2, m111.getNbDataPoints()); 239 } 240 241 public void testGroup() { 242 StatisticalMeasurement m000 = new StatisticalMeasurement(null, g1, "000"); 243 StatisticalMeasurement m001 = new StatisticalMeasurement(null, g1, "001"); 244 StatisticalMeasurement m010 = new StatisticalMeasurement(null, g1, "010"); 245 StatisticalMeasurement m011 = new StatisticalMeasurement(null, g1, "011"); 246 StatisticalMeasurement m100 = new StatisticalMeasurement(null, g1, "100"); 247 StatisticalMeasurement m101 = new StatisticalMeasurement(null, g1, "101"); 248 StatisticalMeasurement m110 = new StatisticalMeasurement(null, g1, "110"); 249 StatisticalMeasurement m111 = new StatisticalMeasurement(null, g1, "111"); 250 251 assertEquals("000", 0, m000.getNbDataPoints()); 252 assertEquals("001", 4, m001.getNbDataPoints()); 253 assertEquals("010", 2, m010.getNbDataPoints()); 254 assertEquals("011", 2, m011.getNbDataPoints()); 255 assertEquals("100", 0, m100.getNbDataPoints()); 256 assertEquals("101", 4, m101.getNbDataPoints()); 257 assertEquals("110", 2, m110.getNbDataPoints()); 258 assertEquals("111", 2, m111.getNbDataPoints()); 259 } 260 261 public void testClass() { 262 StatisticalMeasurement m000 = new StatisticalMeasurement(null, c1, "000"); 263 StatisticalMeasurement m001 = new StatisticalMeasurement(null, c1, "001"); 264 StatisticalMeasurement m010 = new StatisticalMeasurement(null, c1, "010"); 265 StatisticalMeasurement m011 = new StatisticalMeasurement(null, c1, "011"); 266 StatisticalMeasurement m100 = new StatisticalMeasurement(null, c1, "100"); 267 StatisticalMeasurement m101 = new StatisticalMeasurement(null, c1, "101"); 268 StatisticalMeasurement m110 = new StatisticalMeasurement(null, c1, "110"); 269 StatisticalMeasurement m111 = new StatisticalMeasurement(null, c1, "111"); 270 271 assertEquals("000", 0, m000.getNbDataPoints()); 272 assertEquals("001", 2, m001.getNbDataPoints()); 273 assertEquals("010", 0, m010.getNbDataPoints()); 274 assertEquals("011", 2, m011.getNbDataPoints()); 275 assertEquals("100", 0, m100.getNbDataPoints()); 276 assertEquals("101", 2, m101.getNbDataPoints()); 277 assertEquals("110", 0, m110.getNbDataPoints()); 278 assertEquals("111", 2, m111.getNbDataPoints()); 279 } 280 281 public void testMethod() { 282 StatisticalMeasurement m000 = new StatisticalMeasurement(null, m1, "000"); 283 StatisticalMeasurement m001 = new StatisticalMeasurement(null, m1, "001"); 284 StatisticalMeasurement m010 = new StatisticalMeasurement(null, m1, "010"); 285 StatisticalMeasurement m011 = new StatisticalMeasurement(null, m1, "011"); 286 StatisticalMeasurement m100 = new StatisticalMeasurement(null, m1, "100"); 287 StatisticalMeasurement m101 = new StatisticalMeasurement(null, m1, "101"); 288 StatisticalMeasurement m110 = new StatisticalMeasurement(null, m1, "110"); 289 StatisticalMeasurement m111 = new StatisticalMeasurement(null, m1, "111"); 290 291 assertEquals("000", 0, m000.getNbDataPoints()); 292 assertEquals("001", 0, m001.getNbDataPoints()); 293 assertEquals("010", 0, m010.getNbDataPoints()); 294 assertEquals("011", 0, m011.getNbDataPoints()); 295 assertEquals("100", 0, m100.getNbDataPoints()); 296 assertEquals("101", 0, m101.getNbDataPoints()); 297 assertEquals("110", 0, m110.getNbDataPoints()); 298 assertEquals("111", 0, m111.getNbDataPoints()); 299 } 300 301 public void testIrregular() { 302 Metrics m11 = new Metrics("m11"); 303 Metrics m12 = new Metrics("m12"); 304 Metrics m21 = new Metrics("m21"); 305 Metrics m22 = new Metrics("m22"); 306 307 Metrics c1 = new Metrics("c1"); 308 Metrics c2 = new Metrics("c2"); 309 310 c1.addSubMetrics(m11); 311 c1.addSubMetrics(m12); 312 c2.addSubMetrics(m21); 313 c2.addSubMetrics(m22); 314 315 Metrics g = new Metrics("g"); 316 317 g.addSubMetrics(c1); 318 g.addSubMetrics(c2); 319 320 m11.track("bar", new CounterMeasurement(null, null, null)); 321 m12.track("bar", new CounterMeasurement(null, null, null)); 322 m21.track("bar", new CounterMeasurement(null, null, null)); 323 m22.track("bar", new CounterMeasurement(null, null, null)); 324 325 c1.track("bar", new CounterMeasurement(null, null, null)); 326 327 StatisticalMeasurement sm = new StatisticalMeasurement(null, g, "bar"); 328 assertEquals(3, sm.getNbDataPoints()); 329 } 330 } 331 | Popular Tags |