DecimalLog10Test   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
c 0
b 0
f 0
lcom 1
cbo 2
dl 0
loc 44
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testZeroLog10() 0 5 1
A testNegativeLog10() 0 4 1
A testBigNumbersLog10() 0 7 1
A testLittleNumbersLog10() 0 7 1
A testMediumNumbersLog10() 0 5 1
1
<?php
2
3
use Litipk\BigNumbers\Decimal as Decimal;
4
use PHPUnit\Framework\TestCase;
5
6
date_default_timezone_set('UTC');
7
8
class DecimalLog10Test extends TestCase
9
{
10
    /**
11
     * @expectedException \DomainException
12
     * @expectedExceptionMessage Decimal can't represent infinite numbers.
13
     */
14
    public function testZeroLog10()
15
    {
16
        $zero = Decimal::fromInteger(0);
17
        $zero->log10();
18
    }
19
20
    
21
    /**
22
     * @expectedException \DomainException
23
     * @expectedExceptionMessage Decimal can't handle logarithms of negative numbers (it's only for real numbers).
24
     */
25
    public function testNegativeLog10()
26
    {
27
        Decimal::fromInteger(-1)->log10();
28
    }
29
30
    public function testBigNumbersLog10()
31
    {
32
        $bignumber = Decimal::fromString(bcpow('10', '2417'));
33
        $pow = Decimal::fromInteger(2417);
34
35
        $this->assertTrue($bignumber->log10()->equals($pow));
36
    }
37
38
    public function testLittleNumbersLog10()
39
    {
40
        $littlenumber = Decimal::fromString(bcpow('10', '-2417', 2417));
41
        $pow = Decimal::fromInteger(-2417);
42
43
        $this->assertTrue($littlenumber->log10()->equals($pow));
44
    }
45
46
    public function testMediumNumbersLog10()
47
    {
48
        $this->assertTrue(Decimal::fromInteger(75)->log10(5)->equals(Decimal::fromString('1.87506')));
49
        $this->assertTrue(Decimal::fromInteger(49)->log10(7)->equals(Decimal::fromString('1.6901961')));
50
    }
51
}
52