KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jeantessier > metrics > TestStatisticalMeasurementWithDispose


1 /*
2  * Copyright (c) 2001-2005, Jean Tessier
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Jean Tessier nor the names of his contributors
17  * may be used to endorse or promote products derived from this software
18  * without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */

32
33 package com.jeantessier.metrics;
34
35 import junit.framework.*;
36
37 import org.apache.log4j.*;
38
39 public class TestStatisticalMeasurementWithDispose 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
47     private Metrics c1;
48     private Metrics c2;
49
50     private Metrics g;
51
52     private MeasurementDescriptor descriptor;
53     
54     protected void setUp() throws Exception JavaDoc {
55         Logger.getLogger(getClass()).info("Starting test: " + getName());
56
57         descriptor = new MeasurementDescriptor();
58         descriptor.setShortName("bar");
59         
60         m1 = new Metrics("m1");
61         m2 = new Metrics("m2");
62         m3 = new Metrics("m3");
63         m4 = new Metrics("m4");
64         m5 = new Metrics("m5");
65         m6 = new Metrics("m6");
66
67         m1.track("bar", new CounterMeasurement(null, null, null));
68         m2.track("bar", new CounterMeasurement(null, null, null));
69         m3.track("bar", new CounterMeasurement(null, null, null));
70         m4.track("bar", new CounterMeasurement(null, null, null));
71         m5.track("bar", new CounterMeasurement(null, null, null));
72         m6.track("bar", new CounterMeasurement(null, null, null));
73     
74         m1.addToMeasurement("bar", 1);
75         m2.addToMeasurement("bar", 2);
76         m3.addToMeasurement("bar", 3);
77         m4.addToMeasurement("bar", 4);
78         m5.addToMeasurement("bar", 5);
79         m6.addToMeasurement("bar", 6);
80
81         c1 = new Metrics("c1");
82         c2 = new Metrics("c2");
83
84         c1.track("bar", new StatisticalMeasurement(descriptor, c1, "bar"));
85         c2.track("bar", new StatisticalMeasurement(descriptor, c2, "bar"));
86         
87         c1.addSubMetrics(m1);
88         c1.addSubMetrics(m2);
89         c2.addSubMetrics(m3);
90         c2.addSubMetrics(m4);
91         c2.addSubMetrics(m5);
92         c2.addSubMetrics(m6);
93
94         g = new Metrics("g");
95
96         g.addSubMetrics(c1);
97         g.addSubMetrics(c2);
98     }
99
100     protected void tearDown() throws Exception JavaDoc {
101         Logger.getLogger(getClass()).info("End of " + getName());
102     }
103
104     public void testDefault() {
105         StatisticalMeasurement sm = new StatisticalMeasurement(descriptor, g, "bar");
106
107         assertEquals("size " + sm, 6, sm.getNbDataPoints());
108         assertEquals("Minimum " + sm, 1.0, sm.getMinimum(), 0.01);
109         assertEquals("Median " + sm, 4.0, sm.getMedian(), 0.01);
110         assertEquals("Average " + sm, 3.5, sm.getAverage(), 0.01);
111         assertEquals("Standard Deviation " + sm, 1.71, sm.getStandardDeviation(), 0.01);
112         assertEquals("Maximum " + sm, 6.0, sm.getMaximum(), 0.01);
113         assertEquals("Sum " + sm, 21.0, sm.getSum(), 0.01);
114     }
115
116     public void testIgnore() {
117         StatisticalMeasurement sm = new StatisticalMeasurement(descriptor, g, "bar DISPOSE_IGNORE");
118
119         assertEquals("size " + sm, 6, sm.getNbDataPoints());
120         assertEquals("Minimum " + sm, 1.0, sm.getMinimum(), 0.01);
121         assertEquals("Median " + sm, 4.0, sm.getMedian(), 0.01);
122         assertEquals("Average " + sm, 3.5, sm.getAverage(), 0.01);
123         assertEquals("Standard Deviation " + sm, 1.71, sm.getStandardDeviation(), 0.01);
124         assertEquals("Maximum " + sm, 6.0, sm.getMaximum(), 0.01);
125         assertEquals("Sum " + sm, 21.0, sm.getSum(), 0.01);
126     }
127
128     public void testMinimum() {
129         StatisticalMeasurement sm = new StatisticalMeasurement(descriptor, g, "bar DISPOSE_MINIMUM");
130
131         assertEquals("size " + sm, 2, sm.getNbDataPoints());
132         assertEquals("Minimum " + sm, 1.0, sm.getMinimum(), 0.01);
133         assertEquals("Median " + sm, 3.0, sm.getMedian(), 0.01);
134         assertEquals("Average " + sm, 2.0, sm.getAverage(), 0.01);
135         assertEquals("Standard Deviation " + sm, 1.0, sm.getStandardDeviation(), 0.01);
136         assertEquals("Maximum " + sm, 3.0, sm.getMaximum(), 0.01);
137         assertEquals("Sum " + sm, 4.0, sm.getSum(), 0.01);
138     }
139
140     public void testMedian() {
141         StatisticalMeasurement sm = new StatisticalMeasurement(descriptor, g, "bar DISPOSE_MEDIAN");
142
143         assertEquals("size " + sm, 2, sm.getNbDataPoints());
144         assertEquals("Minimum " + sm, 2.0, sm.getMinimum(), 0.01);
145         assertEquals("Median " + sm, 5.0, sm.getMedian(), 0.01);
146         assertEquals("Average " + sm, 3.5, sm.getAverage(), 0.01);
147         assertEquals("Standard Deviation " + sm, 1.5, sm.getStandardDeviation(), 0.01);
148         assertEquals("Maximum " + sm, 5.0, sm.getMaximum(), 0.01);
149         assertEquals("Sum " + sm, 7.0, sm.getSum(), 0.01);
150     }
151
152     public void testAverage() {
153         StatisticalMeasurement sm = new StatisticalMeasurement(descriptor, g, "bar DISPOSE_AVERAGE");
154
155         assertEquals("size " + sm, 2, sm.getNbDataPoints());
156         assertEquals("Minimum " + sm, 1.5, sm.getMinimum(), 0.01);
157         assertEquals("Median " + sm, 4.5, sm.getMedian(), 0.01);
158         assertEquals("Average " + sm, 3.0, sm.getAverage(), 0.01);
159         assertEquals("Standard Deviation " + sm, 1.5, sm.getStandardDeviation(), 0.01);
160         assertEquals("Maximum " + sm, 4.5, sm.getMaximum(), 0.01);
161         assertEquals("Sum " + sm, 6.0, sm.getSum(), 0.01);
162     }
163
164     public void testStandardDeviation() {
165         StatisticalMeasurement sm = new StatisticalMeasurement(descriptor, g, "bar DISPOSE_STANDARD_DEVIATION");
166
167         assertEquals("size " + sm, 2, sm.getNbDataPoints());
168         assertEquals("Minimum " + sm, 0.5, sm.getMinimum(), 0.01);
169         assertEquals("Median " + sm, 1.12, sm.getMedian(), 0.01);
170         assertEquals("Average " + sm, 0.81, sm.getAverage(), 0.01);
171         assertEquals("Standard Deviation " + sm, 0.31, sm.getStandardDeviation(), 0.01);
172         assertEquals("Maximum " + sm, 1.12, sm.getMaximum(), 0.01);
173         assertEquals("Sum " + sm, 1.62, sm.getSum(), 0.01);
174     }
175
176     public void testMaximum() {
177         StatisticalMeasurement sm = new StatisticalMeasurement(descriptor, g, "bar DISPOSE_MAXIMUM");
178
179         assertEquals("size " + sm, 2, sm.getNbDataPoints());
180         assertEquals("Minimum " + sm, 2.0, sm.getMinimum(), 0.01);
181         assertEquals("Median " + sm, 6.0, sm.getMedian(), 0.01);
182         assertEquals("Average " + sm, 4.0, sm.getAverage(), 0.01);
183         assertEquals("Standard Deviation " + sm, 2.0, sm.getStandardDeviation(), 0.01);
184         assertEquals("Maximum " + sm, 6.0, sm.getMaximum(), 0.01);
185         assertEquals("Sum " + sm, 8.0, sm.getSum(), 0.01);
186     }
187
188     public void testSum() {
189         StatisticalMeasurement sm = new StatisticalMeasurement(descriptor, g, "bar DISPOSE_SUM");
190
191         assertEquals("size " + sm, 2, sm.getNbDataPoints());
192         assertEquals("Minimum " + sm, 3.0, sm.getMinimum(), 0.01);
193         assertEquals("Median " + sm, 18.0, sm.getMedian(), 0.01);
194         assertEquals("Average " + sm, 10.5, sm.getAverage(), 0.01);
195         assertEquals("Standard Deviation " + sm, 7.5, sm.getStandardDeviation(), 0.01);
196         assertEquals("Maximum " + sm, 18.0, sm.getMaximum(), 0.01);
197         assertEquals("Sum " + sm, 21.0, sm.getSum(), 0.01);
198     }
199
200     public void testNbDataPoints() {
201         StatisticalMeasurement sm = new StatisticalMeasurement(descriptor, g, "bar DISPOSE_NB_DATA_POINTS");
202
203         assertEquals("size " + sm, 2, sm.getNbDataPoints());
204         assertEquals("Minimum " + sm, 2.0, sm.getMinimum(), 0.01);
205         assertEquals("Median " + sm, 4.0, sm.getMedian(), 0.01);
206         assertEquals("Average " + sm, 3.0, sm.getAverage(), 0.01);
207         assertEquals("Standard Deviation " + sm, 1.0, sm.getStandardDeviation(), 0.01);
208         assertEquals("Maximum " + sm, 4.0, sm.getMaximum(), 0.01);
209         assertEquals("Sum " + sm, 6.0, sm.getSum(), 0.01);
210     }
211 }
212
Popular Tags