( algorithm: AlgorithmRunner, algorithmName: string )
| 207 | * Test that algorithm handles edge cases |
| 208 | */ |
| 209 | export function testAlgorithmEdgeCases( |
| 210 | algorithm: AlgorithmRunner, |
| 211 | algorithmName: string |
| 212 | ): void { |
| 213 | const palette = testPalettes.blackAndWhite as [number, number, number][]; |
| 214 | const baseParams = { |
| 215 | pattern: 0, |
| 216 | threshold: 128, |
| 217 | invert: false, |
| 218 | serpentine: false, |
| 219 | isErrorDiffusion: false, |
| 220 | palette |
| 221 | }; |
| 222 | |
| 223 | // Test with 1x1 image |
| 224 | const tiny = createTestImageData(1, 1, [128, 128, 128, 255]); |
| 225 | expect(() => algorithm({ srcData: tiny.data, width: tiny.width, height: tiny.height, params: baseParams })).not.toThrow(); |
| 226 | |
| 227 | // Test with minimal palette (2 colors) |
| 228 | const small = createTestImageData(4, 4, [128, 128, 128, 255]); |
| 229 | expect(() => algorithm({ srcData: small.data, width: small.width, height: small.height, params: baseParams })).not.toThrow(); |
| 230 | |
| 231 | // Test with all-black image |
| 232 | const black = createTestImageData(8, 8, [0, 0, 0, 255]); |
| 233 | const blackResultData = algorithm({ srcData: black.data, width: black.width, height: black.height, params: baseParams }); |
| 234 | const blackResult = blackResultData instanceof ImageData ? blackResultData : new ImageData(new Uint8ClampedArray(blackResultData), black.width, black.height); |
| 235 | expectOnlyPaletteColors(blackResult, palette); |
| 236 | |
| 237 | // Test with all-white image |
| 238 | const white = createTestImageData(8, 8, [255, 255, 255, 255]); |
| 239 | const whiteResultData = algorithm({ srcData: white.data, width: white.width, height: white.height, params: baseParams }); |
| 240 | const whiteResult = whiteResultData instanceof ImageData ? whiteResultData : new ImageData(new Uint8ClampedArray(whiteResultData), white.width, white.height); |
| 241 | expectOnlyPaletteColors(whiteResult, palette); |
| 242 | } |
| 243 | |
| 244 | /** |
| 245 | * Benchmark suite for all algorithms |
nothing calls this directly
no test coverage detected