class CellAddressRangeTests extends BaseTest { test_iterator() { const grid = new SpreadsheetGrid(3, 4); let range = new CellAddressRange(new CellAddress(0, 0), new CellAddress(2, 3)); var visited = []; var sanity = 100; for (const address of range.cellsIn(grid)) { visited.push(address.name); if (sanity-- < 0) break; } const actual = visited.join(','); const expected = 'A1,A2,A3,A4,B1,B2,B3,B4,C1,C2,C3,C4'; this.assertEqual(expected, actual); } test_iterator_column() { const grid = new SpreadsheetGrid(3, 4); let range = new CellAddressRange(new CellAddress(1, -1), new CellAddress(2, -1)); var visited = []; var sanity = 100; for (const address of range.cellsIn(grid)) { visited.push(address.name); if (sanity-- < 0) break; } const actual = visited.join(','); const expected = 'B1,B2,B3,B4,C1,C2,C3,C4'; this.assertEqual(expected, actual); } test_iterator_beyondBounds() { const grid = new SpreadsheetGrid(3, 4); let range = new CellAddressRange(new CellAddress(0, 1), new CellAddress(9, 9)); var visited = []; var sanity = 100; for (const address of range.cellsIn(grid)) { visited.push(address.name); if (sanity-- < 0) break; } const actual = visited.join(','); const expected = 'A2,A3,A4,B2,B3,B4,C2,C3,C4'; this.assertEqual(expected, actual); } test_iterator_outOfBounds() { const grid = new SpreadsheetGrid(3, 4); let range = new CellAddressRange(new CellAddress(5, 0), new CellAddress(5, 9)); var visited = []; var sanity = 100; for (const address of range.cellsIn(grid)) { visited.push(address.name); if (sanity-- < 0) break; } const actual = visited.join(','); const expected = ''; this.assertEqual(expected, actual); } }