Skip to content

Commit

Permalink
Fix full tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
paragonie-scott committed Jul 8, 2015
1 parent b424ddf commit f146da1
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 26 deletions.
56 changes: 56 additions & 0 deletions tests/full/DieHardTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php
class DieHardTest extends PHPUnit_Framework_TestCase
{
/**
* Birthday spacings: Choose random points on a large interval.
* The spacings between the points should be asymptotically exponentially
* distributed.
*/
public function testBirthday()
{
// Number of buckets to make
$num_buckets = 17;
$rand_min = 200000;
$rand_max = 600000;
$rand_step = 100000;

for ($nums_to_generate = $rand_min; $nums_to_generate < $rand_max; $nums_to_generate += $rand_step) {
$buckets = array_fill(0, $num_buckets, 0);

// The number of ints we expect per bucket +/- 2%;
$min = (int) ceil(0.97 * $nums_to_generate / $num_buckets);
$max = (int) floor(1.03 * $nums_to_generate / $num_buckets);

for ($i = 0; $i < $nums_to_generate; ++$i) {
$random = random_int(0, 999);
$bucket = $random % $num_buckets;
$buckets[$bucket]++;
}
for ($i = 0; $i < $num_buckets; ++$i) {

// Debugging code:

if ($buckets[$i] <= $min ) {
var_dump([
'bucket' => $i,
'value' => $buckets[$i],
'min' => $min,
'nums' => $nums_to_generate,
'reason' => 'below min'
]);
}
if ($buckets[$i] >= $max ) {
var_dump([
'bucket' => $i,
'value' => $buckets[$i],
'maax' => $max,
'nums' => $nums_to_generate,
'reason' => 'above max'
]);
}

$this->assertTrue($buckets[$i] < $max && $buckets[$i] > $min);
}
}
}
}
25 changes: 0 additions & 25 deletions tests/full/DieHardTests.php

This file was deleted.

2 changes: 1 addition & 1 deletion tests/full/StatTests.php → tests/full/StatTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

class StatTests extends PHPUnit_Framework_TestCase
class StatTest extends PHPUnit_Framework_TestCase
{
/**
* All possible values should be > 30% but less than 170%
Expand Down

0 comments on commit f146da1

Please sign in to comment.