1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PHP\Math\BigIntegerTest; |
4
|
|
|
|
5
|
|
|
use PHP\Math\BigInteger\BigInteger; |
6
|
|
|
use PHPUnit_Framework_TestCase; |
7
|
|
|
|
8
|
|
|
class BigIntegerModTest extends PHPUnit_Framework_TestCase |
9
|
|
|
{ |
10
|
|
|
public function testWithInteger() |
11
|
|
|
{ |
12
|
|
|
// Arrange |
13
|
|
|
$bigInteger = new BigInteger('456'); |
14
|
|
|
|
15
|
|
|
// Act |
16
|
|
|
$bigInteger->mod(123); |
17
|
|
|
|
18
|
|
|
// Assert |
19
|
|
|
$this->assertInternalType('string', $bigInteger->getValue()); |
20
|
|
|
$this->assertEquals('87', $bigInteger->getValue()); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function testWithString() |
24
|
|
|
{ |
25
|
|
|
// Arrange |
26
|
|
|
$bigInteger = new BigInteger('456'); |
27
|
|
|
|
28
|
|
|
// Act |
29
|
|
|
$bigInteger->mod('123'); |
30
|
|
|
|
31
|
|
|
// Assert |
32
|
|
|
$this->assertInternalType('string', $bigInteger->getValue()); |
33
|
|
|
$this->assertEquals('87', $bigInteger->getValue()); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function testWithBigInteger() |
37
|
|
|
{ |
38
|
|
|
// Arrange |
39
|
|
|
$bigInteger = new BigInteger('456'); |
40
|
|
|
$bigIntegerValue = new BigInteger('123'); |
41
|
|
|
|
42
|
|
|
// Act |
43
|
|
|
$bigInteger->mod($bigIntegerValue); |
44
|
|
|
|
45
|
|
|
// Assert |
46
|
|
|
$this->assertInternalType('string', $bigInteger->getValue()); |
47
|
|
|
$this->assertEquals('87', $bigInteger->getValue()); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @expectedException InvalidArgumentException |
52
|
|
|
*/ |
53
|
|
|
public function testWithInvalidValue() |
54
|
|
|
{ |
55
|
|
|
// Arrange |
56
|
|
|
$bigInteger = new BigInteger('123'); |
57
|
|
|
|
58
|
|
|
// Act |
59
|
|
|
$bigInteger->mod('123.123'); |
60
|
|
|
|
61
|
|
|
// Assert |
62
|
|
|
// ... |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function testWithMutableFalse() |
66
|
|
|
{ |
67
|
|
|
// Arrange |
68
|
|
|
$bigInteger = new BigInteger('15', false); |
69
|
|
|
|
70
|
|
|
// Act |
71
|
|
|
$newBigInteger = $bigInteger->mod('7'); |
72
|
|
|
|
73
|
|
|
// Assert |
74
|
|
|
$this->assertInstanceOf('PHP\Math\BigInteger\BigInteger', $bigInteger); |
75
|
|
|
$this->assertInstanceOf('PHP\Math\BigInteger\BigInteger', $newBigInteger); |
76
|
|
|
$this->assertEquals('15', $bigInteger->getValue()); |
77
|
|
|
$this->assertEquals('1', $newBigInteger->getValue()); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function testWithMutableTrue() |
81
|
|
|
{ |
82
|
|
|
// Arrange |
83
|
|
|
$bigInteger = new BigInteger('15', true); |
84
|
|
|
|
85
|
|
|
// Act |
86
|
|
|
$newBigInteger = $bigInteger->mod('7'); |
87
|
|
|
|
88
|
|
|
// Assert |
89
|
|
|
$this->assertInstanceOf('PHP\Math\BigInteger\BigInteger', $bigInteger); |
90
|
|
|
$this->assertInstanceOf('PHP\Math\BigInteger\BigInteger', $newBigInteger); |
91
|
|
|
$this->assertEquals('1', $bigInteger->getValue()); |
92
|
|
|
$this->assertEquals('1', $newBigInteger->getValue()); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|