DecimalAddTest::testPositivePositiveDecimalAdd()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 1
eloc 5
nc 1
nop 0
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