Skip to content

Commit

Permalink
Added tests for mergeStructs (#177)
Browse files Browse the repository at this point in the history
* added tests for mergeStructs

* fixed typo and added test for error
  • Loading branch information
RabiyaF authored Nov 27, 2023
1 parent 0039c7d commit 756e64a
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions tests/testMergeStructs.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
classdef testMergeStructs < matlab.unittest.TestCase

properties (TestParameter)
s = {struct('s1', 1, 's2', 2),...
struct('s1', 1),...
struct('s1', 1, 's2', 2, 's3', 3)};
d = {struct('d1', 1, 'd2', 2),...
struct('d1', 1),...
struct('d1', 1, 'd2', 2)};
r = {struct('s1', 1, 's2', 2, 'd1', 1, 'd2', 2),...
struct('s1', 1, 'd1', 1),...
struct('s1', 1, 's2', 2, 's3', 3, 'd1', 1, 'd2', 2)};
end

methods (Test, ParameterCombination="sequential")
function testMergeResults(testCase, s, d, r)
result = mergeStructs(s, d);
testCase.verifyEqual(result, r);
end

function testMergeError(testCase)
s1 = struct('s', 1);
s2 = struct('s', 3);
testCase.verifyError(@() mergeStructs(s1, s2), 'MATLAB:DuplicateFieldName')
end
end
end

0 comments on commit 756e64a

Please sign in to comment.