1 classdef StructCompareTC < matlab.unittest.TestCase
6 methods (TestMethodSetup)
7 function self = setUp(self)
28 self = self@matlab.unittest.TestCase(varargin{:});
32 function self = test_simplestruct_positive(
self)
33 S1=struct('a',1,'b',2);
34 S2=struct('a',2,'b',2);
36 self.verifyEqual(isEqual,false);
39 function testUpdateLeavesEmpty(self)
43 self.verifyTrue(isequal(S,Res));
46 function testVectorialStruct(self)
61 self.verifyEqual(false,isEqual);
65 function self = test_simplestruct_int64(self)
66 check(int64(1),int64(1),0,true);
67 check(uint64(1),uint64(2),3,true);
68 check(uint64(1),uint64(2),0,false);
70 function check(value1,value2,tol,expRes)
71 S1=struct('a',1,'b',value1);
72 S2=struct('a',1,'b',value2);
74 self.verifyEqual(isEqual,expRes);
78 function testInf(self)
79 S1=struct('a',1,'b',[nan inf -inf 1]);
81 self.verifyEqual(isEqual,true);
84 function self = test_simplestruct_negative(self)
85 S1=struct('a',1,'b',nan);
86 S2=struct('a',1,'b',2);
88 self.verifyEqual(isEqual,false);
90 function self = test_simplestruct_negative2(self)
91 S1=struct('a',1,'b',2);
92 S2=struct('a',1,'b',2);
94 self.verifyEqual(isEqual,true);
96 function self = test_simplestruct2_negative(self)
97 S1=struct('a',struct('a',1+1e-10,'b',1),'b',2);
98 S2=struct('a',struct('a',1,'b',1),'b',2);
100 self.verifyEqual(isEqual,false);
102 function self = test_simplestruct2_positive(self)
103 S1=struct('a',struct('a',1+1e-10,'b',1),'b',2);
104 S2=struct('a',struct('a',1,'b',1),'b',2);
106 self.verifyEqual(isEqual,true,reportStr);
108 function self = test_simplestruct3_negative(self)
109 S1=struct('a',struct('a',nan,'b',1),'b',2);
110 S2=struct('a',struct('a',1,'b',1),'b',2);
112 self.verifyEqual(isEqual,false);
115 function self = test_simplestructarray1_negative(self)
116 S1(1)=struct('a',struct('a',1+1e-10,'b',1),'b',2);
117 S1(2)=struct('a',struct('a',nan,'b',1),'b',2);
118 S2(1)=struct('a',struct('a',1,'b',1),'b',2);
119 S2(2)=struct('a',struct('a',1,'b',1),'b',2);
121 self.verifyEqual(isEqual,false);
123 function self = test_simplestructarray1_positive(self)
124 S2(1)=struct('a',struct('a',1,'b',1),'b',2);
125 S2(2)=struct('a',struct('a',1,'b',1),'b',2);
128 self.verifyEqual(isEqual,true,reportStr);
130 function self = test_complex1_positive(self)
132 self.verifyEqual(isEqual,true,reportStr);
134 function self = test_complex1_negative(self)
136 self.verifyEqual(isEqual,false);
137 self.verifyEqual(numel(strfind(reportStr,sprintf('\n'))),5);
139 function self = test_optional_tolerance_arg(self)
142 self.verifyEqual(isEqual,isEqual2);
143 self.verifyEqual(reportStr,reportStr2);
145 function self = test_complex2_negative(self)
146 S1=struct('a',1,'b',
repmat([2 nan 3],2,1));
147 S2=struct('a',2,'b',
repmat([1 nan 2],2,1));
149 self.verifyEqual(isEqual,false);
150 self.verifyEqual(2,numel(strfind(reportStr,'Max.')));
152 function self = test_differentsize_negative(self)
153 S1=struct('a',1,'b',
repmat([2 nan 3 3],2,1));
154 S2=struct('a',2,'b',
repmat([1 nan 2],2,1));
156 self.verifyEqual(isEqual,false);
157 self.verifyEqual(1,numel(strfind(reportStr,'Max.')));
158 self.verifyEqual(1,numel(strfind(reportStr,'Different sizes')));
160 function self = test_cell_positive(self)
161 S1=struct('a',1,'b',{{NaN;
struct(
'c',{
'aaa'})}});
163 self.verifyEqual(isEqual,
true);
165 function self = test_cell_negative(
self)
166 S1=struct('a',1,'b',{{NaN;
struct(
'c',{
'aaa'})}});
167 S2=
struct(
'a',1,
'b',{{NaN;
struct(
'c',{
'bbb'})}});
169 self.verifyEqual(isEqual,
false);
170 self.verifyEqual(1,numel(strfind(reportStr,
'values are different')));
172 function self = test_simplestruct_order_positive(
self)
173 S1=struct('a',1,'b',2);
174 S2=struct('b',2,'a',1);
176 self.verifyEqual(isEqual,true);
178 function self = test_relative_negative(self)
179 S1=struct('a',1e+10,'b',2e+12);
181 S2=struct('b',2e+12, 'a',1e+10 + 1e+6);
186 S2=struct('b',2e+12 - 1e+2, 'a',1e+10 + 1e+6);
191 S2=struct('b',2e+12 - 1e+9, 'a',1e+10 + 1e+6);
196 S1=struct('a',1e+6 - 2,'b',2e+6, 'c', 'aab');
197 S2=struct('a',1e+6,'b',2e+6 + 4, 'c', 'aab');
201 function check_neg(repMsgCount)
202 self.verifyEqual(isEqual,false);
203 self.verifyEqual(repMsgCount, ...
204 numel(strfind(reportStr, 'Max. relative difference')));
207 function self = test_relative_positive(self)
208 S1=struct('a',1e+6 - 0.5,'b',2e+6, 'c', 'aab');
209 S2=struct('a',1e+6,'b',2e+6 +1, 'c', 'aab');
211 self.verifyEqual(isEqual,true);
213 S1=struct('a',1e+10,'b',2e+12);
214 S2=struct('b',2e+12, 'a',1e+10 + 1e+2);
216 self.verifyEqual(isEqual,true);
218 S2=struct('b',2e+12 - 1e+4, 'a',1e+10 + 1e+2);
220 self.verifyEqual(isEqual,true);
function repmat(in inpArray, in varargin)
function structcompare(in SX, in SY, in absTol, in relTol)
STRUCTCOMPARE compares two structures using the specified tolerance.
function updateleaves(in SData, in fUpdateFunc)
UPDATELEAVES applies the specified function to each structure leave value and returns the updated str...