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

DecimalLog10Test   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

5 Methods

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