-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from navapbc/george/test-blur-detector
- Loading branch information
Showing
1 changed file
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
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(() => { | ||
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, | ||
}); | ||
}); | ||
}); |