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

DecimalConstantsTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 3
Bugs 0 Features 2
Metric Value
wmc 4
c 3
b 0
f 2
lcom 0
cbo 3
dl 0
loc 53
rs 10

4 Methods

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