|
| 1 | +import { Image } from "../../image.class"; |
| 2 | +import { Point } from "../../point.class"; |
| 3 | +import JimpImageProcessor from "./jimp-image-processor.class"; |
| 4 | + |
| 5 | +const imageWidth = 10; |
| 6 | +const imageHeight = 20; |
| 7 | + |
| 8 | +describe("JimpImageProcessor", () => { |
| 9 | + it.each([[new Point(-1, 5)], [new Point(imageWidth + 5, 5)]])( |
| 10 | + `should reject on out of bounds x coordinates`, |
| 11 | + async (outOfBoundsPoint: Point) => { |
| 12 | + // GIVEN |
| 13 | + const inputImage = new Image( |
| 14 | + imageWidth, |
| 15 | + imageHeight, |
| 16 | + Buffer.from([0, 0, 0]), |
| 17 | + 3, |
| 18 | + "input_image", |
| 19 | + 4, |
| 20 | + 4 |
| 21 | + ); |
| 22 | + const SUT = new JimpImageProcessor(); |
| 23 | + |
| 24 | + // WHEN |
| 25 | + const result = SUT.colorAt(inputImage, outOfBoundsPoint); |
| 26 | + |
| 27 | + // THEN |
| 28 | + await expect(result).rejects.toBe( |
| 29 | + `Query location out of bounds. Should be in range 0 <= x < image.width, is ${outOfBoundsPoint.x}` |
| 30 | + ); |
| 31 | + } |
| 32 | + ); |
| 33 | + |
| 34 | + it.each([[new Point(5, -1)], [new Point(5, imageHeight + 10)]])( |
| 35 | + `should reject on out of bounds y coordinates`, |
| 36 | + async (outOfBoundsPoint: Point) => { |
| 37 | + // GIVEN |
| 38 | + const imageWidth = 10; |
| 39 | + const imageHeight = 20; |
| 40 | + const inputImage = new Image( |
| 41 | + imageWidth, |
| 42 | + imageHeight, |
| 43 | + Buffer.from([0, 0, 0]), |
| 44 | + 3, |
| 45 | + "input_image", |
| 46 | + 4, |
| 47 | + 4 |
| 48 | + ); |
| 49 | + const SUT = new JimpImageProcessor(); |
| 50 | + |
| 51 | + // WHEN |
| 52 | + const result = SUT.colorAt(inputImage, outOfBoundsPoint); |
| 53 | + |
| 54 | + // THEN |
| 55 | + await expect(result).rejects.toBe( |
| 56 | + `Query location out of bounds. Should be in range 0 <= y < image.height, is ${outOfBoundsPoint.y}` |
| 57 | + ); |
| 58 | + } |
| 59 | + ); |
| 60 | +}); |
0 commit comments