From b163583644c37b7924175f491e9273bb8f7d64db Mon Sep 17 00:00:00 2001 From: peter279k Date: Thu, 22 Mar 2018 06:18:11 +0800 Subject: [PATCH] Test enhancement (#10) --- tests/BigIntegerTest.php | 9 ++ .../Calculator/NativeCalculatorTest.php | 103 ++++++++++++++++++ 2 files changed, 112 insertions(+) create mode 100644 tests/Internal/Calculator/NativeCalculatorTest.php diff --git a/tests/BigIntegerTest.php b/tests/BigIntegerTest.php index 45ecacc..48e8dde 100644 --- a/tests/BigIntegerTest.php +++ b/tests/BigIntegerTest.php @@ -1905,4 +1905,13 @@ public function testDirectCallToUnserialize() { BigInteger::zero()->unserialize('123'); } + + public function testJsonSerialize() + { + $value = '-1234567890987654321012345678909876543210123456789'; + + $number = BigInteger::of($value); + + $this->assertSame($value, $number->jsonSerialize()); + } } diff --git a/tests/Internal/Calculator/NativeCalculatorTest.php b/tests/Internal/Calculator/NativeCalculatorTest.php new file mode 100644 index 0000000..e7f1c3f --- /dev/null +++ b/tests/Internal/Calculator/NativeCalculatorTest.php @@ -0,0 +1,103 @@ +assertSame($expectedValue, $nativeCalculator->add($a, $b)); + } + + /** + * @return array + */ + public function providerAdd() + { + return [ + ['0', '1234567891234567889999999', '1234567891234567889999999'], + ['1234567891234567889999999', '0', '1234567891234567889999999'], + + ['1234567891234567889999999', '-1234567891234567889999999', '0'], + ['-1234567891234567889999999', '1234567891234567889999999', '0'], + + ['1234567891234567889999999', '1234567891234567889999999', '2469135782469135779999998'], + ]; + } + + /** + * @dataProvider providerMul + * + * @param string $a + * @param string $b + * @param string $expectedValue + */ + public function testMul($a, $b, $expectedValue) + { + $nativeCalculator = new NativeCalculator(); + $this->assertSame($expectedValue, $nativeCalculator->mul($a, $b)); + } + + /** + * @return array + */ + public function providerMul() + { + return [ + ['0', '0', '0'], + + ['1', '1234567891234567889999999', '1234567891234567889999999'], + ['1234567891234567889999999', '1', '1234567891234567889999999'], + + ['1234567891234567889999999', '-1234567891234567889999999', '-1524157878067367851562259605883269630864220000001'], + ['-1234567891234567889999999', '1234567891234567889999999', '-1524157878067367851562259605883269630864220000001'], + + ['1234567891234567889999999', '1234567891234567889999999', '1524157878067367851562259605883269630864220000001'], + ]; + } + + /** + * @dataProvider providerPow + * + * @param string $a + * @param string $b + * @param string $expectedValue + */ + public function testPow($a, $b, $expectedValue) + { + $nativeCalculator = new NativeCalculator(); + $this->assertSame($expectedValue, $nativeCalculator->pow($a, $b)); + } + + /** + * @return array + */ + public function providerPow() + { + return [ + ['123456789012345678901234567890', 0, '1'], + + ['1', 2, '1'], + ['1234567891234567889999999', 1, '1234567891234567889999999'], + + ['1234567891234567889999999', -2, '1'], + ['-1234567891234567889999999', 2, '1524157878067367851562259605883269630864220000001'], + + ['1234567891234567889999999', 3, '1881676377434183981909558127466713752376807174114547646517403703669999999'], + ]; + } +}