-
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: Add SA tests for
Random
and Shuffle
operations.
- Loading branch information
Showing
2 changed files
with
134 additions
and
0 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,67 @@ | ||
<?php | ||
|
||
/** | ||
* For the full copyright and license information, please view | ||
* the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
include __DIR__ . '/../../vendor/autoload.php'; | ||
|
||
use loophp\collection\Collection; | ||
use loophp\collection\Contract\Collection as CollectionInterface; | ||
|
||
/** | ||
* @param CollectionInterface<int, int> $collection | ||
*/ | ||
function random_checkIntList(CollectionInterface $collection): void | ||
{ | ||
} | ||
/** | ||
* @param CollectionInterface<int, string> $collection | ||
*/ | ||
function random_checkStringList(CollectionInterface $collection): void | ||
{ | ||
} | ||
/** | ||
* @param CollectionInterface<int, bool> $collection | ||
*/ | ||
function random_checkBoolList(CollectionInterface $collection): void | ||
{ | ||
} | ||
/** | ||
* @param CollectionInterface<string, string> $collection | ||
*/ | ||
function random_checkStringMap(CollectionInterface $collection): void | ||
{ | ||
} | ||
|
||
$intGenerator = static function (): Generator { | ||
while (true) { | ||
yield mt_rand(); | ||
} | ||
}; | ||
|
||
$boolGenerator = static function (): Generator { | ||
while (true) { | ||
yield (0 === mt_rand() % 2) ? true : false; | ||
} | ||
}; | ||
|
||
$stringGenerator = static function (): Generator { | ||
while (true) { | ||
yield chr(random_int(0, 255)); | ||
} | ||
}; | ||
|
||
$stringStringGenerator = static function (): Generator { | ||
while (true) { | ||
yield chr(random_int(0, 255)) => chr(random_int(0, 255)); | ||
} | ||
}; | ||
|
||
random_checkIntList(Collection::fromIterable($intGenerator())->random()); | ||
random_checkStringList(Collection::fromIterable($stringGenerator())->random()); | ||
random_checkBoolList(Collection::fromIterable($boolGenerator())->random()); | ||
random_checkStringMap(Collection::fromIterable($stringStringGenerator())->random()); |
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,67 @@ | ||
<?php | ||
|
||
/** | ||
* For the full copyright and license information, please view | ||
* the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
include __DIR__ . '/../../vendor/autoload.php'; | ||
|
||
use loophp\collection\Collection; | ||
use loophp\collection\Contract\Collection as CollectionInterface; | ||
|
||
/** | ||
* @param CollectionInterface<int, int> $collection | ||
*/ | ||
function shuffle_checkIntList(CollectionInterface $collection): void | ||
{ | ||
} | ||
/** | ||
* @param CollectionInterface<int, string> $collection | ||
*/ | ||
function shuffle_checkStringList(CollectionInterface $collection): void | ||
{ | ||
} | ||
/** | ||
* @param CollectionInterface<int, bool> $collection | ||
*/ | ||
function shuffle_checkBoolList(CollectionInterface $collection): void | ||
{ | ||
} | ||
/** | ||
* @param CollectionInterface<string, string> $collection | ||
*/ | ||
function shuffle_checkStringMap(CollectionInterface $collection): void | ||
{ | ||
} | ||
|
||
$intGenerator = static function (): Generator { | ||
while (true) { | ||
yield mt_rand(); | ||
} | ||
}; | ||
|
||
$boolGenerator = static function (): Generator { | ||
while (true) { | ||
yield (0 === mt_rand() % 2) ? true : false; | ||
} | ||
}; | ||
|
||
$stringGenerator = static function (): Generator { | ||
while (true) { | ||
yield chr(random_int(0, 255)); | ||
} | ||
}; | ||
|
||
$stringStringGenerator = static function (): Generator { | ||
while (true) { | ||
yield chr(random_int(0, 255)) => chr(random_int(0, 255)); | ||
} | ||
}; | ||
|
||
shuffle_checkIntList(Collection::fromIterable($intGenerator())->shuffle()); | ||
shuffle_checkStringList(Collection::fromIterable($stringGenerator())->shuffle()); | ||
shuffle_checkBoolList(Collection::fromIterable($boolGenerator())->shuffle()); | ||
shuffle_checkStringMap(Collection::fromIterable($stringStringGenerator())->shuffle()); |