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

Commit 3100787

Browse files
committed
Added new tests, fixed some bugs related with trigonometry and infinite values
1 parent 050d4c5 commit 3100787

12 files changed

+181
-57
lines changed

src/Decimal.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ public function mod(Decimal $d, $scale = null)
637637
* Calculates the sine of this method with the highest possible accuracy
638638
* Note that accuracy is limited by the accuracy of predefined PI;
639639
*
640-
* @param null $scale
640+
* @param integer $scale
641641
* @return Decimal sin($this)
642642
*/
643643
public function sin($scale = null) {
@@ -689,7 +689,7 @@ public function sin($scale = null) {
689689
* Calculates the cosine of this method with the highest possible accuracy
690690
* Note that accuracy is limited by the accuracy of predefined PI;
691691
*
692-
* @param null $scale
692+
* @param integer $scale
693693
* @return Decimal cos($this)
694694
*/
695695
public function cos($scale = null) {
@@ -741,7 +741,7 @@ public function cos($scale = null) {
741741
* Calculates the tangent of this method with the highest possible accuracy
742742
* Note that accuracy is limited by the accuracy of predefined PI;
743743
*
744-
* @param null $scale
744+
* @param integer $scale
745745
* @return Decimal tan($this)
746746
*/
747747
public function tan($scale = null) {

src/InfiniteDecimal.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,30 @@ public function floor($scale = 0)
257257
return $this;
258258
}
259259

260+
public function sin($scale = null)
261+
{
262+
throw new \DomainException(($this === self::$pInf) ?
263+
"Sinus function hasn't limit in the positive infinite." :
264+
"Sinus function hasn't limit in the negative infinite."
265+
);
266+
}
267+
268+
public function cos($scale = null)
269+
{
270+
throw new \DomainException(($this === self::$pInf) ?
271+
"Cosinus function hasn't limit in the positive infinite." :
272+
"Cosinus function hasn't limit in the negative infinite."
273+
);
274+
}
275+
276+
public function tan($scale = null)
277+
{
278+
throw new \DomainException(($this === self::$pInf) ?
279+
"Tangent function hasn't limit in the positive infinite." :
280+
"Tangent function hasn't limit in the negative infinite."
281+
);
282+
}
283+
260284
/**
261285
* @return boolean
262286
*/

tests/Decimal/DecimalCeilTest.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,4 @@ public function testNoUsefulCeil()
3333
$this->assertTrue(Decimal::fromString('3.45')->ceil(2)->equals(Decimal::fromString('3.45')));
3434
$this->assertTrue(Decimal::fromString('3.45')->ceil(3)->equals(Decimal::fromString('3.45')));
3535
}
36-
37-
public function testInfiniteRound()
38-
{
39-
$pInf = Decimal::getPositiveInfinite();
40-
$nInf = Decimal::getNegativeInfinite();
41-
42-
$this->assertTrue($pInf->ceil()->equals($pInf));
43-
$this->assertTrue($nInf->ceil()->equals($nInf));
44-
}
4536
}

tests/Decimal/DecimalCompTest.php

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -22,29 +22,4 @@ public function testBasicCases()
2222
$this->assertTrue($one->comp($ten) === -1);
2323
$this->assertTrue($ten->comp($one) === 1);
2424
}
25-
26-
public function testFiniteInfiniteComp()
27-
{
28-
$ten = Decimal::fromInteger(10);
29-
$pInf = Decimal::getPositiveInfinite();
30-
$nInf = Decimal::getNegativeInfinite();
31-
32-
$this->assertTrue($ten->comp($pInf) === -1);
33-
$this->assertTrue($ten->comp($nInf) === 1);
34-
35-
$this->assertTrue($pInf->comp($ten) === 1);
36-
$this->assertTrue($nInf->comp($ten) === -1);
37-
}
38-
39-
public function testInfiniteInfiniteComp()
40-
{
41-
$pInf = Decimal::getPositiveInfinite();
42-
$nInf = Decimal::getNegativeInfinite();
43-
44-
$this->assertTrue($pInf->comp($pInf) === 0);
45-
$this->assertTrue($nInf->comp($nInf) === 0);
46-
47-
$this->assertTrue($pInf->comp($nInf) === 1);
48-
$this->assertTrue($nInf->comp($pInf) === -1);
49-
}
5025
}

