Completed
Pull Request — master (#51)
by
unknown
08:53
created

DecimalAddTest::testZeroAdd()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 1
Metric Value
c 3
b 0
f 1
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
5
6
date_default_timezone_set('UTC');
7
8
9
class DecimalAddTest extends PHPUnit_Framework_TestCase
10
{
11
    public function testZeroAdd()
12
    {
13
        $z = Decimal::fromInteger(0);
14
        $n = Decimal::fromInteger(5);
15
16
        $this->assertTrue($z->add($n)->equals($n));
17
        $this->assertTrue($n->add($z)->equals($n));
18
    }
19
20
    public function testPositivePositiveDecimalAdd()
21
    {
22
        $n1 = Decimal::fromString('3.45');
23
        $n2 = Decimal::fromString('7.67');
24
25
        $this->assertTrue($n1->add($n2)->equals(Decimal::fromString('11.12')));
26
        $this->assertTrue($n2->add($n1)->equals(Decimal::fromString('11.12')));
27
    }
28
29
    public function testNegativenegativeDecimalAdd()
30
    {
31
        $n1 = Decimal::fromString('-3.45');
32
        $n2 = Decimal::fromString('-7.67');
33
34
        $this->assertTrue($n1->add($n2)->equals(Decimal::fromString('-11.12')));
35
        $this->assertTrue($n2->add($n1)->equals(Decimal::fromString('-11.12')));
36
    }
37
38
    public function testPositiveNegativeDecimalAdd()
39
    {
40
        $n1 = Decimal::fromString('3.45');
41
        $n2 = Decimal::fromString('-7.67');
42
43
        $this->assertTrue($n1->add($n2)->equals(Decimal::fromString('-4.22')));
44
        $this->assertTrue($n2->add($n1)->equals(Decimal::fromString('-4.22')));
45
    }
46
}
47