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

Commit f082b00

Browse files
committed
Fixed two tests (pow & Infinite)
1 parent 5a3247c commit f082b00

File tree

3 files changed

+29
-16
lines changed

3 files changed

+29
-16
lines changed

src/InfiniteDecimal.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,22 @@ public function pow(Decimal $b, $scale = null)
188188
throw new \DomainException("Negative infinite elevated to infinite is undefined.");
189189
}
190190

191-
191+
if ($b->isInteger()) {
192+
if (preg_match('/^[+\-]?[0-9]*[02468](\.0+)?$/', $b->value, $captures) === 1) {
193+
// $b is an even number
194+
return self::$pInf;
195+
} else {
196+
// $b is an odd number
197+
return $this; // self::$nInf;
198+
}
199+
}
192200

193201
throw new NotImplementedException("See issues #21, #22, #23 and #24 on Github.");
194202

195203
} else if ($b->isNegative()) {
196204
return DecimalConstants::Zero();
205+
} else if ($b->isZero()) {
206+
throw new \DomainException("Infinite elevated to zero is undefined.");
197207
}
198208
}
199209

tests/Decimal/DecimalTanTest.php

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,14 @@ public function testSimple($nr, $answer, $digits)
2929
'tan('.$nr.') must be equal to '.$answer.', but was '.$tanX
3030
);
3131
}
32-
33-
public function testTanPiTwoDiv()
34-
{
35-
$PI = DecimalConstants::PI();
36-
$two = Decimal::fromInteger(2);
37-
$PiDividedByTwo = $PI->div($two);
3832

39-
$catched = false;
40-
try {
41-
$PiDividedByTwo->tan();
42-
} catch (\DomainException $e) {
43-
$catched = true;
44-
}
45-
$this->assertTrue($catched);
33+
/**
34+
* @expectedException \DomainException
35+
* @expectedExceptionMessage The tangent of this 'angle' is undefined.
36+
*/
37+
public function testTanPiTwoDiv()
38+
{
39+
$PiDividedByTwo = DecimalConstants::PI()->div(Decimal::fromInteger(2));
40+
$PiDividedByTwo->tan();
4641
}
4742
}

tests/InfiniteDecimal/InfiniteDecimalPowTest.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,21 @@ public function testNegativeInfiniteNegativePower()
6262
$this->assertTrue($nInf->pow($nInf)->equals($zero));
6363
}
6464

65+
/**
66+
* @expectedException \DomainException
67+
* @expectedExceptionMessage Infinite elevated to zero is undefined.
68+
*/
6569
public function testPositiveInfiniteZeroPower()
6670
{
67-
$this->assertTrue(false);
71+
InfiniteDecimal::getPositiveInfinite()->pow(DecimalConstants::Zero());
6872
}
6973

74+
/**
75+
* @expectedException \DomainException
76+
* @expectedExceptionMessage Infinite elevated to zero is undefined.
77+
*/
7078
public function testNegativeInfiniteZeroPower()
7179
{
72-
$this->assertTrue(false);
80+
InfiniteDecimal::getNegativeInfinite()->pow(DecimalConstants::Zero());
7381
}
7482
}

0 commit comments

Comments
 (0)