2 properties (Access=
private)
7 function self = StructDispTC(varargin)
8 self = self@
mxberry.unittest.TestCase(varargin{:});
10 shortClassName=mfilename(
'classname');
11 self.testDataRootDir=[fileparts(which(className)),...
15 methods (TestMethodSetup)
16 function self = set_up(
self)
17 self.resTmpDir=
mxberry.test.TmpDataManager.getDirByCallerKey();
20 methods (TestMethodTeardown)
21 function self = tear_down(self)
27 function self = test_strucdisp(self)
30 S.description=[]; %
#ok<STRNU> 32 res=evalc(
'strucdisp(S)');
33 ind=strfind(res,
'name');
34 self.verifyEqual(1,numel(ind));
35 ind=strfind(res,
'description');
36 self.verifyEqual(1,numel(ind));
38 function testStruct2Str(
self)
46 self.verifyEqual(true,isequal(resStr,resStr2));
48 function testStrucDispSimpleRegress(self)
64 function check(S,expList)
66 inpArgList={S,
'depth',2,
'printValues',
true};
67 resStr=evalc(
'mxberry.core.struct.strucdisp(inpArgList{:})');
69 self.verifyEqual(
true,isequal(resStr,resStr2));
70 resList=textscan(resStr,
'%s',
'delimiter',
'\n');
72 self.verifyEqual(
true,isequal(resList,expList));
75 function testStrucDispRegress(
self)
77 {
'depth',100,
'printValues',
false,
'maxArrayLength',100},...
78 {
'depth',100,
'printValues',
true,
'maxArrayLength',100},...
79 {
'depth',2,
'printValues',
true},...
80 {
'depth',100,
'printValues',
true},...
81 {
'depth',100,
'printValues',
false}};
84 inpFileName=[
self.testDataRootDir,
filesep,[methodName,
'_inp.mat']];
87 'storageLocationRoot',
self.testDataRootDir,...
88 'storageBranchKey',[methodName,
'_out'],
'storageFormat',
'mat',...
89 'useHashedPath',
false,
'useHashedKeys',
true);
90 SData=load(inpFileName);
91 structNameList=fieldnames(SData);
92 nFields=length(structNameList);
93 nArgCombs=length(ARG_COMB_LIST);
95 %resTmpDir=
self.resTmpDir;
96 %resFileName=[resTmpDir,
filesep,
'out.txt'];
98 structName=structNameList{iField};
100 for iArgComb=1:nArgCombs
101 inpArgList=ARG_COMB_LIST{iArgComb};
102 resStr=evalc(
'mxberry.core.struct.strucdisp(S,inpArgList{:})');
105 SRes.inpArgList=inpArgList;
108 %resMap.put(inpKey,SRes);
109 SExpRes=resMap.get(inpKey);
110 [isPos,reportStr]=...
112 self.verifyEqual(
true,isPos,reportStr);
117 function testGetLeaveList(
self)
129 Data.alpha(2,1,5).a=2;
130 Data.alpha(2,4,4).a=6;
133 function SRes=check()
134 SRes=checkGetField();
141 self.verifyEqual(true,isEqual,reportStr);
142 self.verifyEqual(true,isequaln(SRes,Data));
144 function SRes=checkValue()
146 nPaths=numel(pathSpecList);
149 SRes=setfield(SRes,pathSpecList{iPath}{:},...
153 function SRes=checkGetField()
155 nPaths=numel(pathSpecList);
158 SRes=setfield(SRes,pathSpecList{iPath}{:},...
159 getfield(Data,pathSpecList{iPath}{:}));
164 function test_updateLeaves(
self)
170 self.verifyEqual(true,isequal(SRes,SExp));
172 function [val,path]=fTransform(val,path)
173 path{4}=
repmat(path{4},1,2);
176 function testGetUpdateLeaves(
self)
184 SData.alpha.beta.gamma.theta=2;
185 SData.alpha.beta.gamma.delta='vega';
186 SData.alpha.beta.gamma.delta2=1;
195 self.verifyEqual(true,...
196 isequaln(SData,SRes));
199 self.verifyEqual(true,...
200 isequaln(SData,SRes));
206 self.verifyEqual(
true,isequal(pathList,pathExpList));
208 function value=storePath(value,subFieldNameList)
209 pathList=[pathList;{subFieldNameList}];
211 function x=fMinus(x,~)
217 function checkPathList(pathList)
219 self.verifyEqual(true,iscell(pathList));
220 if ~isempty(pathList)
221 self.verifyEqual(true,...
222 all(cellfun('isclass',pathList,'cell')));
223 self.verifyEqual(true,...
229 function self = testArrays(
self)
233 isOk = ~isempty(strfind(str, '1'));
235 S = struct('a', [1 2 3]);
237 isOk = isOk & ~isempty(strfind(str, '[1 2 3]'));
239 S = struct('a', ones(5, 3, 2));
241 isOk = isOk & ~isempty(strfind(str, '[5x3x2 Array]'));
243 self.verifyEqual(isOk, true);
246 function self = testLogicalFields(self)
248 S = struct('a', false(1, 2));
250 isOk = ~isempty(strfind(str, '[false false]'));
252 S = struct('a', false);
254 isOk = isOk & ~isempty(strfind(str, 'false'));
256 S = struct('a', false(5));
258 isOk = isOk & ~isempty(strfind(str, '[5x5 Logic array]'));
260 self.verifyEqual(isOk, true);
263 function self = testUpdateRegress(self)
266 {
'depth',100,
'printValues',
false,
'maxArrayLength',100},...
267 {
'depth',100,
'printValues',
true,
'maxArrayLength',100},...
268 {
'depth',2,
'printValues',
true},...
269 {
'depth',100,
'printValues',
true},...
270 {
'depth',100,
'printValues',
false}};
275 'storageLocationRoot',
self.testDataRootDir,...
276 'storageBranchKey',[methodName
'_inp'],
'storageFormat',
'mat',...
277 'useHashedPath',
false,
'useHashedKeys',
true);
279 'storageLocationRoot',
self.testDataRootDir,...
280 'storageBranchKey',[methodName
'_out'],
'storageFormat',
'mat',...
281 'useHashedPath',
false,
'useHashedKeys',
true);
282 nArgCombs=length(ARG_COMB_LIST);
284 keyList=inpResMap.getKeyList();
285 nKeys=numel(keyList);
287 keyName=keyList{iKey};
288 SDataVec=inpResMap.get(keyName);
289 for iArgComb=1:nArgCombs
290 inpArgList=ARG_COMB_LIST{iArgComb};
291 nElems=numel(SDataVec);
299 [rowIndVec,colIndVec]=...
300 stDispObj.update(SDataVec(iElem));
302 resStr=char(stDispObj);
304 'S',{SDataVec(iElem)},...
305 'inpArgList',{inpArgList},...
306 'rowIndVec',{rowIndVec},...
307 'colIndVec',{colIndVec},...
309 self.verifyEqual(
true,isequal(resStr,...
310 strucdisp(SDataVec(iElem),inpArgList{:})));
314 SExpRes=outResMap.get(inpKey);
315 if isunix()&&(iKey==3)
316 %different behavior on Linux
317 SExpRes.resStr=strrep(SExpRes.resStr,...
318 '-1430.13',
'-1430.12');
319 SExpRes.resStr=strrep(SExpRes.resStr,...
320 '-3102.63',
'-3102.62');
322 [isPos,reportStr]=...
324 self.verifyEqual(
true,isPos,reportStr);
function updateleavesext(in SData, in fUpdateFunc)
UPDATELEAVESEXT applies the specified function to each structure leave value and returns the updated ...
function struct2str(in SInp, in varargin)
STRUCDISP display structure outline.
function getleavelist(in SInp)
GETLEAVELIST generates a list of structure leave paths.
function genteststruct(in inpNum)
function repmat(in inpArray, in varargin)
This class is responsible for displaying structure outline.
function iscellofstring(in inpArray)
function rmdir(in dirName, in sFlag)
RMDIR removes a directory (optionally recursively)
function strucdisp(in varargin)
STRUCDISP display structure outline.
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...