Failed Conditions
Push — master ( 5868f8...b1beaf )
by
unknown
21:24 queued 09:39
created

AssociativityTest::testAssociativity()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
dl 0
loc 8
rs 10
c 1
b 0
f 0
cc 2
nc 2
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpOffice\PhpSpreadsheetTests\Calculation;
6
7
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
8
use PHPUnit\Framework\Attributes\DataProvider;
9
use PHPUnit\Framework\TestCase;
10
11
class AssociativityTest extends TestCase
12
{
13
    #[DataProvider('providerAssociativity')]
14
    public function testAssociativity(mixed $expectedResult, string $formula): void
15
    {
16
        $result = Calculation::getInstance()->calculateFormula($formula);
17
        if (is_float($expectedResult)) {
18
            self::assertEqualsWithDelta($expectedResult, $result, 1E-8);
19
        } else {
20
            self::assertSame($expectedResult, $result);
21
        }
22
    }
23
24
    public static function providerAssociativity(): array
25
    {
26
        return [
27
            'Excel exponentiation is left-associative unlike Php and pure math' => [4096, '=4^2^3'],
28
            'multiplication' => [24, '=4*2*3'],
29
            'division' => [1, '=8/4/2'],
30
            'addition' => [9, '=4+2+3'],
31
            'subtraction' => [-1, '=4-2-3'],
32
            'concatenation' => ['abc', '="a"&"b"&"c"'],
33
        ];
34
    }
35
}
36