DecimalMulTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testZeroFiniteMul() 0 14 1
B testSignsMul() 0 24 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 DecimalMulTest extends TestCase
9
{
10
    public function testZeroFiniteMul()
11
    {
12
        $z = Decimal::fromInteger(0);
13
        $n = Decimal::fromInteger(5);
14
15
        $r1 = $z->mul($n);
16
        $r2 = $n->mul($z);
17
18
        $this->assertTrue($r1->equals($r2));
19
        $this->assertTrue($r2->equals($r1));
20
21
        $this->assertTrue($r1->isZero());
22
        $this->assertTrue($r2->isZero());
23
    }
24
25
    public function testSignsMul()
26
    {
27
        $n1 = Decimal::fromInteger(1);
28
        $n2 = Decimal::fromInteger(-1);
29
30
        $n11 = $n1->mul($n1);
31
        $n12 = $n1->mul($n2);
32
        $n21 = $n2->mul($n1);
33
34
        $this->assertTrue($n1->equals($n11));
35
        $this->assertTrue($n11->equals($n1));
36
37
        $this->assertTrue($n11->isPositive());
38
        $this->assertFalse($n11->isNegative());
39
40
        $this->assertTrue($n12->equals($n21));
41
        $this->assertTrue($n21->equals($n12));
42
43
        $this->assertTrue($n12->isNegative());
44
        $this->assertTrue($n21->isNegative());
45
46
        $this->assertFalse($n12->isPositive());
47
        $this->assertFalse($n21->isPositive());
48
    }
49
}
50