forked from phoedos/pmd
Added test to check for Metrics on the Report.
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@816 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
package test.net.sourceforge.pmd.stat;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Random;
|
||||
@ -60,7 +61,7 @@ public class StatisticalRuleTest
|
||||
|
||||
|
||||
public static final double MEAN = 499.5;
|
||||
public static final double SIGMA = 288.8194;
|
||||
public static final double SIGMA = 288.6750;
|
||||
public static final int NUM_TESTS = 32;
|
||||
|
||||
public StatisticalRuleTest(String name)
|
||||
@ -81,6 +82,30 @@ public class StatisticalRuleTest
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This test verifies that the Stat rule creates a Metric,
|
||||
* with the proper values.
|
||||
*/
|
||||
public void testMetrics() throws Throwable
|
||||
{
|
||||
Report report = makeReport( IUT );
|
||||
Iterator metrics = report.metrics();
|
||||
|
||||
assertTrue( metrics.hasNext());
|
||||
Object o = metrics.next();
|
||||
|
||||
assertTrue( o instanceof Metric);
|
||||
Metric m = (Metric) o;
|
||||
|
||||
assertEquals("test.net.sourceforge.pmd.stat.MockStatisticalRule",
|
||||
m.getMetricName());
|
||||
|
||||
assertEquals( 0.0, m.getLowValue(), 0.05 );
|
||||
assertEquals( 999.0, m.getHighValue(), 0.05 );
|
||||
assertEquals( MEAN, m.getAverage(), 0.05 );
|
||||
assertEquals( SIGMA, m.getStandardDeviation(), 0.05 );
|
||||
}
|
||||
|
||||
/**
|
||||
* This returns a Random value for Sigma which will
|
||||
* return some values.
|
||||
|
@ -24,11 +24,14 @@ public abstract class StatisticalRule extends AbstractRule {
|
||||
|
||||
private int count = 0;
|
||||
private double total = 0.0;
|
||||
|
||||
private double totalSquared = 0.0;
|
||||
|
||||
public void addDataPoint( DataPoint point )
|
||||
{
|
||||
count++;
|
||||
total += point.getScore();
|
||||
totalSquared += point.getScore() * point.getScore();
|
||||
|
||||
dataPoints.add( point );
|
||||
}
|
||||
|
||||
@ -61,8 +64,8 @@ public abstract class StatisticalRule extends AbstractRule {
|
||||
|
||||
makeViolations(ctx, newPoints);
|
||||
|
||||
double low = ((DataPoint) newPoints.first()).getScore();
|
||||
double high = ((DataPoint) newPoints.last()).getScore();
|
||||
double low = ((DataPoint) dataPoints.first()).getScore();
|
||||
double high = ((DataPoint) dataPoints.last()).getScore();
|
||||
|
||||
ctx.getReport().addMetric( new Metric( this.getName(), low, high,
|
||||
getMean(), getStdDev()));
|
||||
@ -77,13 +80,8 @@ public abstract class StatisticalRule extends AbstractRule {
|
||||
|
||||
Iterator points = dataPoints.iterator();
|
||||
|
||||
while (points.hasNext()) {
|
||||
DataPoint point = (DataPoint) points.next();
|
||||
varTotal += ((point.getScore() - getMean()) *
|
||||
(point.getScore() - getMean()));
|
||||
}
|
||||
|
||||
double variance = varTotal / count;
|
||||
double variance = ((totalSquared / count) -
|
||||
(getMean() * getMean() ));
|
||||
return Math.sqrt( variance );
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user