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