KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > test > internal > performance > eval > RelativeBandChecker


1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.test.internal.performance.eval;
12
13 import org.eclipse.test.internal.performance.PerformanceTestPlugin;
14 import org.eclipse.test.internal.performance.data.Dim;
15
16 /**
17  * @since 3.1
18  */

19 public class RelativeBandChecker extends AssertChecker {
20
21     private final double fLowerBand;
22     private final double fUpperBand;
23
24     public RelativeBandChecker(Dim dimension, double lowerBand, double upperBand) {
25         super(dimension);
26         fLowerBand= lowerBand;
27         fUpperBand= upperBand;
28     }
29
30     public boolean test(StatisticsSession reference, StatisticsSession measured, StringBuffer JavaDoc message) {
31         Dim dimension= getDimension();
32         
33         if (!measured.contains(dimension)) {
34             PerformanceTestPlugin.logWarning("collected data provides no dimension '"+dimension.getName()+'\''); //$NON-NLS-1$ //$NON-NLS-2$
35
return true;
36         }
37         if (!reference.contains(dimension)) {
38             PerformanceTestPlugin.logWarning("reference data provides no dimension '"+dimension.getName()+'\''); //$NON-NLS-1$ //$NON-NLS-2$
39
return true;
40         }
41         
42         double actual= measured.getAverage(dimension);
43         double test= reference.getAverage(dimension);
44         
45         if (test < 0.001 && test > -0.001) {
46             // we don't fail for reference value of zero
47
PerformanceTestPlugin.logWarning("ref value for '"+dimension.getName()+"' is too small"); //$NON-NLS-1$ //$NON-NLS-2$
48
return true;
49         }
50         if (actual < 0) {
51             // we don't fail for negative values
52
PerformanceTestPlugin.logWarning("actual value for '"+dimension.getName()+"' is negative"); //$NON-NLS-1$ //$NON-NLS-2$
53
return true;
54         }
55         
56         if (actual > fUpperBand * test || actual < fLowerBand * test) {
57             message.append('\n' + dimension.getName() + ": " + dimension.getDisplayValue(actual) + " is not within [" + Math.round(fLowerBand * 100)+ "%, " + Math.round(fUpperBand * 100) + "%] of " + dimension.getDisplayValue(test)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
58
return false;
59         }
60         return true;
61     }
62 }
63
Popular Tags