001: /*
002: * Copyright (c) 2001-2007, Jean Tessier
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms, with or without
006: * modification, are permitted provided that the following conditions
007: * are met:
008: *
009: * * Redistributions of source code must retain the above copyright
010: * notice, this list of conditions and the following disclaimer.
011: *
012: * * Redistributions in binary form must reproduce the above copyright
013: * notice, this list of conditions and the following disclaimer in the
014: * documentation and/or other materials provided with the distribution.
015: *
016: * * Neither the name of Jean Tessier nor the names of his contributors
017: * may be used to endorse or promote products derived from this software
018: * without specific prior written permission.
019: *
020: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
021: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
022: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
023: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
024: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
025: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
026: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
027: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
028: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
029: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
030: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
031: */
032:
033: package com.jeantessier.metrics;
034:
035: import junit.framework.*;
036:
037: import org.apache.log4j.*;
038:
039: public class TestStatisticalMeasurementWithMetrics extends TestCase {
040: private Metrics m1;
041: private Metrics m2;
042: private Metrics m3;
043: private Metrics m4;
044: private Metrics m5;
045: private Metrics m6;
046: private Metrics m7;
047: private Metrics m8;
048:
049: private Metrics c1;
050: private Metrics c2;
051: private Metrics c3;
052: private Metrics c4;
053:
054: private Metrics g1;
055: private Metrics g2;
056:
057: private Metrics p;
058:
059: protected void setUp() throws Exception {
060: Logger.getLogger(getClass())
061: .info("Starting test: " + getName());
062:
063: m1 = new Metrics("a.A.a");
064: m2 = new Metrics("a.A.b");
065: m3 = new Metrics("a.B.a");
066: m4 = new Metrics("a.B.b");
067: m5 = new Metrics("b.A.a");
068: m6 = new Metrics("b.A.b");
069: m7 = new Metrics("b.B.a");
070: m8 = new Metrics("b.B.b");
071:
072: m1.track("001", new CounterMeasurement(null, null, null));
073: m1.track("011", new CounterMeasurement(null, null, null));
074: m1.track("101", new CounterMeasurement(null, null, null));
075: m1.track("111", new CounterMeasurement(null, null, null));
076: m2.track("001", new CounterMeasurement(null, null, null));
077: m2.track("011", new CounterMeasurement(null, null, null));
078: m2.track("101", new CounterMeasurement(null, null, null));
079: m2.track("111", new CounterMeasurement(null, null, null));
080: m3.track("001", new CounterMeasurement(null, null, null));
081: m3.track("011", new CounterMeasurement(null, null, null));
082: m3.track("101", new CounterMeasurement(null, null, null));
083: m3.track("111", new CounterMeasurement(null, null, null));
084: m4.track("001", new CounterMeasurement(null, null, null));
085: m4.track("011", new CounterMeasurement(null, null, null));
086: m4.track("101", new CounterMeasurement(null, null, null));
087: m4.track("111", new CounterMeasurement(null, null, null));
088: m5.track("001", new CounterMeasurement(null, null, null));
089: m5.track("011", new CounterMeasurement(null, null, null));
090: m5.track("101", new CounterMeasurement(null, null, null));
091: m5.track("111", new CounterMeasurement(null, null, null));
092: m6.track("001", new CounterMeasurement(null, null, null));
093: m6.track("011", new CounterMeasurement(null, null, null));
094: m6.track("101", new CounterMeasurement(null, null, null));
095: m6.track("111", new CounterMeasurement(null, null, null));
096: m7.track("001", new CounterMeasurement(null, null, null));
097: m7.track("011", new CounterMeasurement(null, null, null));
098: m7.track("101", new CounterMeasurement(null, null, null));
099: m7.track("111", new CounterMeasurement(null, null, null));
100: m8.track("001", new CounterMeasurement(null, null, null));
101: m8.track("011", new CounterMeasurement(null, null, null));
102: m8.track("101", new CounterMeasurement(null, null, null));
103: m8.track("111", new CounterMeasurement(null, null, null));
104:
105: m1.addToMeasurement("001", 1);
106: m1.addToMeasurement("011", 1);
107: m1.addToMeasurement("101", 1);
108: m1.addToMeasurement("111", 1);
109: m2.addToMeasurement("001", 1);
110: m2.addToMeasurement("011", 1);
111: m2.addToMeasurement("101", 1);
112: m2.addToMeasurement("111", 1);
113: m3.addToMeasurement("001", 1);
114: m3.addToMeasurement("011", 1);
115: m3.addToMeasurement("101", 1);
116: m3.addToMeasurement("111", 1);
117: m4.addToMeasurement("001", 1);
118: m4.addToMeasurement("011", 1);
119: m4.addToMeasurement("101", 1);
120: m4.addToMeasurement("111", 1);
121: m5.addToMeasurement("001", 1);
122: m5.addToMeasurement("011", 1);
123: m5.addToMeasurement("101", 1);
124: m5.addToMeasurement("111", 1);
125: m6.addToMeasurement("001", 1);
126: m6.addToMeasurement("011", 1);
127: m6.addToMeasurement("101", 1);
128: m6.addToMeasurement("111", 1);
129: m7.addToMeasurement("001", 1);
130: m7.addToMeasurement("011", 1);
131: m7.addToMeasurement("101", 1);
132: m7.addToMeasurement("111", 1);
133: m8.addToMeasurement("001", 1);
134: m8.addToMeasurement("011", 1);
135: m8.addToMeasurement("101", 1);
136: m8.addToMeasurement("111", 1);
137:
138: c1 = new Metrics("a.A");
139: c2 = new Metrics("a.B");
140: c3 = new Metrics("b.A");
141: c4 = new Metrics("b.B");
142:
143: c1.track("010", new CounterMeasurement(null, null, null));
144: c1.track("011", new CounterMeasurement(null, null, null));
145: c1.track("110", new CounterMeasurement(null, null, null));
146: c1.track("111", new CounterMeasurement(null, null, null));
147: c2.track("010", new CounterMeasurement(null, null, null));
148: c2.track("011", new CounterMeasurement(null, null, null));
149: c2.track("110", new CounterMeasurement(null, null, null));
150: c2.track("111", new CounterMeasurement(null, null, null));
151: c3.track("010", new CounterMeasurement(null, null, null));
152: c3.track("011", new CounterMeasurement(null, null, null));
153: c3.track("110", new CounterMeasurement(null, null, null));
154: c3.track("111", new CounterMeasurement(null, null, null));
155: c4.track("010", new CounterMeasurement(null, null, null));
156: c4.track("011", new CounterMeasurement(null, null, null));
157: c4.track("110", new CounterMeasurement(null, null, null));
158: c4.track("111", new CounterMeasurement(null, null, null));
159:
160: c1.addToMeasurement("010", 10);
161: c1.addToMeasurement("011", 10);
162: c1.addToMeasurement("110", 10);
163: c1.addToMeasurement("111", 10);
164: c2.addToMeasurement("010", 10);
165: c2.addToMeasurement("011", 10);
166: c2.addToMeasurement("110", 10);
167: c2.addToMeasurement("111", 10);
168: c3.addToMeasurement("010", 10);
169: c3.addToMeasurement("011", 10);
170: c3.addToMeasurement("110", 10);
171: c3.addToMeasurement("111", 10);
172: c4.addToMeasurement("010", 10);
173: c4.addToMeasurement("011", 10);
174: c4.addToMeasurement("110", 10);
175: c4.addToMeasurement("111", 10);
176:
177: c1.addSubMetrics(m1);
178: c1.addSubMetrics(m2);
179: c2.addSubMetrics(m3);
180: c2.addSubMetrics(m4);
181: c3.addSubMetrics(m5);
182: c3.addSubMetrics(m6);
183: c4.addSubMetrics(m7);
184: c4.addSubMetrics(m8);
185:
186: g1 = new Metrics("a");
187: g2 = new Metrics("b");
188:
189: g1.track("100", new CounterMeasurement(null, null, null));
190: g1.track("101", new CounterMeasurement(null, null, null));
191: g1.track("110", new CounterMeasurement(null, null, null));
192: g1.track("111", new CounterMeasurement(null, null, null));
193: g2.track("100", new CounterMeasurement(null, null, null));
194: g2.track("101", new CounterMeasurement(null, null, null));
195: g2.track("110", new CounterMeasurement(null, null, null));
196: g2.track("111", new CounterMeasurement(null, null, null));
197:
198: g1.addToMeasurement("100", 100);
199: g1.addToMeasurement("101", 100);
200: g1.addToMeasurement("110", 100);
201: g1.addToMeasurement("111", 100);
202: g2.addToMeasurement("100", 100);
203: g2.addToMeasurement("101", 100);
204: g2.addToMeasurement("110", 100);
205: g2.addToMeasurement("111", 100);
206:
207: g1.addSubMetrics(c1);
208: g1.addSubMetrics(c2);
209: g2.addSubMetrics(c3);
210: g2.addSubMetrics(c4);
211:
212: p = new Metrics("test");
213:
214: p.addSubMetrics(g1);
215: p.addSubMetrics(g2);
216: }
217:
218: protected void tearDown() throws Exception {
219: Logger.getLogger(getClass()).info("End of " + getName());
220: }
221:
222: public void testProject() {
223: StatisticalMeasurement m000 = new StatisticalMeasurement(null,
224: p, "000");
225: StatisticalMeasurement m001 = new StatisticalMeasurement(null,
226: p, "001");
227: StatisticalMeasurement m010 = new StatisticalMeasurement(null,
228: p, "010");
229: StatisticalMeasurement m011 = new StatisticalMeasurement(null,
230: p, "011");
231: StatisticalMeasurement m100 = new StatisticalMeasurement(null,
232: p, "100");
233: StatisticalMeasurement m101 = new StatisticalMeasurement(null,
234: p, "101");
235: StatisticalMeasurement m110 = new StatisticalMeasurement(null,
236: p, "110");
237: StatisticalMeasurement m111 = new StatisticalMeasurement(null,
238: p, "111");
239:
240: assertEquals("000", 0, m000.getNbDataPoints());
241: assertEquals("001", 8, m001.getNbDataPoints());
242: assertEquals("010", 4, m010.getNbDataPoints());
243: assertEquals("011", 4, m011.getNbDataPoints());
244: assertEquals("100", 2, m100.getNbDataPoints());
245: assertEquals("101", 2, m101.getNbDataPoints());
246: assertEquals("110", 2, m110.getNbDataPoints());
247: assertEquals("111", 2, m111.getNbDataPoints());
248: }
249:
250: public void testGroup() {
251: StatisticalMeasurement m000 = new StatisticalMeasurement(null,
252: g1, "000");
253: StatisticalMeasurement m001 = new StatisticalMeasurement(null,
254: g1, "001");
255: StatisticalMeasurement m010 = new StatisticalMeasurement(null,
256: g1, "010");
257: StatisticalMeasurement m011 = new StatisticalMeasurement(null,
258: g1, "011");
259: StatisticalMeasurement m100 = new StatisticalMeasurement(null,
260: g1, "100");
261: StatisticalMeasurement m101 = new StatisticalMeasurement(null,
262: g1, "101");
263: StatisticalMeasurement m110 = new StatisticalMeasurement(null,
264: g1, "110");
265: StatisticalMeasurement m111 = new StatisticalMeasurement(null,
266: g1, "111");
267:
268: assertEquals("000", 0, m000.getNbDataPoints());
269: assertEquals("001", 4, m001.getNbDataPoints());
270: assertEquals("010", 2, m010.getNbDataPoints());
271: assertEquals("011", 2, m011.getNbDataPoints());
272: assertEquals("100", 0, m100.getNbDataPoints());
273: assertEquals("101", 4, m101.getNbDataPoints());
274: assertEquals("110", 2, m110.getNbDataPoints());
275: assertEquals("111", 2, m111.getNbDataPoints());
276: }
277:
278: public void testClass() {
279: StatisticalMeasurement m000 = new StatisticalMeasurement(null,
280: c1, "000");
281: StatisticalMeasurement m001 = new StatisticalMeasurement(null,
282: c1, "001");
283: StatisticalMeasurement m010 = new StatisticalMeasurement(null,
284: c1, "010");
285: StatisticalMeasurement m011 = new StatisticalMeasurement(null,
286: c1, "011");
287: StatisticalMeasurement m100 = new StatisticalMeasurement(null,
288: c1, "100");
289: StatisticalMeasurement m101 = new StatisticalMeasurement(null,
290: c1, "101");
291: StatisticalMeasurement m110 = new StatisticalMeasurement(null,
292: c1, "110");
293: StatisticalMeasurement m111 = new StatisticalMeasurement(null,
294: c1, "111");
295:
296: assertEquals("000", 0, m000.getNbDataPoints());
297: assertEquals("001", 2, m001.getNbDataPoints());
298: assertEquals("010", 0, m010.getNbDataPoints());
299: assertEquals("011", 2, m011.getNbDataPoints());
300: assertEquals("100", 0, m100.getNbDataPoints());
301: assertEquals("101", 2, m101.getNbDataPoints());
302: assertEquals("110", 0, m110.getNbDataPoints());
303: assertEquals("111", 2, m111.getNbDataPoints());
304: }
305:
306: public void testMethod() {
307: StatisticalMeasurement m000 = new StatisticalMeasurement(null,
308: m1, "000");
309: StatisticalMeasurement m001 = new StatisticalMeasurement(null,
310: m1, "001");
311: StatisticalMeasurement m010 = new StatisticalMeasurement(null,
312: m1, "010");
313: StatisticalMeasurement m011 = new StatisticalMeasurement(null,
314: m1, "011");
315: StatisticalMeasurement m100 = new StatisticalMeasurement(null,
316: m1, "100");
317: StatisticalMeasurement m101 = new StatisticalMeasurement(null,
318: m1, "101");
319: StatisticalMeasurement m110 = new StatisticalMeasurement(null,
320: m1, "110");
321: StatisticalMeasurement m111 = new StatisticalMeasurement(null,
322: m1, "111");
323:
324: assertEquals("000", 0, m000.getNbDataPoints());
325: assertEquals("001", 0, m001.getNbDataPoints());
326: assertEquals("010", 0, m010.getNbDataPoints());
327: assertEquals("011", 0, m011.getNbDataPoints());
328: assertEquals("100", 0, m100.getNbDataPoints());
329: assertEquals("101", 0, m101.getNbDataPoints());
330: assertEquals("110", 0, m110.getNbDataPoints());
331: assertEquals("111", 0, m111.getNbDataPoints());
332: }
333:
334: public void testIrregular() {
335: Metrics m11 = new Metrics("m11");
336: Metrics m12 = new Metrics("m12");
337: Metrics m21 = new Metrics("m21");
338: Metrics m22 = new Metrics("m22");
339:
340: Metrics c1 = new Metrics("c1");
341: Metrics c2 = new Metrics("c2");
342:
343: c1.addSubMetrics(m11);
344: c1.addSubMetrics(m12);
345: c2.addSubMetrics(m21);
346: c2.addSubMetrics(m22);
347:
348: Metrics g = new Metrics("g");
349:
350: g.addSubMetrics(c1);
351: g.addSubMetrics(c2);
352:
353: m11.track("bar", new CounterMeasurement(null, null, null));
354: m12.track("bar", new CounterMeasurement(null, null, null));
355: m21.track("bar", new CounterMeasurement(null, null, null));
356: m22.track("bar", new CounterMeasurement(null, null, null));
357:
358: c1.track("bar", new CounterMeasurement(null, null, null));
359:
360: StatisticalMeasurement sm = new StatisticalMeasurement(null, g,
361: "bar");
362: assertEquals(3, sm.getNbDataPoints());
363: }
364: }
|