2014-08-31 12:13:46 +00:00
|
|
|
<?php
|
|
|
|
|
2014-08-31 14:24:10 +02:00
|
|
|
namespace Brick\Math\Tests;
|
2014-08-31 12:13:46 +00:00
|
|
|
|
|
|
|
use Brick\Math\BigDecimal;
|
|
|
|
use Brick\Math\BigInteger;
|
2015-06-12 11:37:07 +02:00
|
|
|
use Brick\Math\BigRational;
|
2014-08-31 12:13:46 +00:00
|
|
|
|
|
|
|
/**
|
2015-07-03 16:03:58 +02:00
|
|
|
* Base class for math tests.
|
2014-08-31 12:13:46 +00:00
|
|
|
*/
|
|
|
|
abstract class AbstractTestCase extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
|
|
|
/**
|
2015-07-03 16:03:58 +02:00
|
|
|
* @param string $expected The expected value, as a string.
|
2014-08-31 12:13:46 +00:00
|
|
|
* @param BigInteger $actual The BigInteger instance to test.
|
|
|
|
*/
|
2015-07-03 13:32:13 +02:00
|
|
|
final protected function assertBigIntegerEquals($expected, $actual)
|
2014-08-31 12:13:46 +00:00
|
|
|
{
|
2015-07-03 13:32:13 +02:00
|
|
|
$this->assertInstanceOf(BigInteger::class, $actual);
|
2015-06-12 01:17:42 +02:00
|
|
|
$this->assertSame($expected, (string) $actual);
|
2014-08-31 12:13:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-07-03 16:03:58 +02:00
|
|
|
* @param string $expected The expected string representation.
|
|
|
|
* @param BigDecimal $actual The BigDecimal instance to test.
|
|
|
|
*/
|
|
|
|
final protected function assertBigDecimalEquals($expected, $actual)
|
|
|
|
{
|
|
|
|
$this->assertInstanceOf(BigDecimal::class, $actual);
|
|
|
|
$this->assertSame($expected, (string) $actual);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $expected The expected string representation.
|
|
|
|
* @param BigRational $actual The BigRational instance to test.
|
|
|
|
*/
|
|
|
|
final protected function assertBigRationalEquals($expected, $actual)
|
|
|
|
{
|
|
|
|
$this->assertInstanceOf(BigRational::class, $actual);
|
|
|
|
$this->assertSame($expected, (string) $actual);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $unscaledValue The expected unscaled value, as a string.
|
2015-06-21 14:37:51 +02:00
|
|
|
* @param int $scale The expected scale.
|
2014-08-31 12:13:46 +00:00
|
|
|
* @param BigDecimal $actual The BigDecimal instance to test.
|
|
|
|
*/
|
2015-07-03 16:03:58 +02:00
|
|
|
final protected function assertBigDecimalInternalValues($unscaledValue, $scale, $actual)
|
2014-08-31 12:13:46 +00:00
|
|
|
{
|
2015-07-03 16:03:58 +02:00
|
|
|
$this->assertInstanceOf(BigDecimal::class, $actual);
|
2015-07-03 16:17:23 +02:00
|
|
|
$this->assertSame($unscaledValue, $actual->unscaledValue());
|
|
|
|
$this->assertSame($scale, $actual->scale());
|
2014-08-31 12:13:46 +00:00
|
|
|
}
|
2015-06-12 11:37:07 +02:00
|
|
|
|
|
|
|
/**
|
2015-07-03 16:03:58 +02:00
|
|
|
* @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.
|
2015-06-12 11:37:07 +02:00
|
|
|
*/
|
2015-07-03 16:03:58 +02:00
|
|
|
final protected function assertBigRationalInternalValues($numerator, $denominator, $actual)
|
2015-06-12 11:37:07 +02:00
|
|
|
{
|
2015-07-03 16:03:58 +02:00
|
|
|
$this->assertInstanceOf(BigRational::class, $actual);
|
2015-07-03 16:17:23 +02:00
|
|
|
$this->assertSame($numerator, (string) $actual->numerator());
|
|
|
|
$this->assertSame($denominator, (string) $actual->denominator());
|
2015-06-12 11:37:07 +02:00
|
|
|
}
|
2015-06-26 00:35:31 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $name
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
final protected function isException($name)
|
|
|
|
{
|
|
|
|
return substr($name, -9) === 'Exception';
|
|
|
|
}
|
2014-08-31 12:13:46 +00:00
|
|
|
}
|