DecimalRoundTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
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 31
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testIntegerRound() 0 8 1
A testRoundWithDecimals() 0 5 1
A testNegativeRoundWithDecimals() 0 7 1
A testNoUsefulRound() 0 5 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 DecimalRoundTest extends TestCase
9
{
10
    public function testIntegerRound()
11
    {
12
        $this->assertTrue(Decimal::fromFloat(0.4)->round()->isZero());
13
        $this->assertTrue(Decimal::fromFloat(0.4)->round()->equals(Decimal::fromInteger(0)));
14
15
        $this->assertFalse(Decimal::fromFloat(0.5)->round()->isZero());
16
        $this->assertTrue(Decimal::fromFloat(0.5)->round()->equals(Decimal::fromInteger(1)));
17
    }
18
19
    public function testRoundWithDecimals()
20
    {
21
        $this->assertTrue(Decimal::fromString('3.45')->round(1)->equals(Decimal::fromString('3.5')));
22
        $this->assertTrue(Decimal::fromString('3.44')->round(1)->equals(Decimal::fromString('3.4')));
23
    }
24
25
    public function testNegativeRoundWithDecimals()
26
    {
27
        $this->assertTrue(Decimal::fromString('-5.59059956723478932512')->round(3)->equals(Decimal::fromString('-5.591')));
28
        $this->assertTrue(Decimal::fromString('-5.59059956723478932512')->round(4)->equals(Decimal::fromString('-5.5906')));
29
        $this->assertTrue(Decimal::fromString('-5.59059956723478932512')->round(5)->equals(Decimal::fromString('-5.59060')));
30
        $this->assertTrue(Decimal::fromString('-5.59059956723478932512')->round(6)->equals(Decimal::fromString('-5.590600')));
31
    }
32
33
    public function testNoUsefulRound()
34
    {
35
        $this->assertTrue(Decimal::fromString('3.45')->round(2)->equals(Decimal::fromString('3.45')));
36
        $this->assertTrue(Decimal::fromString('3.45')->round(3)->equals(Decimal::fromString('3.45')));
37
    }
38
}
39