Skip to content
This repository was archived by the owner on Dec 27, 2023. It is now read-only.

Commit 050d4c5

Browse files
committed
Added a new test for InfiniteDecimal casts
1 parent ab3983b commit 050d4c5

File tree

4 files changed

+51
-41
lines changed

4 files changed

+51
-41
lines changed

tests/Decimal/DecimalAsIntegerTest.php

Lines changed: 0 additions & 25 deletions
This file was deleted.

tests/Decimal/DecimalAsFloatTest.php renamed to tests/Decimal/DecimalAsNativeTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,21 @@
88

99
class DecimalAsFloatTest extends PHPUnit_Framework_TestCase
1010
{
11+
public function testAsInteger()
12+
{
13+
$this->assertEquals(1, Decimal::fromString('1.0')->asInteger());
14+
$this->assertTrue(is_int(Decimal::fromString('1.0')->asInteger()));
15+
16+
$this->assertEquals(1, Decimal::fromInteger(1)->asInteger());
17+
$this->assertTrue(is_int(Decimal::fromInteger(1)->asInteger()));
18+
19+
$this->assertEquals(1, Decimal::fromFloat(1.0)->asInteger());
20+
$this->assertEquals(1, Decimal::fromString('1.123123123')->asInteger());
21+
22+
$this->assertTrue(is_int(Decimal::fromFloat(1.0)->asInteger()));
23+
$this->assertTrue(is_int(Decimal::fromString('1.123123123')->asInteger()));
24+
}
25+
1126
public function testAsFloat()
1227
{
1328
$this->assertEquals(1.0, Decimal::fromString('1.0')->asFloat());

tests/InfiniteDecimal/InfiniteDecimalAsFloatTest.php

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
use Litipk\BigNumbers\InfiniteDecimal as InfiniteDecimal;
4+
use Litipk\Exceptions\InvalidCastException as InvalidCastException;
5+
6+
7+
date_default_timezone_set('UTC');
8+
9+
10+
class InfiniteDecimalAsFloatTest extends PHPUnit_Framework_TestCase
11+
{
12+
public function testAsFloat()
13+
{
14+
$this->assertEquals(INF, InfiniteDecimal::getPositiveInfinite()->asFloat());
15+
$this->assertEquals(-INF, InfiniteDecimal::getNegativeInfinite()->asFloat());
16+
}
17+
18+
public function testAsInteger()
19+
{
20+
$catched = false;
21+
try {
22+
InfiniteDecimal::getPositiveInfinite()->asInteger();
23+
} catch (InvalidCastException $e) {
24+
$catched = true;
25+
}
26+
$this->assertTrue($catched);
27+
28+
$catched = false;
29+
try {
30+
InfiniteDecimal::getNegativeInfinite()->asInteger();
31+
} catch (InvalidCastException $e) {
32+
$catched = true;
33+
}
34+
$this->assertTrue($catched);
35+
}
36+
}

0 commit comments

Comments
 (0)