From a41fadf978b75b6d5845cd7f42f56d6bacf1a10c Mon Sep 17 00:00:00 2001 From: David Dixon-Peugh Date: Wed, 4 Sep 2002 17:21:43 +0000 Subject: [PATCH] Fixed the problems. Should work now. git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@838 51baf565-9d33-0410-a72c-fc3788e3496d --- .../pmd/stat/StatisticalRuleTest.java | 19 ++++++++++++++++--- .../sourceforge/pmd/stat/StatisticalRule.java | 2 +- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/pmd/regress/test/net/sourceforge/pmd/stat/StatisticalRuleTest.java b/pmd/regress/test/net/sourceforge/pmd/stat/StatisticalRuleTest.java index 40e4cc4566..d65b114a9f 100644 --- a/pmd/regress/test/net/sourceforge/pmd/stat/StatisticalRuleTest.java +++ b/pmd/regress/test/net/sourceforge/pmd/stat/StatisticalRuleTest.java @@ -62,7 +62,9 @@ public class StatisticalRuleTest public static final double MEAN = 499.5; public static final double SIGMA = 288.6750; - public static final int NUM_TESTS = 32; + public static final int NUM_TESTS = 512; + + public static final double DELTA = 0.005; public StatisticalRuleTest(String name) { @@ -155,12 +157,21 @@ public class StatisticalRuleTest /** * This returns the expected number of reports. + * + * If the Minimum comes in at 521.569 then we expect + * 522, 523, ... 999 will pass. */ public int expectedMinimum(double minimum) { - int RC = 999 - ((int) Math.round(minimum - 0.5) + 1); - if (RC >= 0) return RC; else return 0; + Double d = new Double( minimum ); + return 999 - d.intValue(); } + public void testExpectedMinimum() { + for (int i = 0; i < 999; i++) { + assertEquals("Integer Min", 999 - i, expectedMinimum( i * 1.0 )); + assertEquals("Double Min", 999 - i, expectedMinimum( (i * 1.0) + 0.5 )); + } + } /** * This returns a random value for Top Score. */ @@ -173,6 +184,8 @@ public class StatisticalRuleTest * which will return more than the minimum provided. */ public int randomTopScore(double target) { + if (target < 0) return 0; + return random.nextInt( (new Double(target)).intValue() ); } diff --git a/pmd/src/net/sourceforge/pmd/stat/StatisticalRule.java b/pmd/src/net/sourceforge/pmd/stat/StatisticalRule.java index caae18c91a..771d538ce5 100644 --- a/pmd/src/net/sourceforge/pmd/stat/StatisticalRule.java +++ b/pmd/src/net/sourceforge/pmd/stat/StatisticalRule.java @@ -96,7 +96,7 @@ public abstract class StatisticalRule extends AbstractRule { while (points.hasNext()) { DataPoint point = (DataPoint) points.next(); - if (point.getScore() >= (minValue - DELTA)) { + if (point.getScore() > (minValue - DELTA)) { RC.add(point); } }