1 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 { 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 { 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 |