tests/Decimal/DecimalCosTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@
88
class DecimalCosTest extends PHPUnit_Framework_TestCase
99
{
1010
public function cosProvider() {
11-
// Some values providede by mathematica
11+
// Some values provided by Mathematica
1212
return array(
1313
array('1', '0.54030230586814', '14'),
1414
array('123.123', '-0.82483472946164834', '17'),
1515
array('15000000000', '-0.72218064388924347681', '20')
16-
1716
);
1817
}
1918

tests/Decimal/DecimalFloorTest.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,4 @@ public function testNoUsefulFloor()
3737
$this->assertTrue(Decimal::fromString('3.45')->floor(2)->equals(Decimal::fromString('3.45')));
3838
$this->assertTrue(Decimal::fromString('3.45')->floor(3)->equals(Decimal::fromString('3.45')));
3939
}
40-
41-
public function testInfiniteRound()
42-
{
43-
$pInf = Decimal::getPositiveInfinite();
44-
$nInf = Decimal::getNegativeInfinite();
45-
46-
$this->assertTrue($pInf->floor()->equals($pInf));
47-
$this->assertTrue($nInf->floor()->equals($nInf));
48-
}
4940
}

tests/Decimal/DecimalRoundTest.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,4 @@ public function testNoUsefulRound()
2828
$this->assertTrue(Decimal::fromString('3.45')->round(2)->equals(Decimal::fromString('3.45')));
2929
$this->assertTrue(Decimal::fromString('3.45')->round(3)->equals(Decimal::fromString('3.45')));
3030
}
31-
32-
public function testInfiniteRound()
33-
{
34-
$pInf = Decimal::getPositiveInfinite();
35-
$nInf = Decimal::getNegativeInfinite();
36-
37-
$this->assertTrue($pInf->round()->equals($pInf));
38-
$this->assertTrue($nInf->round()->equals($nInf));
39-
}
4031
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
use Litipk\BigNumbers\Decimal as Decimal;
4+
5+
6+
date_default_timezone_set('UTC');
7+
8+
9+
class InfiniteDecimalCompTest extends PHPUnit_Framework_TestCase
10+
{
11+
public function testFiniteInfiniteComp()
12+
{
13+
$ten = Decimal::fromInteger(10);
14+
$pInf = Decimal::getPositiveInfinite();
15+
$nInf = Decimal::getNegativeInfinite();
16+
17+
$this->assertTrue($ten->comp($pInf) === -1);
18+
$this->assertTrue($ten->comp($nInf) === 1);
19+
20+
$this->assertTrue($pInf->comp($ten) === 1);
21+
$this->assertTrue($nInf->comp($ten) === -1);
22+
}
23+
24+
public function testInfiniteInfiniteComp()
25+
{
26+
$pInf = Decimal::getPositiveInfinite();
27+
$nInf = Decimal::getNegativeInfinite();
28+
29+
$this->assertTrue($pInf->comp($pInf) === 0);
30+
$this->assertTrue($nInf->comp($nInf) === 0);
31+
32+
$this->assertTrue($pInf->comp($nInf) === 1);
33+
$this->assertTrue($nInf->comp($pInf) === -1);
34+
}
35+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
use Litipk\BigNumbers\InfiniteDecimal as InfiniteDecimal;
4+
5+
/**
6+
* @group cos
7+
*/
8+
class InfiniteDecimalCosTest extends PHPUnit_Framework_TestCase
9+
{
10+
/**
11+
* @expectedException \DomainException
12+
* @expectedExceptionMessage Cosinus function hasn't limit in the positive infinite.
13+
*/
14+
public function testFinitePositiveInfiniteCos()
15+
{
16+
InfiniteDecimal::getPositiveInfinite()->cos();
17+
}
18+
19+
/**
20+
* @expectedException \DomainException
21+
* @expectedExceptionMessage Cosinus function hasn't limit in the negative infinite.
22+
*/
23+
public function testFiniteNegativeInfiniteCos()
24+
{
25+
InfiniteDecimal::getNegativeInfinite()->cos();
26+
}
27+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
use Litipk\BigNumbers\Decimal as Decimal;
4+
5+
6+
date_default_timezone_set('UTC');
7+
8+
9+
class InfiniteDecimalRoundingTest extends PHPUnit_Framework_TestCase
10+
{
11+
public function testInfiniteCeil()
12+
{
13+
$pInf = Decimal::getPositiveInfinite();
14+
$nInf = Decimal::getNegativeInfinite();
15+
16+
$this->assertTrue($pInf->ceil()->equals($pInf));
17+
$this->assertTrue($nInf->ceil()->equals($nInf));
18+
}
19+
20+
public function testInfiniteFloor()
21+
{
22+
$pInf = Decimal::getPositiveInfinite();
23+
$nInf = Decimal::getNegativeInfinite();
24+
25+
$this->assertTrue($pInf->floor()->equals($pInf));
26+
$this->assertTrue($nInf->floor()->equals($nInf));
27+
}
28+
29+
public function testInfiniteRound()
30+
{
31+
$pInf = Decimal::getPositiveInfinite();
32+
$nInf = Decimal::getNegativeInfinite();
33+
34+
$this->assertTrue($pInf->round()->equals($pInf));
35+
$this->assertTrue($nInf->round()->equals($nInf));
36+
}
37+
}

0 commit comments

Comments
 (0)