Completed
Pull Request — master (#51)
by
unknown
08:53
created

DecimalSqrtTest::testPositiveInfiniteSqrt()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
use Litipk\BigNumbers\Decimal as Decimal;
4
5
6
date_default_timezone_set('UTC');
7
8
9
class DecimalSqrtTest extends PHPUnit_Framework_TestCase
10
{
11
    public function testIntegerSqrt()
12
    {
13
        $this->assertTrue(Decimal::fromInteger(0)->sqrt()->equals(Decimal::fromInteger(0)));
14
        $this->assertTrue(Decimal::fromInteger(1)->sqrt()->equals(Decimal::fromInteger(1)));
15
        $this->assertTrue(Decimal::fromInteger(4)->sqrt()->equals(Decimal::fromInteger(2)));
16
        $this->assertTrue(Decimal::fromInteger(9)->sqrt()->equals(Decimal::fromInteger(3)));
17
        $this->assertTrue(Decimal::fromInteger(16)->sqrt()->equals(Decimal::fromInteger(4)));
18
        $this->assertTrue(Decimal::fromInteger(25)->sqrt()->equals(Decimal::fromInteger(5)));
19
    }
20
21
    public function testNearZeroSqrt()
22
    {
23
        $this->assertTrue(Decimal::fromString('0.01')->sqrt()->equals(Decimal::fromString('0.1')));
24
        $this->assertTrue(Decimal::fromString('0.0001')->sqrt()->equals(Decimal::fromString('0.01')));
25
    }
26
27
    /**
28
     * @expectedException \DomainException
29
     * @expectedExceptionMessage Decimal can't handle square roots of negative numbers (it's only for real numbers).
30
     */
31
    public function testFiniteNegativeSqrt()
32
    {
33
        Decimal::fromInteger(-1)->sqrt();
34
    }
35
36
    public function testPositiveInfiniteSqrt()
37
    {
38
        $pInf = Decimal::getPositiveInfinite();
39
        $this->assertTrue($pInf->sqrt()->equals($pInf));
40
    }
41
42
    /**
43
     * @expectedException \DomainException
44
     * @expectedExceptionMessage Decimal can't handle square roots of negative numbers (it's only for real numbers).
45
     */
46
    public function testNegativeInfiniteSqrt()
47
    {
48
        $nInf = Decimal::getNegativeInfinite();
49
        $nInf->sqrt();
50
    }
51
}
52