DecimalAsFloatTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
c 0
b 0
f 0
lcom 1
cbo 2
dl 0
loc 32
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testAsInteger() 0 14 1
A testAsFloat() 0 14 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 DecimalAsFloatTest extends TestCase
11
{
12
    public function testAsInteger()
13
    {
14
        $this->assertEquals(1, Decimal::fromString('1.0')->asInteger());
15
        $this->assertTrue(is_int(Decimal::fromString('1.0')->asInteger()));
16
17
        $this->assertEquals(1, Decimal::fromInteger(1)->asInteger());
18
        $this->assertTrue(is_int(Decimal::fromInteger(1)->asInteger()));
19
20
        $this->assertEquals(1, Decimal::fromFloat(1.0)->asInteger());
21
        $this->assertEquals(1, Decimal::fromString('1.123123123')->asInteger());
22
23
        $this->assertTrue(is_int(Decimal::fromFloat(1.0)->asInteger()));
24
        $this->assertTrue(is_int(Decimal::fromString('1.123123123')->asInteger()));
25
    }
26
27
    public function testAsFloat()
28
    {
29
        $this->assertEquals(1.0, Decimal::fromString('1.0')->asFloat());
30
        $this->assertTrue(is_float(Decimal::fromString('1.0')->asFloat()));
31
32
        $this->assertEquals(1.0, Decimal::fromInteger(1)->asFloat());
33
        $this->assertTrue(is_float(Decimal::fromInteger(1)->asFloat()));
34
35
        $this->assertEquals(1.0, Decimal::fromFloat(1.0)->asFloat());
36
        $this->assertEquals(1.123123123, Decimal::fromString('1.123123123')->asFloat());
37
38
        $this->assertTrue(is_float(Decimal::fromFloat(1.0)->asFloat()));
39
        $this->assertTrue(is_float(Decimal::fromString('1.123123123')->asFloat()));
40
    }
41
}
42