Skip to content

Commit

Permalink
Added test coverage for convertion operators
Browse files Browse the repository at this point in the history
  • Loading branch information
abdullahranginwala authored and ivantha committed Aug 19, 2023
1 parent 267d4a9 commit 8c79e21
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 1 deletion.
2 changes: 1 addition & 1 deletion imagelab_electron/operations.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const PROCESS_OPERATIONS = {
EROSION: "filtering_erosion",
DILATION: "filtering_dilation",
MORPHOLOGICAL: "filtering_morphological",
ADAPTIVETHRESHOLDING: "thresholding_adaptivethreshold"
ADAPTIVETHRESHOLDING: "thresholding_adaptivethreshold",
SIMPLETHRESHOLDING: "thresholding_applythreshold",
};

Expand Down
2 changes: 2 additions & 0 deletions imagelab_electron/src/controller/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ class MainController {
case PROCESS_OPERATIONS.ADAPTIVETHRESHOLDING:
this.#appliedOperators.push(
new AdaptiveThreshold(PROCESS_OPERATIONS.ADAPTIVETHRESHOLDING, id)
);
break;
case PROCESS_OPERATIONS.SIMPLETHRESHOLDING:
this.#appliedOperators.push(
new ApplyThreshold(PROCESS_OPERATIONS.SIMPLETHRESHOLDING, id)
Expand Down
26 changes: 26 additions & 0 deletions imagelab_electron/tests/unit/convertions/GrayImage.test.js
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 imagelab_electron/tests/unit/convertions/GrayToBinary.test.js
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 imagelab_electron/tests/unit/opencv-mocks/convertions.mocks.js
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',
},
};

0 comments on commit 8c79e21

Please sign in to comment.