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

DecimalFloorTest::testNegativeFloor()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
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
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