Skip to content

Commit 756e64a

Browse files
authored
Added tests for mergeStructs (#177)
* added tests for mergeStructs * fixed typo and added test for error
1 parent 0039c7d commit 756e64a

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

tests/testMergeStructs.m

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
classdef testMergeStructs < matlab.unittest.TestCase
2+
3+
properties (TestParameter)
4+
s = {struct('s1', 1, 's2', 2),...
5+
struct('s1', 1),...
6+
struct('s1', 1, 's2', 2, 's3', 3)};
7+
d = {struct('d1', 1, 'd2', 2),...
8+
struct('d1', 1),...
9+
struct('d1', 1, 'd2', 2)};
10+
r = {struct('s1', 1, 's2', 2, 'd1', 1, 'd2', 2),...
11+
struct('s1', 1, 'd1', 1),...
12+
struct('s1', 1, 's2', 2, 's3', 3, 'd1', 1, 'd2', 2)};
13+
end
14+
15+
methods (Test, ParameterCombination="sequential")
16+
function testMergeResults(testCase, s, d, r)
17+
result = mergeStructs(s, d);
18+
testCase.verifyEqual(result, r);
19+
end
20+
21+
function testMergeError(testCase)
22+
s1 = struct('s', 1);
23+
s2 = struct('s', 3);
24+
testCase.verifyError(@() mergeStructs(s1, s2), 'MATLAB:DuplicateFieldName')
25+
end
26+
end
27+
end

0 commit comments

Comments
 (0)