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

DecimalTanTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 7
Bugs 4 Features 1
Metric Value
wmc 3
c 7
b 4
f 1
lcom 0
cbo 3
dl 0
loc 35
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A tanProvider() 0 8 1
A testSimple() 0 9 1
A testTanPiTwoDiv() 0 5 1
1
<?php
2
3
use \Litipk\BigNumbers\Decimal as Decimal;
4
use \Litipk\BigNumbers\DecimalConstants as DecimalConstants;
5
6
/**
7
 * @group tan
8
 */
9
class DecimalTanTest extends PHPUnit_Framework_TestCase
10
{
11
    public function tanProvider() {
12
        // Some values providede by mathematica
13
        return [
14
            ['1', '1.55740772465490', 14],
15
            ['123.123', '0.68543903342472368', 17],
16
            ['15000000000', '-0.95779983511717825557', 20]
17
        ];
18
    }
19
20
    /**
21
     * @dataProvider tanProvider
22
     */
23
    public function testSimple($nr, $answer, $digits)
24
    {
25
        $x = Decimal::fromString($nr);
26
        $tanX = $x->tan($digits);
27
        $this->assertTrue(
28
            Decimal::fromString($answer)->equals($tanX),
29
            'tan('.$nr.') must be equal to '.$answer.', but was '.$tanX
30
        );
31
    }
32
33
    /**
34
     * @expectedException \DomainException
35
     * @expectedExceptionMessage The tangent of this 'angle' is undefined.
36
     */
37
    public function testTanPiTwoDiv()
38
    {
39
        $PiDividedByTwo = DecimalConstants::PI()->div(Decimal::fromInteger(2));
40
        $PiDividedByTwo->tan();
41
    }
42
43
}
44