The `sortCellReferenceArray()` in `Coordinate` should have returned cells ordered by row, then by column... but instead sorted by column, then row.

Fixed that bug, using a slightly faster algorithm for the sort index than the simple fix would have used, and modified the tests that didn't have the correct expected result :-(
This commit is contained in:
MarkBaker 2022-04-28 17:18:37 +02:00
parent 1924f3c1d7
commit 0171709e7f
2 changed files with 40 additions and 40 deletions

View File

@ -353,9 +353,8 @@ abstract class Coordinate
}
$cellList = array_merge(...$cells);
$cellList = self::sortCellReferenceArray($cellList);
return $cellList;
return self::sortCellReferenceArray($cellList);
}
private static function processRangeSetOperators(array $operators, array $cells): array
@ -382,9 +381,10 @@ abstract class Coordinate
{
// Sort the result by column and row
$sortKeys = [];
foreach ($cellList as $coord) {
sscanf($coord, '%[A-Z]%d', $column, $row);
$sortKeys[sprintf('%3s%09d', $column, $row)] = $coord;
foreach ($cellList as $coordinate) {
sscanf($coordinate, '%[A-Z]%d', $column, $row);
$key = (--$row * 16384) + self::columnIndexFromString($column);
$sortKeys[$key] = $coordinate;
}
ksort($sortKeys);

View File

@ -12,10 +12,10 @@ return [
[
[
'B4',
'B5',
'B6',
'D4',
'B5',
'D5',
'B6',
'D6',
],
'B4:B6,D4:D6',
@ -28,13 +28,13 @@ return [
[
[
'B4',
'B5',
'B6',
'C4',
'C5',
'C6',
'D4',
'B5',
'C5',
'D5',
'B6',
'C6',
'D6',
],
'B4:D6',
@ -42,18 +42,18 @@ return [
[
[
'B4',
'B5',
'B6',
'C4',
'C5',
'C6',
'C7',
'D4',
'B5',
'C5',
'D5',
'D6',
'D7',
'E5',
'B6',
'C6',
'D6',
'E6',
'C7',
'D7',
'E7',
],
'B4:D6,C5:E7',
@ -61,8 +61,8 @@ return [
[
[
'C5',
'C6',
'D5',
'C6',
'D6',
],
'B4:D6 C5:E7',
@ -70,23 +70,23 @@ return [
[
[
'B2',
'B3',
'B4',
'C2',
'C3',
'C4',
'C5',
'D2',
'B3',
'C3',
'D3',
'D4',
'D5',
'D6',
'E3',
'B4',
'C4',
'D4',
'E4',
'E5',
'E6',
'F4',
'C5',
'D5',
'E5',
'F5',
'D6',
'E6',
'F6',
],
'B2:D4,C5:D5,E3:E5,D6:E6,F4:F6',
@ -94,23 +94,23 @@ return [
[
[
'B2',
'B3',
'B4',
'C2',
'C3',
'C4',
'C5',
'D2',
'B3',
'C3',
'D3',
'D4',
'D5',
'D6',
'E3',
'B4',
'C4',
'D4',
'E4',
'E5',
'E6',
'F4',
'C5',
'D5',
'E5',
'F5',
'D6',
'E6',
'F6',
],
'B2:D4,C3:E5,D4:F6',
@ -124,8 +124,8 @@ return [
[
[
'Z2',
'Z3',
'AA2',
'Z3',
'AA3',
],
'Z2:AA3',