1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
|
--TEST--
Random: Randomizer: pickArrayKeys(): Basic functionality
--FILE--
<?php
use Random\Engine;
use Random\Engine\Mt19937;
use Random\Engine\PcgOneseq128XslRr64;
use Random\Engine\Secure;
use Random\Engine\Test\TestShaEngine;
use Random\Engine\Xoshiro256StarStar;
use Random\Randomizer;
require __DIR__ . "/../../engines.inc";
$engines = [];
$engines[] = new Mt19937(null, MT_RAND_MT19937);
$engines[] = new Mt19937(null, MT_RAND_PHP);
$engines[] = new PcgOneseq128XslRr64();
$engines[] = new Xoshiro256StarStar();
$engines[] = new Secure();
$engines[] = new TestShaEngine();
$iterations = getenv("SKIP_SLOW_TESTS") ? 10 : 100;
$array1 = []; // list
$array2 = []; // associative array with only strings
$array3 = []; // mixed key array
for ($i = 0; $i < 500; $i++) {
$string = sha1((string)$i);
$array1[] = $i;
$array2[$string] = $i;
$array3[$string] = $i;
$array3[$i] = $string;
}
foreach ($engines as $engine) {
echo $engine::class, PHP_EOL;
$randomizer = new Randomizer($engine);
for ($i = 1; $i < $iterations; $i++) {
$result = $randomizer->pickArrayKeys($array1, $i);
if (array_unique($result) !== $result) {
die("failure: duplicates returned at {$i} for array1");
}
if (array_diff($result, array_keys($array1)) !== []) {
die("failure: non-keys returned at {$i} for array1");
}
$result = $randomizer->pickArrayKeys($array2, $i);
if (array_unique($result) !== $result) {
die("failure: duplicates returned at {$i} for array2");
}
if (array_diff($result, array_keys($array2)) !== []) {
die("failure: non-keys returned at {$i} for array2");
}
$result = $randomizer->pickArrayKeys($array3, $i);
if (array_unique($result) !== $result) {
die("failure: duplicates returned at {$i} for array3");
}
if (array_diff($result, array_keys($array3)) !== []) {
die("failure: non-keys returned at {$i} for array3");
}
}
}
die('success');
?>
--EXPECTF--
Deprecated: Constant MT_RAND_PHP is deprecated in %s on line %d
Deprecated: The MT_RAND_PHP variant of Mt19937 is deprecated in %s on line %d
Random\Engine\Mt19937
Random\Engine\Mt19937
Random\Engine\PcgOneseq128XslRr64
Random\Engine\Xoshiro256StarStar
Random\Engine\Secure
Random\Engine\Test\TestShaEngine
success
|