DecimalCeilTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testIntegerCeil() 0 13 1
A testCeilWithDecimals() 0 5 1
A testNoUsefulCeil() 0 5 1
A testNegativeCeil() 0 5 1
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