From e539226d8e36ae65e14e757ff807b8c5de644fac Mon Sep 17 00:00:00 2001 From: George Byers Date: Fri, 23 Feb 2024 12:13:56 -0500 Subject: [PATCH 1/2] added test for blur detector --- app/tests/utils/blur-detector.spec.ts | 44 +++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 app/tests/utils/blur-detector.spec.ts diff --git a/app/tests/utils/blur-detector.spec.ts b/app/tests/utils/blur-detector.spec.ts new file mode 100644 index 00000000..045595e3 --- /dev/null +++ b/app/tests/utils/blur-detector.spec.ts @@ -0,0 +1,44 @@ +import { describe, it, expect, jest, beforeEach, afterEach } from '@jest/globals'; +import BlurryDetector, { BlurryDetectorReport } from '../../src/utils/blur-detector'; // Adjust the import path accordingly + +describe('./src/utils/blur-detector.ts', () => { + let blurryDetector: BlurryDetector; + + beforeEach(() => { + blurryDetector = new BlurryDetector(); // Using the default threshold of 300 + }); + + afterEach(() => { + jest.clearAllMocks(); + }); + + it('should detect a clear image', async () => { + // Mock computeLaplacianVariance to return a high variance indicating a clear image + blurryDetector.computeLaplacianVariance = jest.fn(() => { + return Promise.resolve(450) + }); + + const result: BlurryDetectorReport = await blurryDetector.analyse('path/to/clear/image.jpg'); + + expect(result).toEqual({ + imagePath: 'path/to/clear/image.jpg', + isBlurry: false, + score: 450, + }); + }); + + it('should detect a blurry image', async () => { + // Mock computeLaplacianVariance to return a low variance indicating a blurry image + blurryDetector.computeLaplacianVariance = jest.fn(() => { + return Promise.resolve(220) + }); + + const result: BlurryDetectorReport = await blurryDetector.analyse('path/to/blurry/image.jpg'); + + expect(result).toEqual({ + imagePath: 'path/to/blurry/image.jpg', + isBlurry: true, + score: 220, + }); + }); +}); From 9724c8d8bbb273ff9b5662635ec469460c3e3c0e Mon Sep 17 00:00:00 2001 From: George Byers Date: Fri, 23 Feb 2024 13:27:08 -0500 Subject: [PATCH 2/2] ran prettier --- app/tests/utils/blur-detector.spec.ts | 40 +++++++++++++++++++-------- 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/app/tests/utils/blur-detector.spec.ts b/app/tests/utils/blur-detector.spec.ts index 045595e3..ef044a08 100644 --- a/app/tests/utils/blur-detector.spec.ts +++ b/app/tests/utils/blur-detector.spec.ts @@ -1,7 +1,19 @@ -import { describe, it, expect, jest, beforeEach, afterEach } from '@jest/globals'; -import BlurryDetector, { BlurryDetectorReport } from '../../src/utils/blur-detector'; // Adjust the import path accordingly - -describe('./src/utils/blur-detector.ts', () => { +import { + afterEach, + beforeEach, + describe, + expect, + it, + jest, +} from "@jest/globals"; + +import BlurryDetector, { + BlurryDetectorReport, +} from "../../src/utils/blur-detector"; + +// Adjust the import path accordingly + +describe("./src/utils/blur-detector.ts", () => { let blurryDetector: BlurryDetector; beforeEach(() => { @@ -12,31 +24,35 @@ describe('./src/utils/blur-detector.ts', () => { jest.clearAllMocks(); }); - it('should detect a clear image', async () => { + it("should detect a clear image", async () => { // Mock computeLaplacianVariance to return a high variance indicating a clear image blurryDetector.computeLaplacianVariance = jest.fn(() => { - return Promise.resolve(450) + return Promise.resolve(450); }); - const result: BlurryDetectorReport = await blurryDetector.analyse('path/to/clear/image.jpg'); + const result: BlurryDetectorReport = await blurryDetector.analyse( + "path/to/clear/image.jpg" + ); expect(result).toEqual({ - imagePath: 'path/to/clear/image.jpg', + imagePath: "path/to/clear/image.jpg", isBlurry: false, score: 450, }); }); - it('should detect a blurry image', async () => { + it("should detect a blurry image", async () => { // Mock computeLaplacianVariance to return a low variance indicating a blurry image blurryDetector.computeLaplacianVariance = jest.fn(() => { - return Promise.resolve(220) + return Promise.resolve(220); }); - const result: BlurryDetectorReport = await blurryDetector.analyse('path/to/blurry/image.jpg'); + const result: BlurryDetectorReport = await blurryDetector.analyse( + "path/to/blurry/image.jpg" + ); expect(result).toEqual({ - imagePath: 'path/to/blurry/image.jpg', + imagePath: "path/to/blurry/image.jpg", isBlurry: true, score: 220, });