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

DecimalAddTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 8
Bugs 1 Features 3
Metric Value
wmc 4
c 8
b 1
f 3
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
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