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
|
|
|
|