1
0
mirror of https://github.com/danog/math.git synced 2025-01-23 06:01:25 +01:00
math/tests/AbstractTestCase.php

78 lines
2.5 KiB
PHP
Raw Normal View History

2014-08-31 12:13:46 +00:00
<?php
namespace Brick\Math\Tests;
2014-08-31 12:13:46 +00:00
use Brick\Math\BigDecimal;
use Brick\Math\BigInteger;
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.
*/
final protected function assertBigIntegerEquals($expected, $actual)
2014-08-31 12:13:46 +00: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.
* @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);
$this->assertSame($unscaledValue, $actual->unscaledValue());
$this->assertSame($scale, $actual->scale());
2014-08-31 12:13:46 +00: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-07-03 16:03:58 +02:00
final protected function assertBigRationalInternalValues($numerator, $denominator, $actual)
{
2015-07-03 16:03:58 +02:00
$this->assertInstanceOf(BigRational::class, $actual);
$this->assertSame($numerator, (string) $actual->numerator());
$this->assertSame($denominator, (string) $actual->denominator());
}
/**
* @param string $name
*
* @return bool
*/
final protected function isException($name)
{
return substr($name, -9) === 'Exception';
}
2014-08-31 12:13:46 +00:00
}