mirror of
https://github.com/danog/endtoend-test-psl.git
synced 2024-11-30 04:39:48 +01:00
49 lines
1.2 KiB
PHP
49 lines
1.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Psl\Tests\PseudoRandom;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
use Psl\Exception;
|
|
use Psl\Math;
|
|
use Psl\PseudoRandom;
|
|
|
|
final class IntTest extends TestCase
|
|
{
|
|
public function testInt(): void
|
|
{
|
|
$random = PseudoRandom\int();
|
|
|
|
static::assertIsInt($random);
|
|
static::assertGreaterThanOrEqual(Math\INT64_MIN, $random);
|
|
static::assertLessThanOrEqual(Math\INT64_MAX, $random);
|
|
}
|
|
|
|
public function testIntWithASpecificMin(): void
|
|
{
|
|
$random = PseudoRandom\int(10);
|
|
|
|
static::assertIsInt($random);
|
|
static::assertGreaterThanOrEqual(10, $random);
|
|
static::assertLessThanOrEqual(Math\INT64_MAX, $random);
|
|
}
|
|
|
|
public function testIntWithASpecificRange(): void
|
|
{
|
|
$random = PseudoRandom\int(20, 1200);
|
|
|
|
static::assertIsInt($random);
|
|
static::assertGreaterThanOrEqual(20, $random);
|
|
static::assertLessThanOrEqual(1200, $random);
|
|
}
|
|
|
|
public function testIntWithMinGreaterThanMax(): void
|
|
{
|
|
$this->expectException(Exception\InvariantViolationException::class);
|
|
$this->expectExceptionMessage('Expected $min (20) to be less than or equal to $max (5).');
|
|
|
|
PseudoRandom\int(20, 5);
|
|
}
|
|
}
|