Skip to content

Commit

Permalink
Handle the use-case of step = 0; and tests for exception handling for…
Browse files Browse the repository at this point in the history
… invalid arguments
  • Loading branch information
MarkBaker committed Jan 29, 2022
1 parent ea5a390 commit 1df4d4c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/PhpSpreadsheet/Calculation/MathTrig/MatrixFunctions.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ public static function sequence($rows = 1, $columns = 1, $start = 1, $step = 1)
return $e->getMessage();
}

if ($step === 0) {
return array_chunk(
array_fill(0, $rows * $columns, $start),
$columns
);
}

return array_chunk(
range($start, $start + (($rows * $columns - 1) * $step), $step),
$columns
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ class SequenceTest extends AllSetupTeardown
* @dataProvider providerSEQUENCE
*
* @param mixed[] $arguments
* @param mixed[] $expectedResult
* @param mixed[]|string $expectedResult
*/
public function testSEQUENCE(array $arguments, array $expectedResult): void
public function testSEQUENCE(array $arguments, $expectedResult): void
{
$result = MathTrig\MatrixFunctions::sequence(...$arguments);
self::assertEquals($expectedResult, $result);
Expand Down
11 changes: 11 additions & 0 deletions tests/data/Calculation/MathTrig/SEQUENCE.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,15 @@
[-5, -7.5, -10],
],
],
[
[2, 2, 1, 0],
[
[1, 1],
[1, 1],
],
],
[
[2, 2, 'A', 0],
'#VALUE!',
],
];

0 comments on commit 1df4d4c

Please sign in to comment.