Completed
Push — master ( b9f967...7a222d )
by Andreu
9s
created

DecimalExpTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 2
c 2
b 0
f 1
lcom 0
cbo 2
dl 0
loc 34
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A expProvider() 0 17 1
A testSimple() 0 10 1
1
<?php
2
3
use Litipk\BigNumbers\Decimal as Decimal;
4
5
/**
6
 * @group cos
7
 */
8
class DecimalExpTest extends PHPUnit_Framework_TestCase
9
{
10
    public function expProvider() {
11
        // Some values provided by Mathematica
12
        return [
13
            ['0', '1', 0],
14
            ['0', '1', 1],
15
            ['0', '1', 2],
16
17
            ['1', '3', 0],
18
            ['1', '2.7', 1],
19
            ['1', '2.72', 2],
20
            ['1', '2.718', 3],
21
22
            ['-1', '0', 0],
23
            ['-1', '0.4', 1],
24
            ['-1', '0.37', 2]
25
        ];
26
    }
27
28
    /**
29
     * @dataProvider expProvider
30
     */
31
    public function testSimple($nr, $answer, $digits)
32
    {
33
        $x = Decimal::fromString($nr);
34
        $expX = $x->exp((int)$digits);
35
36
        $this->assertTrue(
37
            Decimal::fromString($answer)->equals($expX),
38
            "The answer must be " . $answer . ", but was " . $expX
39
        );
40
    }
41
}
42