Skip to content

Commit

Permalink
Configurable max digits for random numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
BenMorel committed Aug 18, 2020
1 parent b16fe17 commit f442bfc
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions random-tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,28 @@

use Brick\Math\Internal\Calculator;

(new class {
(new class(100) {
private $gmp;
private $bcmath;
private $native;

public function __construct()
private $maxDigits;

public function __construct(int $maxDigits)
{
$this->gmp = new Calculator\GmpCalculator();
$this->bcmath = new Calculator\BcMathCalculator();
$this->native = new Calculator\NativeCalculator();

$this->maxDigits = $maxDigits;
}

public function __invoke() : void
{
for (;;) {
$a = self::generateRandomNumber();
$b = self::generateRandomNumber();
$c = self::generateRandomNumber();
$a = $this->generateRandomNumber();
$b = $this->generateRandomNumber();
$c = $this->generateRandomNumber();

$this->runTests($a, $b);
$this->runTests($b, $a);
Expand Down Expand Up @@ -159,9 +163,9 @@ private static function failure(string $c1, string $c2, string $test) : void
die;
}

private static function generateRandomNumber() : string
private function generateRandomNumber() : string
{
$length = random_int(1, 100);
$length = random_int(1, $this->maxDigits);

$number = '';

Expand Down

0 comments on commit f442bfc

Please sign in to comment.