DecimalConstantsTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
c 0
b 0
f 0
lcom 0
cbo 3
dl 0
loc 49
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testFiniteAbs() 0 22 1
A testE() 0 14 1
A testNegativeParamsOnE() 0 4 1
1
<?php
2
3
use Litipk\BigNumbers\DecimalConstants as DecimalConstants;
4
use Litipk\BigNumbers\Decimal as Decimal;
5
use PHPUnit\Framework\TestCase;
6
7
date_default_timezone_set('UTC');
8
9
class DecimalConstantsTest extends TestCase
10
{
11
    public function testFiniteAbs()
12
    {
13
        $this->assertTrue(DecimalConstants::pi()->equals(
14
            Decimal::fromString("3.14159265358979323846264338327950")
15
        ));
16
17
        $this->assertTrue(DecimalConstants::eulerMascheroni()->equals(
18
            Decimal::fromString("0.57721566490153286060651209008240")
19
        ));
20
21
        $this->assertTrue(DecimalConstants::goldenRatio()->equals(
22
            Decimal::fromString("1.61803398874989484820458683436564")
23
        ));
24
25
        $this->assertTrue(DecimalConstants::silverRatio()->equals(
26
            Decimal::fromString("2.41421356237309504880168872420970")
27
        ));
28
29
        $this->assertTrue(DecimalConstants::lightSpeed()->equals(
30
            Decimal::fromInteger(299792458)
31
        ));
32
    }
33
34
    public function testE()
35
    {
36
        $this->assertTrue(DecimalConstants::e()->equals(
37
            Decimal::fromString("2.71828182845904523536028747135266")
38
        ));
39
40
        $this->assertTrue(DecimalConstants::e(32)->equals(
41
            Decimal::fromString("2.71828182845904523536028747135266")
42
        ));
43
44
        $this->assertTrue(DecimalConstants::e(16)->equals(
45
            Decimal::fromString("2.7182818284590452")
46
        ));
47
    }
48
49
    /**
50
     * @expectedException \InvalidArgumentException
51
     * @expectedExceptionMessage $scale must be positive.
52
     */
53
    public function testNegativeParamsOnE()
54
    {
55
        DecimalConstants::e(-3);
56
    }
57
}
58