DecimalRoundTest::testNoUsefulRound()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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