Skip to content

Commit

Permalink
Test enhancement (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
peter279k authored and BenMorel committed Mar 21, 2018
1 parent 4f39b97 commit b163583
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tests/BigIntegerTest.php
Expand Up @@ -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());
}
}
103 changes: 103 additions & 0 deletions tests/Internal/Calculator/NativeCalculatorTest.php
@@ -0,0 +1,103 @@
<?php

namespace Brick\Math\Tests\Internal\Calculator;

use Brick\Math\Internal\Calculator\NativeCalculator;
use Brick\Math\Tests\AbstractTestCase;

/**
* Unit tests for class NativeCalculator.
*/
class NativeCalculatorTest extends AbstractTestCase
{
/**
* @dataProvider providerAdd
*
* @param string $a
* @param string $b
* @param string $expectedValue
*/
public function testAdd($a, $b, $expectedValue)
{
$nativeCalculator = new NativeCalculator();
$this->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'],
];
}
}

0 comments on commit b163583

Please sign in to comment.