mirror of
https://github.com/php/php-src.git
synced 2025-08-15 21:48:51 +02:00

Only covers constants declared via stub files, others will be handled separately in a later commit. Does not include the intl extension, since that had some errors relating to the cpp code; that extension will be updated separately.
57 lines
1.5 KiB
PHP
57 lines
1.5 KiB
PHP
--TEST--
|
|
Random: Randomizer: shuffleArray(): 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();
|
|
$length = getenv("SKIP_SLOW_TESTS") ? 1_000 : 5_000;
|
|
|
|
foreach ($engines as $engine) {
|
|
echo $engine::class, PHP_EOL;
|
|
|
|
$randomizer = new Randomizer($engine);
|
|
|
|
// This test is slow, test all numbers smaller than 50 and then in steps of 677 (which is prime).
|
|
for ($i = 1; $i < $length; $i += ($i < 50 ? 1 : 677)) {
|
|
$array = range(1, $i);
|
|
|
|
$result = $randomizer->shuffleArray($array);
|
|
|
|
sort($result);
|
|
|
|
if ($result !== $array) {
|
|
die("failure: not a permutation at {$i}");
|
|
}
|
|
}
|
|
}
|
|
|
|
die('success');
|
|
|
|
?>
|
|
--EXPECTF--
|
|
Deprecated: Constant MT_RAND_PHP is deprecated since 8.3, as it uses a biased non-standard variant of Mt19937 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
|