|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace PHP\Math\BigIntegerTest; |
|
4
|
|
|
|
|
5
|
|
|
use PHP\Math\BigInteger\BigInteger; |
|
6
|
|
|
use PHPUnit_Framework_TestCase; |
|
7
|
|
|
|
|
8
|
|
|
class BigIntegerFactorialTest extends PHPUnit_Framework_TestCase |
|
9
|
|
|
{ |
|
10
|
|
|
public function testFactorial() |
|
11
|
|
|
{ |
|
12
|
|
|
// Arrange |
|
13
|
|
|
$bigInteger = new BigInteger('5'); |
|
14
|
|
|
|
|
15
|
|
|
// Act |
|
16
|
|
|
$bigIntegerValue = $bigInteger->factorial(); |
|
17
|
|
|
|
|
18
|
|
|
// Assert |
|
19
|
|
|
$this->assertInternalType('string', $bigIntegerValue->getValue()); |
|
20
|
|
|
$this->assertEquals('120', $bigIntegerValue->getValue()); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
public function testWithMutableFalse() |
|
24
|
|
|
{ |
|
25
|
|
|
// Arrange |
|
26
|
|
|
$bigInteger = new BigInteger('5', false); |
|
27
|
|
|
|
|
28
|
|
|
// Act |
|
29
|
|
|
$newBigInteger = $bigInteger->factorial(); |
|
30
|
|
|
|
|
31
|
|
|
// Assert |
|
32
|
|
|
$this->assertInstanceOf('PHP\Math\BigInteger\BigInteger', $bigInteger); |
|
33
|
|
|
$this->assertInstanceOf('PHP\Math\BigInteger\BigInteger', $newBigInteger); |
|
34
|
|
|
$this->assertEquals('5', $bigInteger->getValue()); |
|
35
|
|
|
$this->assertEquals('120', $newBigInteger->getValue()); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function testWithMutableTrue() |
|
39
|
|
|
{ |
|
40
|
|
|
// Arrange |
|
41
|
|
|
$bigInteger = new BigInteger('5', true); |
|
42
|
|
|
|
|
43
|
|
|
// Act |
|
44
|
|
|
$newBigInteger = $bigInteger->factorial(); |
|
45
|
|
|
|
|
46
|
|
|
// Assert |
|
47
|
|
|
$this->assertInstanceOf('PHP\Math\BigInteger\BigInteger', $bigInteger); |
|
48
|
|
|
$this->assertInstanceOf('PHP\Math\BigInteger\BigInteger', $newBigInteger); |
|
49
|
|
|
$this->assertEquals('120', $bigInteger->getValue()); |
|
50
|
|
|
$this->assertEquals('120', $newBigInteger->getValue()); |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
|