Skip to content

Abstract simulation testing strategy.  #10

@gburtini

Description

@gburtini

When testing if an implementation probabilistically fits the expected distribution, we should be able to abstract simulatory code something like this to test probability cutoff and means. We could also compute expected variances and such within a bound.

$scale = 50000;
$cutoff = 10.0;
$counter = 0;
$draws = new SplFixedArray($scale);
for($i = 0; $i < $scale; $i++) {
   $x = $d->rand();
   $draws[$i] = $x;
   if ($x > $cutoff) $counter = $counter + 1;
}
$number = array_sum((array) $draws) / count($draws);
$this->assertEquals( $number,7.0, "Attempting to draw from P(7.0) {$scale} times gives us a value too far from the expected mean. This could be just random chance.", 0.01);

$p = $counter / $scale;
$this->assertEquals(1-$d->cdf($cutoff), $p, "Attempting to draw from P(7.0) {$scale} times gives the wrong number of values greater than {$cutoff}. This could be just random chance.", 0.01);

A single implementation of this sort of testing that can be reused in the tests will have a lot of value in this project. Speed ($scale) is a concern though.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions