DecimalExpTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
c 0
b 0
f 0
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
use PHPUnit\Framework\TestCase;
5
6
/**
7
 * @group cos
8
 */
9
class DecimalExpTest extends TestCase
10
{
11
    public function expProvider() {
12
        // Some values provided by Mathematica
13
        return [
14
            ['0', '1', 0],
15
            ['0', '1', 1],
16
            ['0', '1', 2],
17
18
            ['1', '3', 0],
19
            ['1', '2.7', 1],
20
            ['1', '2.72', 2],
21
            ['1', '2.718', 3],
22
23
            ['-1', '0', 0],
24
            ['-1', '0.4', 1],
25
            ['-1', '0.37', 2]
26
        ];
27
    }
28
29
    /**
30
     * @dataProvider expProvider
31
     */
32
    public function testSimple($nr, $answer, $digits)
33
    {
34
        $x = Decimal::fromString($nr);
35
        $expX = $x->exp((int)$digits);
36
37
        $this->assertTrue(
38
            Decimal::fromString($answer)->equals($expX),
39
            "The answer must be " . $answer . ", but was " . $expX
40
        );
41
    }
42
}
43