DecimalSqrtTest::testNearZeroSqrt()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
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
use PHPUnit\Framework\TestCase;
5
6
date_default_timezone_set('UTC');
7
8
class DecimalSqrtTest extends TestCase
9
{
10
    public function testIntegerSqrt()
11
    {
12
        $this->assertTrue(Decimal::fromInteger(0)->sqrt()->equals(Decimal::fromInteger(0)));
13
        $this->assertTrue(Decimal::fromInteger(1)->sqrt()->equals(Decimal::fromInteger(1)));
14
        $this->assertTrue(Decimal::fromInteger(4)->sqrt()->equals(Decimal::fromInteger(2)));
15
        $this->assertTrue(Decimal::fromInteger(9)->sqrt()->equals(Decimal::fromInteger(3)));
16
        $this->assertTrue(Decimal::fromInteger(16)->sqrt()->equals(Decimal::fromInteger(4)));
17
        $this->assertTrue(Decimal::fromInteger(25)->sqrt()->equals(Decimal::fromInteger(5)));
18
    }
19
20
    public function testNearZeroSqrt()
21
    {
22
        $this->assertTrue(Decimal::fromString('0.01')->sqrt()->equals(Decimal::fromString('0.1')));
23
        $this->assertTrue(Decimal::fromString('0.0001')->sqrt()->equals(Decimal::fromString('0.01')));
24
    }
25
26
    /**
27
     * @expectedException \DomainException
28
     * @expectedExceptionMessage Decimal can't handle square roots of negative numbers (it's only for real numbers).
29
     */
30
    public function testFiniteNegativeSqrt()
31
    {
32
        Decimal::fromInteger(-1)->sqrt();
33
    }
34
}
35