1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
<?php
declare(strict_types=1);
namespace Brick\Math\Tests;
use Brick\Math\BigDecimal;
use Brick\Math\BigInteger;
use Brick\Math\BigRational;
use PHPUnit\Framework\TestCase;
/**
* Base class for math tests.
*/
abstract class AbstractTestCase extends TestCase
{
/**
* @param string $expected The expected value, as a string.
* @param BigInteger $actual The BigInteger instance to test.
*
* @return void
*/
final protected static function assertBigIntegerEquals(string $expected, BigInteger $actual) : void
{
self::assertSame($expected, (string) $actual);
}
/**
* @param string $expected The expected string representation.
* @param BigDecimal $actual The BigDecimal instance to test.
*
* @return void
*/
final protected static function assertBigDecimalEquals(string $expected, BigDecimal $actual) : void
{
self::assertSame($expected, (string) $actual);
}
/**
* @param string $expected The expected string representation.
* @param BigRational $actual The BigRational instance to test.
*
* @return void
*/
final protected static function assertBigRationalEquals(string $expected, BigRational $actual) : void
{
self::assertSame($expected, (string) $actual);
}
/**
* @param string $unscaledValue The expected unscaled value, as a string.
* @param int $scale The expected scale.
* @param BigDecimal $actual The BigDecimal instance to test.
*
* @return void
*/
final protected static function assertBigDecimalInternalValues(string $unscaledValue, int $scale, BigDecimal $actual) : void
{
self::assertSame($unscaledValue, (string) $actual->getUnscaledValue());
self::assertSame($scale, $actual->getScale());
}
/**
* @param string $numerator The expected numerator, as a string.
* @param string $denominator The expected denominator, as a string.
* @param BigRational $actual The BigRational instance to test.
*
* @return void
*/
final protected static function assertBigRationalInternalValues(string $numerator, string $denominator, BigRational $actual) : void
{
self::assertSame($numerator, (string) $actual->getNumerator());
self::assertSame($denominator, (string) $actual->getDenominator());
}
/**
* @param string $name
*
* @return bool
*/
final protected static function isException(string $name) : bool
{
return \substr($name, -9) === 'Exception';
}
}
|