-
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 convertion operators
- Loading branch information
1 parent
267d4a9
commit 8c79e21
Showing
5 changed files
with
70 additions
and
1 deletion.
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
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
26 changes: 26 additions & 0 deletions
26
imagelab_electron/tests/unit/convertions/GrayImage.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,26 @@ | ||
const GrayImage = require('../../../src/operator/convertions/GrayImage'); | ||
const opencvMock = require('../opencv-mocks/convertions.mocks'); | ||
|
||
|
||
describe('GrayImage Operator', () => { | ||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should process cvtColor function to gray the image', () => { | ||
const operator = new GrayImage('type', 'id'); | ||
operator.cv2 = opencvMock.cv2; | ||
|
||
const imageMock = 'mockImageData'; | ||
|
||
operator.compute(imageMock); | ||
|
||
// Assertions | ||
expect(opencvMock.cv2.Mat).toHaveBeenCalledTimes(1); | ||
expect(opencvMock.cv2.cvtColor).toHaveBeenCalledWith( | ||
imageMock, | ||
{}, | ||
'mockColorBGR2GRAY' | ||
); | ||
}); | ||
}); |
31 changes: 31 additions & 0 deletions
31
imagelab_electron/tests/unit/convertions/GrayToBinary.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,31 @@ | ||
const GrayToBinary = require('../../../src/operator/convertions/GrayToBinary'); | ||
const opencvMock = require('../opencv-mocks/convertions.mocks'); | ||
|
||
describe('GrayToBinary Operator', () => { | ||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should process threshold function to convert gray image to binary', () => { | ||
const operator = new GrayToBinary('type', 'id'); | ||
operator.cv2 = opencvMock.cv2; // Inject the cv2 mock | ||
|
||
// Set private variables using setParams | ||
operator.setParams('thresholdValue', 100); | ||
operator.setParams('maxValue', 255); | ||
|
||
const imageMock = 'mockImageData'; | ||
|
||
operator.compute(imageMock); | ||
|
||
// Assertions | ||
expect(opencvMock.cv2.Mat).toHaveBeenCalledTimes(1); | ||
expect(opencvMock.cv2.threshold).toHaveBeenCalledWith( | ||
imageMock, | ||
{}, | ||
100, | ||
255, | ||
'mockThreshBinary' | ||
); | ||
}); | ||
}); |
10 changes: 10 additions & 0 deletions
10
imagelab_electron/tests/unit/opencv-mocks/convertions.mocks.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,10 @@ | ||
module.exports = { | ||
cv2: { | ||
Mat: jest.fn(), | ||
cvtColor: jest.fn(), | ||
COLOR_BGR2GRAY: 'mockColorBGR2GRAY', | ||
threshold: jest.fn(), | ||
THRESH_BINARY: 'mockThreshBinary', | ||
}, | ||
}; | ||
|