| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- <?php
- declare(strict_types=1);
-
- use PHPUnit\Framework\TestCase;
-
- require_once __DIR__ . '/../../php/markdown.php';
- require_once __DIR__ . '/../../php/spreadsheet.php';
-
- final class CellAddressRangeTests extends TestCase {
- public function test_iterator() {
- $grid = new SpreadsheetGrid(3, 4);
- $range = new CellAddressRange(new CellAddress(0, 0), new CellAddress(2, 3));
- $visited = [];
- $sanity = 100;
- foreach ($range->cellsIn($grid) as $address_string => $cell) {
- array_push($visited, $address_string);
- if ($sanity-- < 0) break;
- }
- $actual = implode(',', $visited);
- $expected = 'A1,A2,A3,A4,B1,B2,B3,B4,C1,C2,C3,C4';
- $this->assertSame($expected, $actual);
- }
-
- public function test_iterator_column() {
- $grid = new SpreadsheetGrid(3, 4);
- $range = new CellAddressRange(new CellAddress(1, -1), new CellAddress(2, -1));
- $visited = [];
- $sanity = 100;
- foreach ($range->cellsIn($grid) as $address_string => $cell) {
- array_push($visited, $address_string);
- if ($sanity-- < 0) break;
- }
- $actual = implode(',', $visited);
- $expected = 'B1,B2,B3,B4,C1,C2,C3,C4';
- $this->assertSame($expected, $actual);
- }
-
- public function test_iterator_beyondBounds() {
- $grid = new SpreadsheetGrid(3, 4);
- $range = new CellAddressRange(new CellAddress(0, 1), new CellAddress(9, 9));
- $visited = [];
- $sanity = 100;
- foreach ($range->cellsIn($grid) as $address_string => $cell) {
- array_push($visited, $address_string);
- if ($sanity-- < 0) break;
- }
- $actual = implode(',', $visited);
- $expected = 'A2,A3,A4,B2,B3,B4,C2,C3,C4';
- $this->assertSame($expected, $actual);
- }
-
- public function test_iterator_outOfBounds() {
- $grid = new SpreadsheetGrid(3, 4);
- $range = new CellAddressRange(new CellAddress(5, 0), new CellAddress(5, 9));
- $visited = [];
- $sanity = 100;
- foreach ($range->cellsIn($grid) as $address_string => $cell) {
- array_push($visited, $address_string);
- if ($sanity-- < 0) break;
- }
- $actual = implode(',', $visited);
- $expected = '';
- $this->assertSame($expected, $actual);
- }
- }
- ?>
|