1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use Litipk\BigNumbers\Decimal as Decimal; |
4
|
|
|
use PHPUnit\Framework\TestCase; |
5
|
|
|
|
6
|
|
|
date_default_timezone_set('UTC'); |
7
|
|
|
|
8
|
|
|
class DecimalIsIntegerTest extends TestCase |
9
|
|
|
{ |
10
|
|
|
public function testIntegers() |
11
|
|
|
{ |
12
|
|
|
$this->assertTrue(Decimal::fromInteger(-200)->isInteger()); |
13
|
|
|
$this->assertTrue(Decimal::fromInteger(-2)->isInteger()); |
14
|
|
|
$this->assertTrue(Decimal::fromInteger(-1)->isInteger()); |
15
|
|
|
$this->assertTrue(Decimal::fromInteger(0)->isInteger()); |
16
|
|
|
$this->assertTrue(Decimal::fromInteger(1)->isInteger()); |
17
|
|
|
$this->assertTrue(Decimal::fromInteger(2)->isInteger()); |
18
|
|
|
$this->assertTrue(Decimal::fromInteger(200)->isInteger()); |
19
|
|
|
|
20
|
|
|
$this->assertTrue(Decimal::fromString("-200")->isInteger()); |
21
|
|
|
$this->assertTrue(Decimal::fromString("-2")->isInteger()); |
22
|
|
|
$this->assertTrue(Decimal::fromString("-1")->isInteger()); |
23
|
|
|
$this->assertTrue(Decimal::fromString("0")->isInteger()); |
24
|
|
|
$this->assertTrue(Decimal::fromString("1")->isInteger()); |
25
|
|
|
$this->assertTrue(Decimal::fromString("2")->isInteger()); |
26
|
|
|
$this->assertTrue(Decimal::fromString("200")->isInteger()); |
27
|
|
|
|
28
|
|
|
$this->assertTrue(Decimal::fromString("-200.000")->isInteger()); |
29
|
|
|
$this->assertTrue(Decimal::fromString("-2.000")->isInteger()); |
30
|
|
|
$this->assertTrue(Decimal::fromString("-1.000")->isInteger()); |
31
|
|
|
$this->assertTrue(Decimal::fromString("0.000")->isInteger()); |
32
|
|
|
$this->assertTrue(Decimal::fromString("1.000")->isInteger()); |
33
|
|
|
$this->assertTrue(Decimal::fromString("2.000")->isInteger()); |
34
|
|
|
$this->assertTrue(Decimal::fromString("200.000")->isInteger()); |
35
|
|
|
|
36
|
|
|
$this->assertTrue(Decimal::fromFloat(-200.0)->isInteger()); |
37
|
|
|
$this->assertTrue(Decimal::fromFloat(-2.0)->isInteger()); |
38
|
|
|
$this->assertTrue(Decimal::fromFloat(-1.0)->isInteger()); |
39
|
|
|
$this->assertTrue(Decimal::fromFloat(0.0)->isInteger()); |
40
|
|
|
$this->assertTrue(Decimal::fromFloat(1.0)->isInteger()); |
41
|
|
|
$this->assertTrue(Decimal::fromFloat(2.0)->isInteger()); |
42
|
|
|
$this->assertTrue(Decimal::fromFloat(200.0)->isInteger()); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function testNotIntegers() |
46
|
|
|
{ |
47
|
|
|
$this->assertFalse(Decimal::fromString("-200.001")->isInteger()); |
48
|
|
|
$this->assertFalse(Decimal::fromString("-2.001")->isInteger()); |
49
|
|
|
$this->assertFalse(Decimal::fromString("-1.001")->isInteger()); |
50
|
|
|
$this->assertFalse(Decimal::fromString("0.001")->isInteger()); |
51
|
|
|
$this->assertFalse(Decimal::fromString("1.001")->isInteger()); |
52
|
|
|
$this->assertFalse(Decimal::fromString("2.001")->isInteger()); |
53
|
|
|
$this->assertFalse(Decimal::fromString("200.001")->isInteger()); |
54
|
|
|
|
55
|
|
|
$this->assertFalse(Decimal::fromFloat(-200.001)->isInteger()); |
56
|
|
|
$this->assertFalse(Decimal::fromFloat(-2.001)->isInteger()); |
57
|
|
|
$this->assertFalse(Decimal::fromFloat(-1.001)->isInteger()); |
58
|
|
|
$this->assertFalse(Decimal::fromFloat(0.001)->isInteger()); |
59
|
|
|
$this->assertFalse(Decimal::fromFloat(1.001)->isInteger()); |
60
|
|
|
$this->assertFalse(Decimal::fromFloat(2.001)->isInteger()); |
61
|
|
|
$this->assertFalse(Decimal::fromFloat(200.001)->isInteger()); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|