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

InfiniteDecimalAddTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 1
Bugs 1 Features 1
Metric Value
wmc 4
c 1
b 1
f 1
lcom 0
cbo 3
dl 0
loc 48
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testFiniteInfiniteAdd() 0 20 1
B testInfiniteInfiniteAdd() 0 24 3
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