endtoend-test-psl/tests/Psl/Math/ToBaseTest.php

67 lines
1.4 KiB
PHP
Raw Normal View History

2019-12-24 01:52:07 +01:00
<?php
declare(strict_types=1);
namespace Psl\Tests\Math;
use PHPUnit\Framework\TestCase;
2019-12-26 21:03:29 +01:00
use Psl\Exception;
use Psl\Math;
2019-12-24 01:52:07 +01:00
final class ToBaseTest extends TestCase
2019-12-24 01:52:07 +01:00
{
2019-12-26 21:03:29 +01:00
/**
* @dataProvider provideData
*/
public function testFromBase(string $expected, int $value, int $to_base): void
{
static::assertSame($expected, Math\to_base($value, $to_base));
2019-12-26 21:03:29 +01:00
}
public function provideData(): array
{
return [
[
'1010101111001',
5497,
2
],
[
'pphlmw9v',
2014587925987,
36
],
[
'zik0zj',
Math\INT32_MAX,
36
],
[
'f',
15,
16
]
];
}
public function testNegativeValueThrows(): void
{
$this->expectException(Exception\InvariantViolationException::class);
2020-07-09 00:28:29 +02:00
$this->expectExceptionMessage('Expected a non-negative number.');
2019-12-26 21:03:29 +01:00
Math\to_base(-5, 16);
}
public function testInvalidToBaseThrows(): void
{
$this->expectException(Exception\InvariantViolationException::class);
$this->expectExceptionMessage('Expected $to_base to be between 2 and 36, got 64');
Math\to_base(1, 64);
}
2019-12-24 01:52:07 +01:00
}