|
1 | 1 | import * as path from "path";
|
2 |
| -import { ImageProcessor } from "./image-processor.class"; |
3 |
| -import { ImageReader } from "./image-reader.class"; |
4 |
| -import { scaleImage } from "./scale-image.function"; |
| 2 | +import {ImageReader} from "./image-reader.class"; |
| 3 | +import {scaleImage} from "./scale-image.function"; |
| 4 | +import {fromImageWithoutAlphaChannel} from "./image-processor.class"; |
5 | 5 |
|
6 | 6 | describe("scaleImage", () => {
|
7 |
| - it.each([[0.5], [1.5]])("should scale an image correctly by factor %f", async (scaleFactor) => { |
8 |
| - // GIVEN |
9 |
| - const imageLoader = new ImageReader(); |
10 |
| - const pathToinput = path.resolve(__dirname, "./__mocks__/mouse.png"); |
11 |
| - const inputImage = await imageLoader.load(pathToinput); |
12 |
| - const inputMat = await ImageProcessor.fromImageWithoutAlphaChannel(inputImage); |
13 |
| - const expectedWidth = Math.floor(inputMat.cols * scaleFactor); |
14 |
| - const expectedHeight = Math.floor(inputMat.rows * scaleFactor); |
| 7 | + it.each([[0.5], [1.5]])("should scale an image correctly by factor %f", async (scaleFactor) => { |
| 8 | + // GIVEN |
| 9 | + const imageLoader = new ImageReader(); |
| 10 | + const pathToinput = path.resolve(__dirname, "./__mocks__/mouse.png"); |
| 11 | + const inputImage = await imageLoader.load(pathToinput); |
| 12 | + const inputMat = await fromImageWithoutAlphaChannel(inputImage); |
| 13 | + const expectedWidth = Math.floor(inputMat.cols * scaleFactor); |
| 14 | + const expectedHeight = Math.floor(inputMat.rows * scaleFactor); |
15 | 15 |
|
16 |
| - // WHEN |
17 |
| - const result = await scaleImage(inputMat, scaleFactor); |
| 16 | + // WHEN |
| 17 | + const result = await scaleImage(inputMat, scaleFactor); |
18 | 18 |
|
19 |
| - // THEN |
20 |
| - expect(result.rows).toBe(expectedHeight); |
21 |
| - expect(result.cols).toBe(expectedWidth); |
22 |
| - }); |
| 19 | + // THEN |
| 20 | + expect(result.rows).toBe(expectedHeight); |
| 21 | + expect(result.cols).toBe(expectedWidth); |
| 22 | + }); |
23 | 23 |
|
24 |
| - it.each([[0], [-0.25]])("should keep scale if factor <= 0: Scale %f", async (scaleFactor) => { |
25 |
| - // GIVEN |
26 |
| - const imageLoader = new ImageReader(); |
27 |
| - const pathToinput = path.resolve(__dirname, "./__mocks__/mouse.png"); |
28 |
| - const inputImage = await imageLoader.load(pathToinput); |
29 |
| - const inputMat = await ImageProcessor.fromImageWithoutAlphaChannel(inputImage); |
30 |
| - const expectedWidth = inputMat.cols; |
31 |
| - const expectedHeight = inputMat.rows; |
| 24 | + it.each([[0], [-0.25]])("should keep scale if factor <= 0: Scale %f", async (scaleFactor) => { |
| 25 | + // GIVEN |
| 26 | + const imageLoader = new ImageReader(); |
| 27 | + const pathToinput = path.resolve(__dirname, "./__mocks__/mouse.png"); |
| 28 | + const inputImage = await imageLoader.load(pathToinput); |
| 29 | + const inputMat = await fromImageWithoutAlphaChannel(inputImage); |
| 30 | + const expectedWidth = inputMat.cols; |
| 31 | + const expectedHeight = inputMat.rows; |
32 | 32 |
|
33 |
| - // WHEN |
34 |
| - const result = await scaleImage(inputMat, scaleFactor); |
| 33 | + // WHEN |
| 34 | + const result = await scaleImage(inputMat, scaleFactor); |
35 | 35 |
|
36 |
| - // THEN |
37 |
| - expect(result.rows).toBe(expectedHeight); |
38 |
| - expect(result.cols).toBe(expectedWidth); |
39 |
| - }); |
| 36 | + // THEN |
| 37 | + expect(result.rows).toBe(expectedHeight); |
| 38 | + expect(result.cols).toBe(expectedWidth); |
| 39 | + }); |
40 | 40 | });
|
0 commit comments