net.sourceforge.pmd.stat

## Class StatisticalRuleTest

- java.lang.Object
- - net.sourceforge.pmd.stat.StatisticalRuleTest

    public class StatisticalRuleTest
    extends Object

This class tests the Statistical Rules in PMD.

The idea is, that we fill up 999 datapoints into the Stat Rule, and then throw random parameters at it.

The three parameters which are checked are: sigma - # Sigmas over the mean. topscore - Only the top 5 or so items. minimum - Only things of score 10 or better

When more than one parameter is lumped together, then we expect the one which would return the fewest to determine what gets sent back.

So, we throw each collection of parameters, where each one is a different order into the system. We check the results off of what the smallest value should be.

If you are going to work with StatisticalRule any, please bump the "NUM_TESTS" number up to something like 128. That way you are more likely to identify problems. It is set low now to make building and running tests easier (when we aren't touching the file.)

Note also, that when verifying the Sigma, I wasn't quite able to determine how many results it would return (it would vary from -2 to 2 of what I expected.) That is what the delta parameter on the verify method takes. If you can figure it out exactly, (without stealing code from the StatRule) then feel free to change it and tighten the deltas.

### Field Summary

Fields
`static double` `DELTA`
`static double` `MAX_MINIMUM`
`static double` `MAX_SIGMA`
`static double` `MEAN`
`static int` `MIN_TOPSCORE`
`static double` `NO_MINIMUM`
`static double` `NO_SIGMA`
`static int` `NO_TOPSCORE`
`static int` `NUM_TESTS`
`static double` `SIGMA`

### Constructor Summary

Constructors
Constructor and Description
`StatisticalRuleTest()`

### Method Summary

Methods
`int` `expectedMinimum(double minimum)` This returns the expected number of reports.
`int` `expectedSigma(double sigma)` This returns the expected number of results when the Sigma rating is the smallest.
`int` `expectedTopScore(int target)` This will return the expected number of results with the given Top Score.
`Report` `makeReport(Rule IUT)`
`double` `randomMinimum()` This generates a random minimum value for testing.
`double` `randomMinimum(int minimum)` This generates a random minimum value for which fewer results would be returned.
`double` `randomSigma()` This returns a Random value for Sigma which will return some values.
`double` `randomSigma(int minimum)` This returns a Random value for Sigma which value is greater than the parameter.
`int` `randomTopScore()` This returns a random value for Top Score.
`int` `randomTopScore(double target)` This will return a random value for the Top Score which will return more than the minimum provided.
`void` `setUp()`
`static junit.framework.Test` `suite()`
`void` `testExpectedMinimum()`
`void` `testM()`
`void` `testM1()`
`void` `testM2()`
`void` `testM3()`
`void` `testM4()`
`void` `testM5()`
`void` `testMetrics()` This test verifies that the Stat rule creates a Metric, with the proper values.
`void` `testMS()`
`void` `testMS1()`
`void` `testMS2()`
`void` `testMS3()`
`void` `testMS4()`
`void` `testMS5()`
`void` `testMT()`
`void` `testMT1()`
`void` `testMT2()`
`void` `testMT3()`
`void` `testMT4()`
`void` `testMT5()`
`void` `testS()`
`void` `testS1()`
`void` `testS2()`
`void` `testS3()`
`void` `testS4()`
`void` `testS5()`
`void` `testSingleDatapoint()`
`void` `testSM()`
`void` `testSM1()`
`void` `testSM2()`
`void` `testSM3()`
`void` `testSM4()`
`void` `testSM5()`
`void` `testSMT()`
`void` `testSMT1()`
`void` `testSMT2()`
`void` `testSMT3()`
`void` `testSMT4()`
`void` `testSMT5()`
`void` `testST()`
`void` `testST1()`
`void` `testST2()`
`void` `testST3()`
`void` `testST4()`
`void` `testST5()`
`void` `testSTM()`
`void` `testSTM1()`
`void` `testSTM2()`
`void` `testSTM3()`
`void` `testSTM4()`
`void` `testSTM5()`
`void` `testT()`
`void` `testT1()`
`void` `testT2()`
`void` `testT3()`
`void` `testT4()`
`void` `testT5()`
`void` `testTM()`
`void` `testTM1()`
`void` `testTM2()`
`void` `testTM3()`
`void` `testTM4()`
`void` `testTM5()`
`void` `testTMS()`
`void` `testTMS1()`
`void` `testTMS2()`
`void` `testTMS3()`
`void` `testTMS4()`
`void` `testTMS5()`
`void` `testTS()`
`void` `testTS1()`
`void` `testTS2()`
`void` `testTS3()`
`void` `testTS4()`
`void` `testTS5()`
`void` `testTSM()`
`void` `testTSM1()`
`void` `testTSM2()`
`void` `testTSM3()`
`void` `testTSM4()`
`void` `testTSM5()`
`void` `verifyResults(double sigma, double minimum, int topScore, int expected, int delta)` Verifies what happens when you pass these parameters into the thing.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### MAX_MINIMUM

    public static final double MAX_MINIMUM

See Also:
  Constant Field Values

#### NO_MINIMUM

    public static final double NO_MINIMUM

See Also:
  Constant Field Values

#### MAX_SIGMA

    public static final double MAX_SIGMA

See Also:
  Constant Field Values

#### NO_SIGMA

    public static final double NO_SIGMA

See Also:
  Constant Field Values

#### MIN_TOPSCORE

    public static final int MIN_TOPSCORE

See Also:
  Constant Field Values

#### NO_TOPSCORE

    public static final int NO_TOPSCORE

See Also:
  Constant Field Values

#### MEAN

    public static final double MEAN

See Also:
  Constant Field Values

#### SIGMA

    public static final double SIGMA

See Also:
  Constant Field Values

#### NUM_TESTS

    public static final int NUM_TESTS

See Also:
  Constant Field Values

#### DELTA

    public static final double DELTA

See Also:
  Constant Field Values

### Constructor Detail

#### StatisticalRuleTest

    public StatisticalRuleTest()

### Method Detail

#### setUp

    public void setUp()

#### testMetrics

    public void testMetrics()
                     throws Throwable

This test verifies that the Stat rule creates a Metric, with the proper values.

Throws:
  `Throwable`

#### randomSigma

    public double randomSigma()

This returns a Random value for Sigma which will return some values.

#### randomSigma

    public double randomSigma(int minimum)

This returns a Random value for Sigma which value is greater than the parameter.

#### expectedSigma

    public int expectedSigma(double sigma)

This returns the expected number of results when the Sigma rating is the smallest.

#### randomMinimum

    public double randomMinimum()

This generates a random minimum value for testing.

#### randomMinimum

    public double randomMinimum(int minimum)

This generates a random minimum value for which fewer results would be returned.

#### expectedMinimum

    public int expectedMinimum(double minimum)

This returns the expected number of reports.

If the Minimum comes in at 521.569 then we expect 522, 523, ... 999 will pass.

#### testExpectedMinimum

    public void testExpectedMinimum()

#### randomTopScore

    public int randomTopScore()

This returns a random value for Top Score.

#### randomTopScore

    public int randomTopScore(double target)

This will return a random value for the Top Score which will return more than the minimum provided.

#### expectedTopScore

    public int expectedTopScore(int target)

This will return the expected number of results with the given Top Score.

#### testSingleDatapoint

    public void testSingleDatapoint()

#### testS

    public void testS()
               throws Throwable

Throws:
  `Throwable`

#### testS1

    public void testS1()
                throws Throwable

Throws:
  `Throwable`

#### testS2

    public void testS2()
                throws Throwable

Throws:
  `Throwable`

#### testS3

    public void testS3()
                throws Throwable

Throws:
  `Throwable`

#### testS4

    public void testS4()
                throws Throwable

Throws:
  `Throwable`

#### testS5

    public void testS5()
                throws Throwable

Throws:
  `Throwable`

#### testT

    public void testT()
               throws Throwable

Throws:
  `Throwable`

#### testT1

    public void testT1()
                throws Throwable

Throws:
  `Throwable`

#### testT2

    public void testT2()
                throws Throwable

Throws:
  `Throwable`

#### testT3

    public void testT3()
                throws Throwable

Throws:
  `Throwable`

#### testT4

    public void testT4()
                throws Throwable

Throws:
  `Throwable`

#### testT5

    public void testT5()
                throws Throwable

Throws:
  `Throwable`

#### testM

    public void testM()
               throws Throwable

Throws:
  `Throwable`

#### testM1

    public void testM1()
                throws Throwable

Throws:
  `Throwable`

#### testM2

    public void testM2()
                throws Throwable

Throws:
  `Throwable`

#### testM3

    public void testM3()
                throws Throwable

Throws:
  `Throwable`

#### testM4

    public void testM4()
                throws Throwable

Throws:
  `Throwable`

#### testM5

    public void testM5()
                throws Throwable

Throws:
  `Throwable`

#### testST

    public void testST()
                throws Throwable

Throws:
  `Throwable`

#### testST1

    public void testST1()
                 throws Throwable

Throws:
  `Throwable`

#### testST2

    public void testST2()
                 throws Throwable

Throws:
  `Throwable`

#### testST3

    public void testST3()
                 throws Throwable

Throws:
  `Throwable`

#### testST4

    public void testST4()
                 throws Throwable

Throws:
  `Throwable`

#### testST5

    public void testST5()
                 throws Throwable

Throws:
  `Throwable`

#### testTS

    public void testTS()
                throws Throwable

Throws:
  `Throwable`

#### testTS1

    public void testTS1()
                 throws Throwable

Throws:
  `Throwable`

#### testTS2

    public void testTS2()
                 throws Throwable

Throws:
  `Throwable`

#### testTS3

    public void testTS3()
                 throws Throwable

Throws:
  `Throwable`

#### testTS4

    public void testTS4()
                 throws Throwable

Throws:
  `Throwable`

#### testTS5

    public void testTS5()
                 throws Throwable

Throws:
  `Throwable`

#### testSM

    public void testSM()
                throws Throwable

Throws:
  `Throwable`

#### testSM1

    public void testSM1()
                 throws Throwable

Throws:
  `Throwable`

#### testSM2

    public void testSM2()
                 throws Throwable

Throws:
  `Throwable`

#### testSM3

    public void testSM3()
                 throws Throwable

Throws:
  `Throwable`

#### testSM4

    public void testSM4()
                 throws Throwable

Throws:
  `Throwable`

#### testSM5

    public void testSM5()
                 throws Throwable

Throws:
  `Throwable`

#### testMS

    public void testMS()
                throws Throwable

Throws:
  `Throwable`

#### testMS1

    public void testMS1()
                 throws Throwable

Throws:
  `Throwable`

#### testMS2

    public void testMS2()
                 throws Throwable

Throws:
  `Throwable`

#### testMS3

    public void testMS3()
                 throws Throwable

Throws:
  `Throwable`

#### testMS4

    public void testMS4()
                 throws Throwable

Throws:
  `Throwable`

#### testMS5

    public void testMS5()
                 throws Throwable

Throws:
  `Throwable`

#### testTM

    public void testTM()
                throws Throwable

Throws:
  `Throwable`

#### testTM1

    public void testTM1()
                 throws Throwable

Throws:
  `Throwable`

#### testTM2

    public void testTM2()
                 throws Throwable

Throws:
  `Throwable`

#### testTM3

    public void testTM3()
                 throws Throwable

Throws:
  `Throwable`

#### testTM4

    public void testTM4()
                 throws Throwable

Throws:
  `Throwable`

#### testTM5

    public void testTM5()
                 throws Throwable

Throws:
  `Throwable`

#### testMT

    public void testMT()
                throws Throwable

Throws:
  `Throwable`

#### testMT1

    public void testMT1()
                 throws Throwable

Throws:
  `Throwable`

#### testMT2

    public void testMT2()
                 throws Throwable

Throws:
  `Throwable`

#### testMT3

    public void testMT3()
                 throws Throwable

Throws:
  `Throwable`

#### testMT4

    public void testMT4()
                 throws Throwable

Throws:
  `Throwable`

#### testMT5

    public void testMT5()
                 throws Throwable

Throws:
  `Throwable`

#### testSTM

    public void testSTM()
                 throws Throwable

Throws:
  `Throwable`

#### testSTM1

    public void testSTM1()
                  throws Throwable

Throws:
  `Throwable`

#### testSTM2

    public void testSTM2()
                  throws Throwable

Throws:
  `Throwable`

#### testSTM3

    public void testSTM3()
                  throws Throwable

Throws:
  `Throwable`

#### testSTM4

    public void testSTM4()
                  throws Throwable

Throws:
  `Throwable`

#### testSTM5

    public void testSTM5()
                  throws Throwable

Throws:
  `Throwable`

#### testSMT

    public void testSMT()
                 throws Throwable

Throws:
  `Throwable`

#### testSMT1

    public void testSMT1()
                  throws Throwable

Throws:
  `Throwable`

#### testSMT2

    public void testSMT2()
                  throws Throwable

Throws:
  `Throwable`

#### testSMT3

    public void testSMT3()
                  throws Throwable

Throws:
  `Throwable`

#### testSMT4

    public void testSMT4()
                  throws Throwable

Throws:
  `Throwable`

#### testSMT5

    public void testSMT5()
                  throws Throwable

Throws:
  `Throwable`

#### testTSM

    public void testTSM()
                 throws Throwable

Throws:
  `Throwable`

#### testTSM1

    public void testTSM1()
                  throws Throwable

Throws:
  `Throwable`

#### testTSM2

    public void testTSM2()
                  throws Throwable

Throws:
  `Throwable`

#### testTSM3

    public void testTSM3()
                  throws Throwable

Throws:
  `Throwable`

#### testTSM4

    public void testTSM4()
                  throws Throwable

Throws:
  `Throwable`

#### testTSM5

    public void testTSM5()
                  throws Throwable

Throws:
  `Throwable`

#### testTMS

    public void testTMS()
                 throws Throwable

Throws:
  `Throwable`

#### testTMS1

    public void testTMS1()
                  throws Throwable

Throws:
  `Throwable`

#### testTMS2

    public void testTMS2()
                  throws Throwable

Throws:
  `Throwable`

#### testTMS3

    public void testTMS3()
                  throws Throwable

Throws:
  `Throwable`

#### testTMS4

    public void testTMS4()
                  throws Throwable

Throws:
  `Throwable`

#### testTMS5

    public void testTMS5()
                  throws Throwable

Throws:
  `Throwable`

#### verifyResults

    public void verifyResults(double sigma,
                     double minimum,
                     int topScore,
                     int expected,
                     int delta)

Verifies what happens when you pass these parameters into the thing. DELTA is the amount of error allowed. Usually DELTA is only used for Sigma, as we really can't calculate it exactly.

#### makeReport

    public Report makeReport(Rule IUT)

#### suite

    public static junit.framework.Test suite()