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