1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use Litipk\BigNumbers\InfiniteDecimal as InfiniteDecimal; |
4
|
|
|
use Litipk\BigNumbers\Decimal as Decimal; |
5
|
|
|
|
6
|
|
|
|
7
|
|
|
date_default_timezone_set('UTC'); |
8
|
|
|
|
9
|
|
|
|
10
|
|
|
class InfiniteDecimalDivTest extends PHPUnit_Framework_TestCase |
11
|
|
|
{ |
12
|
|
|
public function testZeroInfiniteDiv() |
13
|
|
|
{ |
14
|
|
|
$pInf = InfiniteDecimal::getPositiveInfinite(); |
15
|
|
|
$nInf = InfiniteDecimal::getNegativeInfinite(); |
16
|
|
|
$zero = Decimal::fromInteger(0); |
17
|
|
|
|
18
|
|
|
$catched = false; |
19
|
|
|
try { |
20
|
|
|
$pInf->div($zero); |
21
|
|
|
} catch (\DomainException $e) { |
22
|
|
|
$catched = true; |
23
|
|
|
} |
24
|
|
|
$this->assertTrue($catched); |
25
|
|
|
|
26
|
|
|
$catched = false; |
27
|
|
|
try { |
28
|
|
|
$nInf->div($zero); |
29
|
|
|
} catch (\DomainException $e) { |
30
|
|
|
$catched = true; |
31
|
|
|
} |
32
|
|
|
$this->assertTrue($catched); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function testFiniteInfiniteDiv() |
36
|
|
|
{ |
37
|
|
|
$pTen = Decimal::fromInteger(10); |
38
|
|
|
$nTen = Decimal::fromInteger(-10); |
39
|
|
|
|
40
|
|
|
$pInf = InfiniteDecimal::getPositiveInfinite(); |
41
|
|
|
$nInf = InfiniteDecimal::getNegativeInfinite(); |
42
|
|
|
|
43
|
|
|
$this->assertTrue($pInf->div($pTen)->equals($pInf)); |
44
|
|
|
$this->assertTrue($pInf->div($nTen)->equals($nInf)); |
45
|
|
|
|
46
|
|
|
$this->assertTrue($nInf->div($pTen)->equals($nInf)); |
47
|
|
|
$this->assertTrue($nInf->div($nTen)->equals($pInf)); |
48
|
|
|
|
49
|
|
|
$this->assertTrue($pTen->div($pInf)->isZero()); |
50
|
|
|
$this->assertTrue($nTen->div($pInf)->isZero()); |
51
|
|
|
|
52
|
|
|
$this->assertTrue($pTen->div($nInf)->isZero()); |
53
|
|
|
$this->assertTrue($nTen->div($nInf)->isZero()); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function testInfiniteInfiniteDiv() |
57
|
|
|
{ |
58
|
|
|
$pInf = InfiniteDecimal::getPositiveInfinite(); |
59
|
|
|
$nInf = InfiniteDecimal::getNegativeInfinite(); |
60
|
|
|
|
61
|
|
|
$catched = false; |
62
|
|
|
try { |
63
|
|
|
$pInf->div($pInf); |
64
|
|
|
} catch (\DomainException $e) { |
65
|
|
|
$catched = true; |
66
|
|
|
} |
67
|
|
|
$this->assertTrue($catched); |
68
|
|
|
|
69
|
|
|
$catched = false; |
70
|
|
|
try { |
71
|
|
|
$pInf->div($nInf); |
72
|
|
|
} catch (\DomainException $e) { |
73
|
|
|
$catched = true; |
74
|
|
|
} |
75
|
|
|
$this->assertTrue($catched); |
76
|
|
|
|
77
|
|
|
$catched = false; |
78
|
|
|
try { |
79
|
|
|
$nInf->div($pInf); |
80
|
|
|
} catch (\DomainException $e) { |
81
|
|
|
$catched = true; |
82
|
|
|
} |
83
|
|
|
$this->assertTrue($catched); |
84
|
|
|
|
85
|
|
|
$catched = false; |
86
|
|
|
try { |
87
|
|
|
$nInf->div($nInf); |
88
|
|
|
} catch (\DomainException $e) { |
89
|
|
|
$catched = true; |
90
|
|
|
} |
91
|
|
|
$this->assertTrue($catched); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|