-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added test coverage for Gaussian and Median blur
- Loading branch information
1 parent
d72872a
commit 8ad1886
Showing
4 changed files
with
112 additions
and
3 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
68 changes: 68 additions & 0 deletions
68
imagelab_electron/tests/unit/blurring/GaussianBlur.test.js
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,68 @@ | ||
const GaussianBlur = require('../../../src/operator/blurring/GaussianBlur') | ||
const opencvMock = require('../opencv-mocks/blurring.mock'); | ||
|
||
describe('GaussianBlur Operator', () => { | ||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should process Gaussian blur function with given parameters', () => { | ||
const operator = new GaussianBlur('type', 'id'); | ||
operator.cv2 = opencvMock.cv2; | ||
|
||
// Set private variables using setParams | ||
operator.setParams('widthSize', 3); | ||
operator.setParams('heightSize', 3); | ||
|
||
const imageMock = 'mockImageData'; | ||
|
||
// Mock behavior for cv2 functions | ||
opencvMock.cv2.Size.mockReturnValue({ width: 3, height: 3 }); | ||
|
||
operator.compute(imageMock); | ||
|
||
// Assertions | ||
expect(opencvMock.cv2.Mat).toHaveBeenCalledTimes(1); | ||
expect(opencvMock.cv2.Size).toHaveBeenCalledWith(3, 3); | ||
expect(opencvMock.cv2.GaussianBlur).toHaveBeenCalledWith( | ||
imageMock, | ||
{}, | ||
opencvMock.cv2.Size(), | ||
0, | ||
0, | ||
opencvMock.cv2.BORDER_DEFAULT | ||
); | ||
}); | ||
|
||
it('should throw an error if the height is even', () => { | ||
const operator = new GaussianBlur('type', 'id'); | ||
operator.cv2 = opencvMock.cv2; | ||
|
||
// Set private variables using setParams | ||
operator.setParams('widthSize', 3); | ||
operator.setParams('heightSize', 2); | ||
|
||
const imageMock = 'mockImageData'; | ||
|
||
// Assertions | ||
expect(() => { | ||
operator.compute(imageMock); | ||
}).toThrow('Height should be an odd number!'); | ||
}); | ||
|
||
it('should throw an error if the width is even', () => { | ||
const operator = new GaussianBlur('type', 'id'); | ||
operator.cv2 = opencvMock.cv2; | ||
|
||
// Set private variables using setParams | ||
operator.setParams('widthSize', 2); | ||
operator.setParams('heightSize', 3); | ||
|
||
const imageMock = 'mockImageData'; | ||
|
||
// Assertions | ||
expect(() => { | ||
operator.compute(imageMock); | ||
}).toThrow('Width should be an odd number!'); | ||
}); | ||
}); |
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,39 @@ | ||
const MedianBlur = require('../../../src/operator/blurring/MedianBlur') | ||
const opencvMock = require('../opencv-mocks/blurring.mock'); | ||
|
||
describe('MedianBlur Operator', () => { | ||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should process median blur function with given kernel size', () => { | ||
const operator = new MedianBlur('type', 'id'); | ||
operator.cv2 = opencvMock.cv2; // Inject the cv2 mock | ||
|
||
// Set private variable using setParams | ||
operator.setParams('kernelSize', 5); | ||
|
||
const imageMock = 'mockImageData'; | ||
|
||
operator.compute(imageMock); | ||
|
||
// Assertions | ||
expect(opencvMock.cv2.Mat).toHaveBeenCalledTimes(1); | ||
expect(opencvMock.cv2.medianBlur).toHaveBeenCalledWith( | ||
imageMock, | ||
{}, | ||
5 | ||
); | ||
}); | ||
|
||
it('should throw an error if kernel size is even', () => { | ||
const operator = new MedianBlur('type', 'id'); | ||
operator.cv2 = opencvMock.cv2; | ||
|
||
// Assertions | ||
expect(() => { | ||
operator.setParams('kernelSize', 4); | ||
}).toThrow('Kernel Size should be an odd number'); | ||
}); | ||
|
||
}); |
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 |
---|---|---|
@@ -1,9 +1,11 @@ | ||
module.exports = { | ||
cv2: { | ||
Mat: jest.fn(), | ||
Size: jest.fn((width, height) => ({ width, height })), // Mock Size with a function that returns an object | ||
Point: jest.fn((x, y) => ({ x, y })), // Mock Point with a function that returns an object | ||
Size: jest.fn((width, height) => ({ width, height })), | ||
Point: jest.fn((x, y) => ({ x, y })), | ||
blur: jest.fn(), | ||
GaussianBlur: jest.fn(), | ||
medianBlur: jest.fn(), | ||
}, | ||
}; | ||
|