1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PHP\Math\BigIntegerTest; |
4
|
|
|
|
5
|
|
|
use PHP\Math\BigInteger\BigInteger; |
6
|
|
|
use PHPUnit_Framework_TestCase; |
7
|
|
|
|
8
|
|
|
class BigIntegerAbsTest extends PHPUnit_Framework_TestCase |
9
|
|
|
{ |
10
|
|
|
public function testWithNegativeNumber() |
11
|
|
|
{ |
12
|
|
|
// Arrange |
13
|
|
|
$bigInteger = new BigInteger('-123'); |
14
|
|
|
|
15
|
|
|
// Act |
16
|
|
|
$bigInteger->abs(); |
17
|
|
|
|
18
|
|
|
// Assert |
19
|
|
|
$this->assertInternalType('string', $bigInteger->getValue()); |
20
|
|
|
$this->assertEquals('123', $bigInteger->getValue()); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function testWithPositiveNumber() |
24
|
|
|
{ |
25
|
|
|
// Arrange |
26
|
|
|
$bigInteger = new BigInteger('123'); |
27
|
|
|
|
28
|
|
|
// Act |
29
|
|
|
$bigInteger->abs(); |
30
|
|
|
|
31
|
|
|
// Assert |
32
|
|
|
$this->assertInternalType('string', $bigInteger->getValue()); |
33
|
|
|
$this->assertEquals('123', $bigInteger->getValue()); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function testWithZeroNumber() |
37
|
|
|
{ |
38
|
|
|
// Arrange |
39
|
|
|
$bigInteger = new BigInteger('0'); |
40
|
|
|
|
41
|
|
|
// Act |
42
|
|
|
$bigInteger->abs(); |
43
|
|
|
|
44
|
|
|
// Assert |
45
|
|
|
$this->assertInternalType('string', $bigInteger->getValue()); |
46
|
|
|
$this->assertEquals('0', $bigInteger->getValue()); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function testWithMutableFalse() |
50
|
|
|
{ |
51
|
|
|
// Arrange |
52
|
|
|
$bigInteger = new BigInteger('-5', false); |
53
|
|
|
|
54
|
|
|
// Act |
55
|
|
|
$newBigInteger = $bigInteger->abs(); |
56
|
|
|
|
57
|
|
|
// Assert |
58
|
|
|
$this->assertInstanceOf('PHP\Math\BigInteger\BigInteger', $bigInteger); |
59
|
|
|
$this->assertInstanceOf('PHP\Math\BigInteger\BigInteger', $newBigInteger); |
60
|
|
|
$this->assertEquals('-5', $bigInteger->getValue()); |
61
|
|
|
$this->assertEquals('5', $newBigInteger->getValue()); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function testWithMutableTrue() |
65
|
|
|
{ |
66
|
|
|
// Arrange |
67
|
|
|
$bigInteger = new BigInteger('-5', true); |
68
|
|
|
|
69
|
|
|
// Act |
70
|
|
|
$newBigInteger = $bigInteger->abs(); |
71
|
|
|
|
72
|
|
|
// Assert |
73
|
|
|
$this->assertInstanceOf('PHP\Math\BigInteger\BigInteger', $bigInteger); |
74
|
|
|
$this->assertInstanceOf('PHP\Math\BigInteger\BigInteger', $newBigInteger); |
75
|
|
|
$this->assertEquals('5', $bigInteger->getValue()); |
76
|
|
|
$this->assertEquals('5', $newBigInteger->getValue()); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|