DecimalCeilTest::testCeilWithDecimals()   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
7
date_default_timezone_set('UTC');
8
9
10
class DecimalCeilTest extends TestCase
11
{
12
    public function testIntegerCeil()
13
    {
14
        $this->assertTrue(Decimal::fromFloat(0.00)->ceil()->isZero());
15
        $this->assertTrue(Decimal::fromFloat(0.00)->ceil()->equals(Decimal::fromInteger(0)));
16
17
        $this->assertFalse(Decimal::fromFloat(0.01)->ceil()->isZero());
18
        $this->assertFalse(Decimal::fromFloat(0.40)->ceil()->isZero());
19
        $this->assertFalse(Decimal::fromFloat(0.50)->ceil()->isZero());
20
21
        $this->assertTrue(Decimal::fromFloat(0.01)->ceil()->equals(Decimal::fromInteger(1)));
22
        $this->assertTrue(Decimal::fromFloat(0.40)->ceil()->equals(Decimal::fromInteger(1)));
23
        $this->assertTrue(Decimal::fromFloat(0.50)->ceil()->equals(Decimal::fromInteger(1)));
24
    }
25
26
    public function testCeilWithDecimals()
27
    {
28
        $this->assertTrue(Decimal::fromString('3.45')->ceil(1)->equals(Decimal::fromString('3.5')));
29
        $this->assertTrue(Decimal::fromString('3.44')->ceil(1)->equals(Decimal::fromString('3.5')));
30
    }
31
32
    public function testNoUsefulCeil()
33
    {
34
        $this->assertTrue(Decimal::fromString('3.45')->ceil(2)->equals(Decimal::fromString('3.45')));
35
        $this->assertTrue(Decimal::fromString('3.45')->ceil(3)->equals(Decimal::fromString('3.45')));
36
    }
37
38
    public function testNegativeCeil()
39
    {
40
        $this->assertTrue(Decimal::fromFloat(-3.4)->ceil()->equals(Decimal::fromFloat(-3.0)));
41
        $this->assertTrue(Decimal::fromFloat(-3.6)->ceil()->equals(Decimal::fromFloat(-3.0)));
42
    }
43
}
44