|
| 1 | +import { mockPartial } from "sneer"; |
| 2 | +import { Image } from "../../image.class"; |
| 3 | +import { MatchRequest } from "../../match-request.class"; |
| 4 | +import { Region } from "../../region.class"; |
| 5 | +import { determineScaledSearchRegion } from "./determine-searchregion.function"; |
| 6 | + |
| 7 | +describe("determineSearchRegion", () => { |
| 8 | + it("should return a search region adopted to pixel density", () => { |
| 9 | + // GIVEN |
| 10 | + const imageMock = mockPartial<Image>({ |
| 11 | + pixelDensity: { |
| 12 | + scaleX: 1.5, |
| 13 | + scaleY: 2.0 |
| 14 | + } |
| 15 | + }); |
| 16 | + const needlePath = "/path/to/needle"; |
| 17 | + const inputSearchRegion = new Region(0, 0, 100, 100); |
| 18 | + const expectedSearchRegion = new Region(0, 0, 150, 200); |
| 19 | + |
| 20 | + const matchRequest = new MatchRequest( |
| 21 | + imageMock, |
| 22 | + needlePath, |
| 23 | + inputSearchRegion, |
| 24 | + 0.99 |
| 25 | + ); |
| 26 | + |
| 27 | + // WHEN |
| 28 | + const result = determineScaledSearchRegion(matchRequest); |
| 29 | + |
| 30 | + // THEN |
| 31 | + expect(result).toEqual(expectedSearchRegion); |
| 32 | + }); |
| 33 | + |
| 34 | + it.each([[0, 1], [1, 0]])("should not adjust searchregion for factor 0: scaleX: %i scaleY: %i", |
| 35 | + (scaleX: number, scaleY: number) => { |
| 36 | + // GIVEN |
| 37 | + const imageMock = mockPartial<Image>({ |
| 38 | + pixelDensity: { |
| 39 | + scaleX, |
| 40 | + scaleY |
| 41 | + } |
| 42 | + }); |
| 43 | + const needlePath = "/path/to/needle"; |
| 44 | + const inputSearchRegion = new Region(0, 0, 100, 100); |
| 45 | + const expectedSearchRegion = new Region(0, 0, 100, 100); |
| 46 | + |
| 47 | + const matchRequest = new MatchRequest( |
| 48 | + imageMock, |
| 49 | + needlePath, |
| 50 | + inputSearchRegion, |
| 51 | + 0.99 |
| 52 | + ); |
| 53 | + |
| 54 | + // WHEN |
| 55 | + const result = determineScaledSearchRegion(matchRequest); |
| 56 | + |
| 57 | + // THEN |
| 58 | + expect(result).toEqual(expectedSearchRegion); |
| 59 | + }); |
| 60 | +}); |
0 commit comments