Completed
Push — master ( b9f967...7a222d )
by Andreu
9s
created

InfiniteDecimalAddTest::testInfiniteInfiniteAdd()   B

Complexity

Conditions 3
Paths 4

Size

Total Lines 24
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 1
Metric Value
c 1
b 1
f 1
dl 0
loc 24
rs 8.9713
cc 3
eloc 17
nc 4
nop 0
1
<?php
2
3
use Litipk\BigNumbers\Decimal as Decimal;
4
use Litipk\BigNumbers\InfiniteDecimal as InfiniteDecimal;
5
6
7
date_default_timezone_set('UTC');
8
9
10
class InfiniteDecimalAddTest extends PHPUnit_Framework_TestCase
11
{
12
    public function testFiniteInfiniteAdd()
13
    {
14
        $pInf = InfiniteDecimal::getPositiveInfinite();
15
        $nInf = InfiniteDecimal::getNegativeInfinite();
16
17
        $pTen = Decimal::fromInteger(10);
18
        $nTen = Decimal::fromInteger(-10);
19
20
        $this->assertTrue($pInf->add($pTen)->equals($pInf));
21
        $this->assertTrue($nInf->add($pTen)->equals($nInf));
22
23
        $this->assertTrue($pInf->add($nTen)->equals($pInf));
24
        $this->assertTrue($nInf->add($nTen)->equals($nInf));
25
26
        $this->assertTrue($pTen->add($pInf)->equals($pInf));
27
        $this->assertTrue($pTen->add($nInf)->equals($nInf));
28
29
        $this->assertTrue($nTen->add($pInf)->equals($pInf));
30
        $this->assertTrue($nTen->add($nInf)->equals($nInf));
31
    }
32
33
    public function testInfiniteInfiniteAdd()
34
    {
35
        $pInf = InfiniteDecimal::getPositiveInfinite();
36
        $nInf = InfiniteDecimal::getNegativeInfinite();
37
38
        $this->assertTrue($pInf->add($pInf)->equals($pInf));
39
        $this->assertTrue($nInf->add($nInf)->equals($nInf));
40
41
        $catched = false;
42
        try {
43
            $pInf->add($nInf);
44
        } catch (\DomainException $e) {
45
            $catched = true;
46
        }
47
        $this->assertTrue($catched);
48
49
        $catched = false;
50
        try {
51
            $nInf->add($pInf);
52
        } catch (\DomainException $e) {
53
            $catched = true;
54
        }
55
        $this->assertTrue($catched);
56
    }
57
}
58