DecimalFloorTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testIntegerFloor() 0 17 1
A testFloorWithDecimals() 0 5 1
A testNoUsefulFloor() 0 5 1
A testNegativeFloor() 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 DecimalFloorTest extends TestCase
9
{
10
    public function testIntegerFloor()
11
    {
12
        $this->assertTrue(Decimal::fromFloat(0.00)->floor()->isZero());
13
        $this->assertTrue(Decimal::fromFloat(0.00)->floor()->equals(Decimal::fromInteger(0)));
14
15
        $this->assertTrue(Decimal::fromFloat(0.01)->floor()->isZero());
16
        $this->assertTrue(Decimal::fromFloat(0.40)->floor()->isZero());
17
        $this->assertTrue(Decimal::fromFloat(0.50)->floor()->isZero());
18
19
        $this->assertTrue(Decimal::fromFloat(0.01)->floor()->equals(Decimal::fromInteger(0)));
20
        $this->assertTrue(Decimal::fromFloat(0.40)->floor()->equals(Decimal::fromInteger(0)));
21
        $this->assertTrue(Decimal::fromFloat(0.50)->floor()->equals(Decimal::fromInteger(0)));
22
23
        $this->assertTrue(Decimal::fromFloat(1.01)->floor()->equals(Decimal::fromInteger(1)));
24
        $this->assertTrue(Decimal::fromFloat(1.40)->floor()->equals(Decimal::fromInteger(1)));
25
        $this->assertTrue(Decimal::fromFloat(1.50)->floor()->equals(Decimal::fromInteger(1)));
26
    }
27
28
    public function testFloorWithDecimals()
29
    {
30
        $this->assertTrue(Decimal::fromString('3.45')->floor(1)->equals(Decimal::fromString('3.4')));
31
        $this->assertTrue(Decimal::fromString('3.44')->floor(1)->equals(Decimal::fromString('3.4')));
32
    }
33
34
    public function testNoUsefulFloor()
35
    {
36
        $this->assertTrue(Decimal::fromString('3.45')->floor(2)->equals(Decimal::fromString('3.45')));
37
        $this->assertTrue(Decimal::fromString('3.45')->floor(3)->equals(Decimal::fromString('3.45')));
38
    }
39
40
    public function testNegativeFloor()
41
    {
42
        $this->assertTrue(Decimal::fromFloat(-3.4)->floor()->equals(Decimal::fromFloat(-4.0)));
43
        $this->assertTrue(Decimal::fromFloat(-3.6)->floor()->equals(Decimal::fromFloat(-4.0)));
44
    }
45
}
46