endtoend-test-psl/tests/Psl/PseudoRandom/IntTest.php

49 lines
1.2 KiB
PHP
Raw Normal View History

2019-12-24 01:52:07 +01:00
<?php
declare(strict_types=1);
2020-07-16 18:13:12 +02:00
namespace Psl\Tests\PseudoRandom;
2019-12-24 01:52:07 +01:00
use PHPUnit\Framework\TestCase;
2019-12-25 19:11:35 +01:00
use Psl\Exception;
use Psl\Math;
2020-07-16 18:13:12 +02:00
use Psl\PseudoRandom;
2019-12-24 01:52:07 +01:00
class IntTest extends TestCase
{
2019-12-25 19:11:35 +01:00
public function testInt(): void
{
2020-07-16 18:13:12 +02:00
$random = PseudoRandom\int();
2019-12-25 19:11:35 +01:00
self::assertIsInt($random);
self::assertGreaterThanOrEqual(Math\INT64_MIN, $random);
self::assertLessThanOrEqual(Math\INT64_MAX, $random);
}
public function testIntWithASpecificMin(): void
{
2020-07-16 18:13:12 +02:00
$random = PseudoRandom\int(10);
2019-12-25 19:11:35 +01:00
self::assertIsInt($random);
self::assertGreaterThanOrEqual(10, $random);
self::assertLessThanOrEqual(Math\INT64_MAX, $random);
}
public function testIntWithASpecificRange(): void
{
2020-07-16 18:13:12 +02:00
$random = PseudoRandom\int(20, 1200);
2019-12-25 19:11:35 +01:00
self::assertIsInt($random);
self::assertGreaterThanOrEqual(20, $random);
self::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).');
2020-07-16 18:13:12 +02:00
PseudoRandom\int(20, 5);
2019-12-25 19:11:35 +01:00
}
2019-12-24 01:52:07 +01:00
}