DecimalAddTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
c 0
b 0
f 0
lcom 1
cbo 2
dl 0
loc 38
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testZeroAdd() 0 8 1
A testPositivePositiveDecimalAdd() 0 8 1
A testNegativenegativeDecimalAdd() 0 8 1
A testPositiveNegativeDecimalAdd() 0 8 1
1
<?php
2
3
use Litipk\BigNumbers\Decimal as Decimal;
4
use PHPUnit\Framework\TestCase;
5
6
date_default_timezone_set('UTC');
7
8
class DecimalAddTest extends TestCase
9
{
10
    public function testZeroAdd()
11
    {
12
        $z = Decimal::fromInteger(0);
13
        $n = Decimal::fromInteger(5);
14
15
        $this->assertTrue($z->add($n)->equals($n));
16
        $this->assertTrue($n->add($z)->equals($n));
17
    }
18
19
    public function testPositivePositiveDecimalAdd()
20
    {
21
        $n1 = Decimal::fromString('3.45');
22
        $n2 = Decimal::fromString('7.67');
23
24
        $this->assertTrue($n1->add($n2)->equals(Decimal::fromString('11.12')));
25
        $this->assertTrue($n2->add($n1)->equals(Decimal::fromString('11.12')));
26
    }
27
28
    public function testNegativenegativeDecimalAdd()
29
    {
30
        $n1 = Decimal::fromString('-3.45');
31
        $n2 = Decimal::fromString('-7.67');
32
33
        $this->assertTrue($n1->add($n2)->equals(Decimal::fromString('-11.12')));
34
        $this->assertTrue($n2->add($n1)->equals(Decimal::fromString('-11.12')));
35
    }
36
37
    public function testPositiveNegativeDecimalAdd()
38
    {
39
        $n1 = Decimal::fromString('3.45');
40
        $n2 = Decimal::fromString('-7.67');
41
42
        $this->assertTrue($n1->add($n2)->equals(Decimal::fromString('-4.22')));
43
        $this->assertTrue($n2->add($n1)->equals(Decimal::fromString('-4.22')));
44
    }
45
}
46