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

DecimalTanTest::testSimple()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 1
Metric Value
c 2
b 1
f 1
dl 0
loc 9
rs 9.6666
cc 1
eloc 6
nc 1
nop 3
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