-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b424ddf
commit f146da1
Showing
3 changed files
with
57 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters