Completed
Push — master ( b9f967...7a222d )
by Andreu
9s
created

DecimalFloorTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 3
Bugs 2 Features 2
Metric Value
wmc 4
c 3
b 2
f 2
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
5
6
date_default_timezone_set('UTC');
7
8
9
class DecimalFloorTest extends PHPUnit_Framework_TestCase
10
{
11
    public function testIntegerFloor()
12
    {
13
        $this->assertTrue(Decimal::fromFloat(0.00)->floor()->isZero());
14
        $this->assertTrue(Decimal::fromFloat(0.00)->floor()->equals(Decimal::fromInteger(0)));
15
16
        $this->assertTrue(Decimal::fromFloat(0.01)->floor()->isZero());
17
        $this->assertTrue(Decimal::fromFloat(0.40)->floor()->isZero());
18
        $this->assertTrue(Decimal::fromFloat(0.50)->floor()->isZero());
19
20
        $this->assertTrue(Decimal::fromFloat(0.01)->floor()->equals(Decimal::fromInteger(0)));
21
        $this->assertTrue(Decimal::fromFloat(0.40)->floor()->equals(Decimal::fromInteger(0)));
22
        $this->assertTrue(Decimal::fromFloat(0.50)->floor()->equals(Decimal::fromInteger(0)));
23
24
        $this->assertTrue(Decimal::fromFloat(1.01)->floor()->equals(Decimal::fromInteger(1)));
25
        $this->assertTrue(Decimal::fromFloat(1.40)->floor()->equals(Decimal::fromInteger(1)));
26
        $this->assertTrue(Decimal::fromFloat(1.50)->floor()->equals(Decimal::fromInteger(1)));
27
    }
28
29
    public function testFloorWithDecimals()
30
    {
31
        $this->assertTrue(Decimal::fromString('3.45')->floor(1)->equals(Decimal::fromString('3.4')));
32
        $this->assertTrue(Decimal::fromString('3.44')->floor(1)->equals(Decimal::fromString('3.4')));
33
    }
34
35
    public function testNoUsefulFloor()
36
    {
37
        $this->assertTrue(Decimal::fromString('3.45')->floor(2)->equals(Decimal::fromString('3.45')));
38
        $this->assertTrue(Decimal::fromString('3.45')->floor(3)->equals(Decimal::fromString('3.45')));
39
    }
40
41
    public function testNegativeFloor()
42
    {
43
        $this->assertTrue(Decimal::fromFloat(-3.4)->floor()->equals(Decimal::fromFloat(-4.0)));
44
        $this->assertTrue(Decimal::fromFloat(-3.6)->floor()->equals(Decimal::fromFloat(-4.0)));
45
    }
46
}
47