Total Complexity | 8 |
Total Lines | 109 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
14 | class ImSumTest extends TestCase |
||
15 | { |
||
16 | const COMPLEX_PRECISION = 1E-12; |
||
17 | |||
18 | /** |
||
19 | * @var ComplexAssert |
||
20 | */ |
||
21 | private $complexAssert; |
||
22 | |||
23 | protected function setUp(): void |
||
27 | } |
||
28 | |||
29 | /** |
||
30 | * @dataProvider providerIMSUM |
||
31 | * |
||
32 | * @param mixed $expectedResult |
||
33 | */ |
||
34 | public function testDirectCallToIMSUM($expectedResult, ...$args): void |
||
35 | { |
||
36 | /** @scrutinizer ignore-call */ |
||
37 | $result = ComplexOperations::IMSUM(...$args); |
||
38 | self::assertTrue( |
||
39 | $this->complexAssert->assertComplexEquals($expectedResult, $result, self::COMPLEX_PRECISION), |
||
40 | $this->complexAssert->getErrorMessage() |
||
41 | ); |
||
42 | } |
||
43 | |||
44 | private function trimIfQuoted(string $value): string |
||
45 | { |
||
46 | return trim($value, '"'); |
||
47 | } |
||
48 | |||
49 | /** |
||
50 | * @dataProvider providerIMSUM |
||
51 | * |
||
52 | * @param mixed $expectedResult |
||
53 | */ |
||
54 | public function testIMSUMAsFormula($expectedResult, ...$args): void |
||
55 | { |
||
56 | $arguments = new FormulaArguments(...$args); |
||
57 | |||
58 | $calculation = Calculation::getInstance(); |
||
59 | $formula = "=IMSUM({$arguments})"; |
||
60 | |||
61 | $result = $calculation->_calculateFormulaValue($formula); |
||
62 | self::assertTrue( |
||
63 | $this->complexAssert->assertComplexEquals($expectedResult, $this->trimIfQuoted((string) $result), self::COMPLEX_PRECISION), |
||
64 | $this->complexAssert->getErrorMessage() |
||
65 | ); |
||
66 | } |
||
67 | |||
68 | /** |
||
69 | * @dataProvider providerIMSUM |
||
70 | * |
||
71 | * @param mixed $expectedResult |
||
72 | */ |
||
73 | public function testIMSUMInWorksheet($expectedResult, ...$args): void |
||
74 | { |
||
75 | $arguments = new FormulaArguments(...$args); |
||
76 | |||
77 | $spreadsheet = new Spreadsheet(); |
||
78 | $worksheet = $spreadsheet->getActiveSheet(); |
||
79 | $argumentCells = $arguments->populateWorksheet($worksheet); |
||
80 | $formula = "=IMSUM({$argumentCells})"; |
||
81 | |||
82 | $result = $worksheet->setCellValue('A1', $formula) |
||
83 | ->getCell('A1') |
||
84 | ->getCalculatedValue(); |
||
85 | self::assertTrue( |
||
86 | $this->complexAssert->assertComplexEquals($expectedResult, $result, self::COMPLEX_PRECISION), |
||
87 | $this->complexAssert->getErrorMessage() |
||
88 | ); |
||
89 | |||
90 | $spreadsheet->disconnectWorksheets(); |
||
91 | } |
||
92 | |||
93 | public function providerIMSUM(): array |
||
94 | { |
||
95 | return require 'tests/data/Calculation/Engineering/IMSUM.php'; |
||
96 | } |
||
97 | |||
98 | /** |
||
99 | * @dataProvider providerUnhappyIMSUM |
||
100 | */ |
||
101 | public function testIMSUMUnhappyPath(string $expectedException, ...$args): void |
||
117 | } |
||
118 | |||
119 | public function providerUnhappyIMSUM(): array |
||
120 | { |
||
123 | ]; |
||
124 | } |
||
125 | } |
||
126 |