diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md new file mode 100644 index 000000000..d4cee052a --- /dev/null +++ b/.github/copilot-instructions.md @@ -0,0 +1,8 @@ +# GitHub Copilot Instructions + +## Testing + +- Use the `node:test` framework and `assert` for assertions. +- When generating tests, add them to the existing test file for the relevant module. +- Use a new describe block if the function being tested does not already have one. +- Follow existing conventions for test names, structure, and assertions. diff --git a/src/commands/tileindex-validate/__test__/tileindex.validate.test.ts b/src/commands/tileindex-validate/__test__/tileindex.validate.test.ts index 550632b59..86849131c 100644 --- a/src/commands/tileindex-validate/__test__/tileindex.validate.test.ts +++ b/src/commands/tileindex-validate/__test__/tileindex.validate.test.ts @@ -16,6 +16,7 @@ import { createTiff, Url } from '../../common.ts'; import { commandTileIndexValidate, extractTiffLocations, + getSize, getTileName, GridSizeFromString, groupByTileName, @@ -28,6 +29,32 @@ import { FakeCogTiff } from './tileindex.validate.data.ts'; /* eslint-disable @typescript-eslint/no-explicit-any */ +describe('getSize', () => { + it('should return correct width and height for positive extent', () => { + const extent: [number, number, number, number] = [10, 20, 30, 40]; + const size = getSize(extent); + assert.deepEqual(size, { width: 20, height: 20 }); + }); + + it('should return zero width and height for zero-size extent', () => { + const extent: [number, number, number, number] = [5, 5, 5, 5]; + const size = getSize(extent); + assert.deepEqual(size, { width: 0, height: 0 }); + }); + + it('should handle negative coordinates correctly', () => { + const extent: [number, number, number, number] = [-10, -20, 10, 20]; + const size = getSize(extent); + assert.deepEqual(size, { width: 20, height: 40 }); + }); + + it('should handle reversed coordinates (min > max)', () => { + const extent: [number, number, number, number] = [30, 40, 10, 20]; + const size = getSize(extent); + assert.deepEqual(size, { width: -20, height: -20 }); + }); +}); + function convertTileName(fileName: string, gridSize: GridSize): string | null { const mapTileIndex = MapSheet.getMapTileIndex(fileName); if (mapTileIndex == null) return null;