diff --git a/tests/BigDecimalTest.php b/tests/BigDecimalTest.php index 999de12..2a4318f 100644 --- a/tests/BigDecimalTest.php +++ b/tests/BigDecimalTest.php @@ -19,12 +19,12 @@ class BigDecimalTest extends AbstractTestCase { /** - * @param string|number $value The value to convert to a BigDecimal. - * @param string $unscaledValue The expected unscaled value. - * @param int $scale The expected scale. + * @param int|float|string $value The value to convert to a BigDecimal. + * @param string $unscaledValue The expected unscaled value. + * @param int $scale The expected scale. */ #[DataProvider('providerOf')] - public function testOf($value, string $unscaledValue, int $scale) : void + public function testOf(int|float|string $value, string $unscaledValue, int $scale) : void { self::assertBigDecimalInternalValues($unscaledValue, $scale, BigDecimal::of($value)); } @@ -221,7 +221,7 @@ public static function providerOfFloatInDifferentLocales() : array } #[DataProvider('providerOfInvalidValueThrowsException')] - public function testOfInvalidValueThrowsException($value) : void + public function testOfInvalidValueThrowsException(int|float|string $value) : void { $this->expectException(NumberFormatException::class); BigDecimal::of($value); @@ -266,12 +266,12 @@ public function testOfBigDecimalReturnsThis() : void } /** - * @param string|int $unscaledValue The unscaled value of the BigDecimal to create. + * @param int|string $unscaledValue The unscaled value of the BigDecimal to create. * @param int $scale The scale of the BigDecimal to create. * @param string $expectedUnscaledValue The expected result unscaled value. */ #[DataProvider('providerOfUnscaledValue')] - public function testOfUnscaledValue($unscaledValue, int $scale, string $expectedUnscaledValue) : void + public function testOfUnscaledValue(int|string $unscaledValue, int $scale, string $expectedUnscaledValue) : void { $number = BigDecimal::ofUnscaledValue($unscaledValue, $scale); self::assertBigDecimalInternalValues($expectedUnscaledValue, $scale, $number); @@ -751,11 +751,8 @@ public static function providerDividedBy() : array ]; } - /** - * @param string|number $zero - */ #[DataProvider('providerDividedByByZeroThrowsException')] - public function testDividedByByZeroThrowsException($zero) : void + public function testDividedByByZeroThrowsException(int|float|string $zero) : void { $this->expectException(DivisionByZeroException::class); BigDecimal::of(1)->dividedBy($zero, 0); @@ -773,12 +770,12 @@ public static function providerDividedByByZeroThrowsException() : array } /** - * @param string|number $number The number to divide. - * @param string|number $divisor The divisor. - * @param string $expected The expected result, or a class name if an exception is expected. + * @param int|float|string $number The number to divide. + * @param int|float|string $divisor The divisor. + * @param string $expected The expected result, or a class name if an exception is expected. */ #[DataProvider('providerExactlyDividedBy')] - public function testExactlyDividedBy($number, $divisor, string $expected) : void + public function testExactlyDividedBy(int|float|string $number, int|float|string $divisor, string $expected) : void { $number = BigDecimal::of($number); @@ -2044,66 +2041,66 @@ public static function providerNegated() : array /** * @param string $a The base number as a string. - * @param string|int|float $b The number to compare to. + * @param int|float|string $b The number to compare to. * @param int $c The comparison result. */ #[DataProvider('providerCompareTo')] - public function testCompareTo(string $a, $b, int $c) : void + public function testCompareTo(string $a, int|float|string $b, int $c) : void { self::assertSame($c, BigDecimal::of($a)->compareTo($b)); } /** * @param string $a The base number as a string. - * @param string|int|float $b The number to compare to. + * @param int|float|string $b The number to compare to. * @param int $c The comparison result. */ #[DataProvider('providerCompareTo')] - public function testIsEqualTo(string $a, $b, int $c) : void + public function testIsEqualTo(string $a, int|float|string $b, int $c) : void { self::assertSame($c === 0, BigDecimal::of($a)->isEqualTo($b)); } /** * @param string $a The base number as a string. - * @param string|int|float $b The number to compare to. + * @param int|float|string $b The number to compare to. * @param int $c The comparison result. */ #[DataProvider('providerCompareTo')] - public function testIsLessThan(string $a, $b, int $c) : void + public function testIsLessThan(string $a, int|float|string $b, int $c) : void { self::assertSame($c < 0, BigDecimal::of($a)->isLessThan($b)); } /** * @param string $a The base number as a string. - * @param string|int|float $b The number to compare to. + * @param int|float|string $b The number to compare to. * @param int $c The comparison result. */ #[DataProvider('providerCompareTo')] - public function testIsLessThanOrEqualTo(string $a, $b, int $c) : void + public function testIsLessThanOrEqualTo(string $a, int|float|string $b, int $c) : void { self::assertSame($c <= 0, BigDecimal::of($a)->isLessThanOrEqualTo($b)); } /** * @param string $a The base number as a string. - * @param string|int|float $b The number to compare to. + * @param int|float|string $b The number to compare to. * @param int $c The comparison result. */ #[DataProvider('providerCompareTo')] - public function testIsGreaterThan(string $a, $b, int $c) : void + public function testIsGreaterThan(string $a, int|float|string $b, int $c) : void { self::assertSame($c > 0, BigDecimal::of($a)->isGreaterThan($b)); } /** * @param string $a The base number as a string. - * @param string|int|float $b The number to compare to. + * @param int|float|string $b The number to compare to. * @param int $c The comparison result. */ #[DataProvider('providerCompareTo')] - public function testIsGreaterThanOrEqualTo(string $a, $b, int $c) : void + public function testIsGreaterThanOrEqualTo(string $a, int|float|string $b, int $c) : void { self::assertSame($c >= 0, BigDecimal::of($a)->isGreaterThanOrEqualTo($b)); } @@ -2158,61 +2155,61 @@ public static function providerCompareTo() : array } /** - * @param number|string $number The number to test. - * @param int $sign The sign of the number. + * @param int|float|string $number The number to test. + * @param int $sign The sign of the number. */ #[DataProvider('providerSign')] - public function testGetSign($number, int $sign) : void + public function testGetSign(int|float|string $number, int $sign) : void { self::assertSame($sign, BigDecimal::of($number)->getSign()); } /** - * @param number|string $number The number to test. - * @param int $sign The sign of the number. + * @param int|float|string $number The number to test. + * @param int $sign The sign of the number. */ #[DataProvider('providerSign')] - public function testIsZero($number, int $sign) : void + public function testIsZero(int|float|string $number, int $sign) : void { self::assertSame($sign === 0, BigDecimal::of($number)->isZero()); } /** - * @param number|string $number The number to test. - * @param int $sign The sign of the number. + * @param int|float|string $number The number to test. + * @param int $sign The sign of the number. */ #[DataProvider('providerSign')] - public function testIsNegative($number, int $sign) : void + public function testIsNegative(int|float|string $number, int $sign) : void { self::assertSame($sign < 0, BigDecimal::of($number)->isNegative()); } /** - * @param number|string $number The number to test. - * @param int $sign The sign of the number. + * @param int|float|string $number The number to test. + * @param int $sign The sign of the number. */ #[DataProvider('providerSign')] - public function testIsNegativeOrZero($number, int $sign) : void + public function testIsNegativeOrZero(int|float|string $number, int $sign) : void { self::assertSame($sign <= 0, BigDecimal::of($number)->isNegativeOrZero()); } /** - * @param number|string $number The number to test. - * @param int $sign The sign of the number. + * @param int|float|string $number The number to test. + * @param int $sign The sign of the number. */ #[DataProvider('providerSign')] - public function testIsPositive($number, int $sign) : void + public function testIsPositive(int|float|string $number, int $sign) : void { self::assertSame($sign > 0, BigDecimal::of($number)->isPositive()); } /** - * @param number|string $number The number to test. - * @param int $sign The sign of the number. + * @param int|float|string $number The number to test. + * @param int $sign The sign of the number. */ #[DataProvider('providerSign')] - public function testIsPositiveOrZero($number, int $sign) : void + public function testIsPositiveOrZero(int|float|string $number, int $sign) : void { self::assertSame($sign >= 0, BigDecimal::of($number)->isPositiveOrZero()); } diff --git a/tests/BigIntegerTest.php b/tests/BigIntegerTest.php index aab7871..929e2f7 100644 --- a/tests/BigIntegerTest.php +++ b/tests/BigIntegerTest.php @@ -22,11 +22,11 @@ class BigIntegerTest extends AbstractTestCase { /** - * @param string|number $value The value to convert to a BigInteger. - * @param string $expected The expected string value of the result. + * @param int|float|string $value The value to convert to a BigInteger. + * @param string $expected The expected string value of the result. */ #[DataProvider('providerOf')] - public function testOf($value, string $expected) : void + public function testOf(int|float|string $value, string $expected) : void { self::assertBigIntegerEquals($expected, BigInteger::of($value)); } @@ -110,11 +110,8 @@ public function testOfBigIntegerReturnsThis() : void self::assertSame($decimal, BigInteger::of($decimal)); } - /** - * @param string|number $value - */ #[DataProvider('providerOfInvalidFormatThrowsException')] - public function testOfInvalidFormatThrowsException($value) : void + public function testOfInvalidFormatThrowsException(int|float|string $value) : void { $this->expectException(NumberFormatException::class); BigInteger::of($value); @@ -138,11 +135,8 @@ public static function providerOfInvalidFormatThrowsException() : array ]; } - /** - * @param float|string $value - */ #[DataProvider('providerOfNonConvertibleValueThrowsException')] - public function testOfNonConvertibleValueThrowsException($value) : void + public function testOfNonConvertibleValueThrowsException(float|string $value) : void { $this->expectException(RoundingNecessaryException::class); BigInteger::of($value); @@ -568,12 +562,12 @@ public static function providerMinus() : array } /** - * @param string $a The base number. - * @param string|int $b The number to multiply. - * @param string $r The expected result. + * @param string $a The base number. + * @param int|float|string $b The number to multiply. + * @param string $r The expected result. */ #[DataProvider('providerMultipliedBy')] - public function testMultipliedBy(string $a, $b, string $r) : void + public function testMultipliedBy(string $a, int|float|string $b, string $r) : void { self::assertBigIntegerEquals($r, BigInteger::of($a)->multipliedBy($b)); } @@ -602,11 +596,11 @@ public static function providerMultipliedBy() : array /** * @param string $number The base number. - * @param string|int|float $divisor The divisor. + * @param int|float|string $divisor The divisor. * @param string $expected The expected result, or a class name if an exception is expected. */ #[DataProvider('providerDividedBy')] - public function testDividedBy(string $number, $divisor, string $expected) : void + public function testDividedBy(string $number, int|float|string $divisor, string $expected) : void { $number = BigInteger::of($number); @@ -2847,7 +2841,7 @@ public static function providerCompareTo() : array * @param int $sign The sign of the number. */ #[DataProvider('providerSign')] - public function testGetSign($number, int $sign) : void + public function testGetSign(int|string $number, int $sign) : void { self::assertSame($sign, BigInteger::of($number)->getSign()); } @@ -2857,7 +2851,7 @@ public function testGetSign($number, int $sign) : void * @param int $sign The sign of the number. */ #[DataProvider('providerSign')] - public function testIsZero($number, int $sign) : void + public function testIsZero(int|string $number, int $sign) : void { self::assertSame($sign === 0, BigInteger::of($number)->isZero()); } @@ -2867,7 +2861,7 @@ public function testIsZero($number, int $sign) : void * @param int $sign The sign of the number. */ #[DataProvider('providerSign')] - public function testIsNegative($number, int $sign) : void + public function testIsNegative(int|string $number, int $sign) : void { self::assertSame($sign < 0, BigInteger::of($number)->isNegative()); } @@ -2877,7 +2871,7 @@ public function testIsNegative($number, int $sign) : void * @param int $sign The sign of the number. */ #[DataProvider('providerSign')] - public function testIsNegativeOrZero($number, int $sign) : void + public function testIsNegativeOrZero(int|string $number, int $sign) : void { self::assertSame($sign <= 0, BigInteger::of($number)->isNegativeOrZero()); } @@ -2887,7 +2881,7 @@ public function testIsNegativeOrZero($number, int $sign) : void * @param int $sign The sign of the number. */ #[DataProvider('providerSign')] - public function testIsPositive($number, int $sign) : void + public function testIsPositive(int|string $number, int $sign) : void { self::assertSame($sign > 0, BigInteger::of($number)->isPositive()); } @@ -2897,7 +2891,7 @@ public function testIsPositive($number, int $sign) : void * @param int $sign The sign of the number. */ #[DataProvider('providerSign')] - public function testIsPositiveOrZero($number, int $sign) : void + public function testIsPositiveOrZero(int|string $number, int $sign) : void { self::assertSame($sign >= 0, BigInteger::of($number)->isPositiveOrZero()); } diff --git a/tests/BigRationalTest.php b/tests/BigRationalTest.php index 1686510..75ff629 100644 --- a/tests/BigRationalTest.php +++ b/tests/BigRationalTest.php @@ -5,6 +5,7 @@ namespace Brick\Math\Tests; use Brick\Math\BigInteger; +use Brick\Math\BigNumber; use Brick\Math\BigRational; use Brick\Math\Exception\DivisionByZeroException; use Brick\Math\Exception\MathException; @@ -19,13 +20,13 @@ class BigRationalTest extends AbstractTestCase { /** - * @param string $numerator The expected numerator. - * @param string $denominator The expected denominator. - * @param string|int $n The input numerator. - * @param string|int $d The input denominator. + * @param string $numerator The expected numerator. + * @param string $denominator The expected denominator. + * @param int|string $n The input numerator. + * @param int|string $d The input denominator. */ #[DataProvider('providerNd')] - public function testNd(string $numerator, string $denominator, $n, $d) : void + public function testNd(string $numerator, string $denominator, int|string $n, int|string $d) : void { $rational = BigRational::nd($n, $d); self::assertBigRationalInternalValues($numerator, $denominator, $rational); @@ -217,12 +218,12 @@ public function testSumOfZeroValuesThrowsException() : void } /** - * @param string|int $rational The rational number to test. + * @param int|string $rational The rational number to test. * @param string $quotient The expected quotient. * @param string $remainder The expected remainder. */ #[DataProvider('providerQuotientAndRemainder')] - public function testQuotientAndRemainder($rational, string $quotient, string $remainder) : void + public function testQuotientAndRemainder(int|string $rational, string $quotient, string $remainder) : void { $rational = BigRational::of($rational); @@ -246,12 +247,12 @@ public static function providerQuotientAndRemainder() : array } /** - * @param string $rational The rational number to test. - * @param string|int|BigInteger|BigRational $plus The number to add. - * @param string $expected The expected rational number result. + * @param string $rational The rational number to test. + * @param BigNumber|int|string $plus The number to add. + * @param string $expected The expected rational number result. */ #[DataProvider('providerPlus')] - public function testPlus(string $rational, $plus, string $expected) : void + public function testPlus(string $rational, BigNumber|int|string $plus, string $expected) : void { self::assertBigRationalEquals($expected, BigRational::of($rational)->plus($plus)); } @@ -503,66 +504,66 @@ public static function providerSimplified() : array /** * @param string $a The first number to compare. - * @param string|int $b The second number to compare. + * @param int|string $b The second number to compare. * @param int $cmp The comparison value. */ #[DataProvider('providerCompareTo')] - public function testCompareTo(string $a, $b, int $cmp) : void + public function testCompareTo(string $a, int|string $b, int $cmp) : void { self::assertSame($cmp, BigRational::of($a)->compareTo($b)); } /** * @param string $a The first number to compare. - * @param string|int $b The second number to compare. + * @param int|string $b The second number to compare. * @param int $cmp The comparison value. */ #[DataProvider('providerCompareTo')] - public function testIsEqualTo(string $a, $b, int $cmp) : void + public function testIsEqualTo(string $a, int|string $b, int $cmp) : void { self::assertSame($cmp === 0, BigRational::of($a)->isEqualTo($b)); } /** * @param string $a The first number to compare. - * @param string|int $b The second number to compare. + * @param int|string $b The second number to compare. * @param int $cmp The comparison value. */ #[DataProvider('providerCompareTo')] - public function testIsLessThan(string $a, $b, int $cmp) : void + public function testIsLessThan(string $a, int|string $b, int $cmp) : void { self::assertSame($cmp < 0, BigRational::of($a)->isLessThan($b)); } /** * @param string $a The first number to compare. - * @param string|int $b The second number to compare. + * @param int|string $b The second number to compare. * @param int $cmp The comparison value. */ #[DataProvider('providerCompareTo')] - public function testIsLessThanOrEqualTo(string $a, $b, int $cmp) : void + public function testIsLessThanOrEqualTo(string $a, int|string $b, int $cmp) : void { self::assertSame($cmp <= 0, BigRational::of($a)->isLessThanOrEqualTo($b)); } /** * @param string $a The first number to compare. - * @param string|int $b The second number to compare. + * @param int|string $b The second number to compare. * @param int $cmp The comparison value. */ #[DataProvider('providerCompareTo')] - public function testIsGreaterThan(string $a, $b, int $cmp) : void + public function testIsGreaterThan(string $a, int|string $b, int $cmp) : void { self::assertSame($cmp > 0, BigRational::of($a)->isGreaterThan($b)); } /** * @param string $a The first number to compare. - * @param string|int $b The second number to compare. + * @param int|string $b The second number to compare. * @param int $cmp The comparison value. */ #[DataProvider('providerCompareTo')] - public function testIsGreaterThanOrEqualTo(string $a, $b, int $cmp) : void + public function testIsGreaterThanOrEqualTo(string $a, int|string $b, int $cmp) : void { self::assertSame($cmp >= 0, BigRational::of($a)->isGreaterThanOrEqualTo($b)); } @@ -810,11 +811,11 @@ public static function providerToScale() : array } /** - * @param string|int $rational The rational number to test. + * @param int|string $rational The rational number to test. * @param int $integer The expected integer value. */ #[DataProvider('providerToInt')] - public function testToInt($rational, int $integer) : void + public function testToInt(int|string $rational, int $integer) : void { self::assertSame($integer, BigRational::of($rational)->toInt()); }