3 function self = mlunit_test_common(varargin)
8 function testIsVar(
self)
11 self.verifyTrue(isOk);
13 self.verifyTrue(~isOk);
15 function testAbsRelCompare(
self)
18 self.runAndCheckError(...
20 'wrongInput:wrongArgs');
22 self.runAndCheckError(...
23 'mxberry.core.absrelcompare([1 1], [1 1], -0.1, [], @abs)', ...
24 'wrongInput:wrongAbsTol');
26 self.runAndCheckError([...
27 'mxberry.core.absrelcompare([1 1], [1 1], [0.1, 0.1], [],', ...
28 ' @abs)'],
'wrongInput:wrongAbsTol');
30 self.runAndCheckError([...
31 'mxberry.core.absrelcompare([1 1], [1 1], [], [],', ...
32 ' @abs)'],
'wrongInput:wrongAbsTol');
34 self.runAndCheckError(...
35 'mxberry.core.absrelcompare([1 1], [1 1], 0.1, -0.1, @abs)',...
36 'wrongInput:wrongRelTol');
38 self.runAndCheckError([...
39 'mxberry.core.absrelcompare([1 1], [1 1], 0.1, [0.1, 0.1],',...
40 ' @abs)'],
'wrongInput:wrongRelTol');
42 self.runAndCheckError(...
43 'mxberry.core.absrelcompare([1 1], [1 1], 0.1, [], 100)', ...
44 'wrongInput:wrongNormOp');
46 SRes = calc([], [], 0.5, [], @abs);
47 SExpRes =
struct(
'isEqual',
true,
'absDiff', [],
'isRel', ...
48 false,
'relDiff', [],
'relMDiff', []);
51 xVec = [1 2]; yVec = [2 4];
52 SRes = calc(xVec, yVec, 2, [], @abs);
53 SExpRes.isEqual =
true;
57 SRes = calc(xVec, yVec, 1, [], @abs);
58 SExpRes.isEqual =
false;
61 SRes = calc(xVec, yVec, 2, 2/3, @abs);
62 SExpRes.isEqual =
true;
65 SRes = calc(xVec, yVec, 1, 2/3, @abs);
67 SExpRes.relDiff = 2/3;
71 SRes = calc(xVec, yVec, 1, 0.5, @abs);
72 SExpRes.isEqual =
false;
75 SRes = calc(xVec, yVec, 0.5, 0.5, @abs);
77 function SRes = calc(varargin)
78 [SRes.isEqual, SRes.absDiff, SRes.isRel, SRes.relDiff, ...
79 SRes.relMDiff] =
mxberry.
core.absrelcompare(varargin{:});
81 function check(leftArray,rightArray)
82 self.verifyEqual(
true,isequal(leftArray,...
86 function self=testCheckMultVar(
self)
87 import
mxberry.core.check.lib.*;
92 checkP(@(x1)
isstring(x1),1,a,'varNameList',{
'alpha'});
94 checkP('numel(x1)==numel(x2)
',2,a,a); 95 checkP('numel(x1)==numel(x2)
',2,a,a,'varNameList
',{'alpha
'}); 96 checkP('numel(x1)==numel(x2)
',2,a,a,'varNameList
',{'alpha
','beta
'}); 98 checkNSuperMaster(''); 99 checkNSuperMaster('MyMessage
','errorMessage
','MyMessage
'); 101 function checkNSuperMaster(errorMessage,varargin) 103 checkNMaster('',errorMessage,varargin{:}); 104 checkNMaster('wrongParam:badType
',errorMessage,'errorTag
',... 105 'wrongParam:badType
',varargin{:}); 107 checkNMaster('wrongParam:badType
',errorMessage,'errorTag
',... 108 'wrongParam:badType
',varargin{:}); 111 function checkNMaster(expTag,expMessage,varargin) 112 isEmptyMsg=isempty(expMessage); 113 checkN('numel(x1)==numel(x2)
',2,expTag,expMessage,a,a,... 114 'varNameList
',{'alpha
','beta
','gamma
'},varargin{:}); 116 expMessage='Alpha,Beta
'; 118 checkN('numel(x1)==numel(x2)
',2,expTag,expMessage,a,b,... 119 'varNameList
',{'Alpha
','Beta
'},varargin{:}); 121 expMessage='Alpha,b
'; 123 checkN('numel(x1)==numel(x2)
',2,expTag,expMessage,a,b,... 124 'varNameList
',{'Alpha
'},varargin{:}); 128 function checkN(typeSpec,nPlaceHolders,expTag,expMsg,a,b,varargin) 135 expTag=':wrongInput
'; 137 import mxberry.core.check.lib.*; 139 mxberry.core.checkmultvar(... 140 typeSpec,nPlaceHolders,a,b,varargin{:}); 141 catch meObj %#ok<NASGU> 142 self.runAndCheckError(... 143 'rethrow(meObj)
',expTag,runArgList{:}); 145 fHandle=typeSpec2Handle(typeSpec,nPlaceHolders); 147 mxberry.core.checkmultvar(... 148 fHandle,nPlaceHolders,a,b,varargin{:}); 149 catch meObj %#ok<NASGU> 150 self.runAndCheckError(... 151 'rethrow(meObj)
',expTag,runArgList{:}); 155 function checkP(typeSpec,nPlaceHolders,varargin) 156 import mxberry.core.throwerror; 157 mxberry.core.checkmultvar(typeSpec,... 158 nPlaceHolders,varargin{:}); 159 fHandle=typeSpec2Handle(typeSpec,nPlaceHolders); 160 mxberry.core.checkmultvar(fHandle,... 161 nPlaceHolders,varargin{:}); 164 function fHandle=typeSpec2Handle(typeSpec,nPlaceHolders) 165 import mxberry.core.check.lib.*; 169 fHandle=eval(['@(x1)(
',typeSpec,')
']); 171 fHandle=eval(['@(x1,x2)(
',typeSpec,')
']); 173 fHandle=eval(['@(x1,x2,x3)(
',typeSpec,')
']); 175 throwerror('wrongInput
',... 176 'unsupported number of arguments
'); 183 function self=testCheckVar(self) 184 import mxberry.core.check.lib.*; 186 mxberry.core.checkvar(a,@isstring); 187 mxberry.core.checkvar(a,@isstring,'aa
'); 189 checkN(a,@(x)isstring(x)); 190 checkN(a,@(x)iscelloffunc(x)); 192 checkP(a,@(x)(isstring(x)||isrow(x))); 194 checkP(a,@(x)(isstring(x)||isrow(x)||isabrakadabra(x))); 197 checkN(a,@(x)(isstring(x)&&isvec(x))); 198 checkN(a,@(x)(isstring(x)&&isabrakadabra(x))); 201 checkP(a,@(x)(islogical(x)&&isscalar(x))); 203 checkP(a,@(x)(isstruct(x)&&isscalar(x))); 206 checkP(a,@(x)(iscellofstring(x))); 208 checkP(a,@(x)(iscellofstring(x))); 210 checkP(a,@(x)(iscellofstring(x))); 212 checkP(a,@(x)iscellofstring(x)); 213 a={'a
','b
';'d
','esd
'.'};
222 'errorMessage',
'myMessage');
223 checkNE(
'wrongType:wrongSomething',
'myMessage',a,...
225 'errorMessage',
'myMessage',
'errorTag',...
226 'wrongType:wrongSomething');
227 checkNE(
'wrongType:wrongSomething',
'',a,@
iscelloffunc,...
228 'errorTag',
'wrongType:wrongSomething');
230 function checkN(x,typeSpec,varargin)
231 checkNE(
'',
'',x,typeSpec,varargin{:});
235 function checkNE(errorTag,errorMessage,x,typeSpec,varargin)
238 errorTag=
':wrongInput';
240 if isempty(errorMessage)
243 addArgList={errorMessage};
245 self.runAndCheckError(...
246 [
'mxberry.core.checkvar(x,',...
247 'typeSpec,varargin{:})'],...
248 errorTag,addArgList{:});
250 fHandle=eval([
'@(x)(',typeSpec,
')']); %#ok<NASGU>
252 fHandle=typeSpec; %#ok<NASGU>
255 self.runAndCheckError(...
256 [
'mxberry.core.checkvar(x,',...
257 'fHandle,varargin{:})'],...
258 errorTag,addArgList{:});
261 function checkP(x,typeSpec,varargin)
265 fHandle=eval([
'@(x)(',typeSpec,
')']);
275 function testThrowWarn(
self)
276 check('wrongInput','test message');
277 check('wrongInput',...
278 'test \n message C:\\SomeFolder\\sdf/sdf/sdfsdf');
279 function check(identifier,message)
281 ['MXBERRY:CORE:TEST:MLUNIT_TEST_COMMON:TESTTHROWWARN:',...
286 'MXBERRY:CORE:TEST:MLUNIT_TEST_COMMON:TESTTHROWWARN:wrongInput');
289 [lastMsg,lastId]=lastwarn();
290 self.verifyEqual(true,isequal(sprintf(message),lastMsg));
291 self.verifyEqual(true,isequal(ID_STR,lastId));
294 function self=testThrowError(self)
295 check('wrongInput','test message');
296 check('wrongInput',...
297 'test \\ message C:\\SomeFolder\\sdf/sdf/sdfsdf');
298 function check(identifier,message)
303 self.verifyEqual(true,isequal(meObj.identifier,meExpObj.identifier));
304 self.verifyEqual(true,isequal(meObj.message,meExpObj.message));
305 self.verifyEqual(true,isequal(meObj.cause,meExpObj.cause));
309 function testGenFileName(self)
311 expStr='sdfsdfsdf.;_sdfd';
312 self.verifyEqual(true,isequal(resStr,expStr));
314 function testInd2SubMat(self)
318 nDims=length(sizeVec);
319 indSubList=cell(1,nDims);
321 [indSubList{:}]=ind2sub(sizeVec,indVec.
'); 322 indExpMat=[indSubList{:}]; 323 self.verifyEqual(true,isequal(indMat,indExpMat)); 326 function self=test_ismembercellstr(self) 327 import mxberry.core.ismembercellstr; 328 aList={'asdfsdf
','sdfsfd
','sdfsdf
','sdf
'}; 329 bList={'sdf
','sdfsdf
','ssdfsfsdfsd
','sdf
'}; 330 [isTVec,indLVec]=ismember(aList,bList,'legacy
'); 331 [isTOVec,indLOVec]=ismembercellstr(aList,bList,true); 332 self.verifyEqual(true,isequal(isTVec,isTOVec)); 333 self.verifyEqual(true,isequal(indLVec,indLOVec)); 335 [isTOVec,indLOVec]=ismembercellstr(aList,bList); 336 self.verifyEqual(true,isequal([false false true true],isTOVec)); 337 self.verifyEqual(true,isequal([0 0 2 1],indLOVec)); 339 [isTOVec,indLOVec]=ismembercellstr(aList,'sdfsfd
'); 340 self.verifyEqual(true,isequal([false true false false],isTOVec)); 341 self.verifyEqual(true,isequal([0 1 0 0],indLOVec)); 343 [isTOVec,indLOVec]=ismembercellstr('sdfsfd
',aList); 344 self.verifyEqual(true,isequal(true,isTOVec)); 345 self.verifyEqual(true,isequal(2,indLOVec)); 346 [isTOVec,indLOVec]=ismembercellstr('sdfsfd
','sdfsfd
'); 347 self.verifyEqual(true,isTOVec); 348 self.verifyEqual(indLOVec,1); 349 [isTOVec,indLOVec]=ismembercellstr('sdfsfd
','sdfsf
'); 350 self.verifyEqual(false,isTOVec); 351 self.verifyEqual(indLOVec,0); 353 [isTOVec,indLOVec]=ismembercellstr('alpha
',{'a
','b
','c
'}); 354 self.verifyEqual(false,isTOVec); 355 self.verifyEqual(indLOVec,0); 357 [isTOVec,indLOVec]=ismembercellstr({'a
','b
','c
'},'alpha
'); 358 self.verifyEqual(true,isequal(false(1,3),isTOVec)); 359 self.verifyEqual(true,isequal(zeros(1,3),indLOVec)); 362 function self=test_isunique(self) 363 self.verifyEqual(false,mxberry.core.isunique([1 1])); 364 self.verifyEqual(true,mxberry.core.isunique([1 2])); 366 function self=test_cell2tablestr(self) 367 fNeg=@()check(1000,-1,{'1000
'}); 368 self.runAndCheckError(fNeg,'wrongInput
'); 369 check(1000,4,{'1000
'}); 370 check(1000,3,{'1e+003
','1e+03
'}); 371 function check(value,numPrecision,expStr) 372 resStr=mxberry.core.cell.cell2tablestr([],num2cell(value),'_
',... 373 'numPrecision
',numPrecision); 374 self.verifyEqual(true,any(strcmp(expStr,resStr))); 378 function self = test_cellfunallelem(self) 379 inpCell=repmat({rand(7,7,7)<10},4*500,2); 381 self.aux_test_cellfunallelem(inpCell,@all); 382 self.aux_test_cellfunallelem(inpCell,@any); 384 inpCell=repmat({rand(7,7,7)},4*500,2); 385 self.aux_test_cellfunallelem(inpCell,@max); 386 self.aux_test_cellfunallelem(inpCell,@min); 390 function self=aux_test_cellfunallelem(self,inpCell,hFunc) 391 import mxberry.core.cellfunallelem; 393 res=cellfunallelem(hFunc,inpCell); 395 resCheck=cellfun(@(x)hFunc(x(:)),inpCell); 396 self.verifyEqual(isequal(res,resCheck),true); 399 res=cellfunallelem(hFunc,inpCell,'UniformOutput
',false); 401 resCheck=cellfun(@(x)hFunc(x(:)),inpCell,'UniformOutput
',false); 402 self.verifyEqual(isequal(res,resCheck),true); 407 function self=test_subreffrontdim(self) 409 res=mxberry.core.subreffrontdim(inp,1); 410 self.verifyEqual(res,[1 2]); 413 function self=test_num2cell(self) 415 self.aux_test_num2cell(inpArray); 418 resCellEthalon=num2cell(inpMat); 419 resCell=mxberry.core.num2cell(inpMat); 420 self.verifyEqual(true,isequal(resCell,resCellEthalon)); 423 function self=test_num2cell_empty(self) 425 self.aux_test_num2cell(inpArray); 430 function self=aux_test_num2cell(self,inpArray) 431 resCellEthalon={inpArray(1,:);inpArray(2,:);inpArray(3,:)}; 432 resCell=mxberry.core.num2cell(inpArray,2); 433 self.verifyEqual(true,isequal(resCell,resCellEthalon)); 438 function self=test_iscelllogical(self) 439 isTrue=mxberry.core.iscelllogical({true,false}); 440 self.verifyEqual(true,isTrue); 441 isTrue=mxberry.core.iscelllogical({}); 442 self.verifyEqual(false,isTrue); 446 function self=aux_test_iscellnumeric(self,isOk,isEmpty) 448 typeList={'single
','double','int8
','int16
','int32
','int64
'}; 449 for iType=1:length(typeList) 450 obj={mxberry.core.createarray(typeList{iType},sizeVec)}; 455 isTrue=mxberry.core.iscellnumeric(obj); 456 self.verifyEqual(isOk,isTrue,... 457 ['failed
for type
',typeList{iType}]); 462 function self=test_iscellnumeric(self) 463 self.aux_test_iscellnumeric(true,false); 464 self.aux_test_iscellnumeric(false,true); 467 function self=test_isvec(self) 468 isPositive=mxberry.core.iscol(rand(10,1)); 469 self.verifyEqual(isPositive,true); 471 isPositive=mxberry.core.iscol(rand(10,2)); 472 self.verifyEqual(isPositive,false); 474 isPositive=mxberry.core.iscol(zeros(0,1)); 475 self.verifyEqual(isPositive,true); 477 isPositive=mxberry.core.iscol(zeros(1,0)); 478 self.verifyEqual(isPositive,false); 480 isPositive=mxberry.core.iscol(zeros(0,0)); 481 self.verifyEqual(isPositive,false); 483 isPositive=mxberry.core.isvec(rand(10,1)); 484 self.verifyEqual(isPositive,true); 485 isPositive=mxberry.core.isvec(rand(1,10)); 486 self.verifyEqual(isPositive,true); 487 isPositive=mxberry.core.isvec(rand(1,1,10)); 488 self.verifyEqual(isPositive,false); 490 self.verifyEqual(mxberry.core.isrow(rand(10,1)),false); 491 self.verifyEqual(mxberry.core.isrow(rand(1,10)),true); 492 self.verifyEqual(mxberry.core.isrow([]),false); 494 self.verifyEqual(mxberry.core.isrow(zeros(0,1)),false); 495 self.verifyEqual(mxberry.core.isrow(zeros(1,0)),true); 497 self.verifyEqual(mxberry.core.iscol(rand(10,1)),true); 498 self.verifyEqual(mxberry.core.iscol(rand(1,10)),false); 499 self.verifyEqual(mxberry.core.iscol([]),false); 501 self.verifyEqual(mxberry.core.isrow(rand(1,1,2)),false); 503 function self=test_error(self) 504 inpArgList={'myTag
','myMessage %d
',1}; %#ok<NASGU> 505 self.runAndCheckError(... 507 'MXBERRY:CORE:TEST:AUX:TESTERROR:myTag
','myMessage 1
'); 509 function test_parseparext_touch(~) 510 [reg,isRegSpec,putStorageHook,getStorageHook]=... 511 mxberry.core.parseparext(... 513 'putStorageHook
','getStorageHook
';... 515 @(x)isa(x,'function_handle
'),@(x)isa(x,'function_handle
')},... 520 function self=test_parseparext_obligprop(self) 521 inpProp={1,'aa
',1,'bb
',2,'cc
',3}; 522 isObligatoryPropVec=[false false false]; 524 isObligatoryPropVec=[false false true]; 525 self.runAndCheckError(@check,':wrong
'); 527 [reg,isRegSpec,prop,isPropSpec]=... 528 mxberry.core.parseparext(inpProp,{'aa
','bb
','dd
'},... 529 'propRetMode
','list
','isObligatoryPropVec
',... 530 isObligatoryPropVec); %#ok<ASGLU> 533 function test_parseparams_duplicate(self) 534 self.runAndCheckError(@check,... 535 'wrongInput:duplicatePropertiesSpec
'); 536 self.runAndCheckError(@check1,... 537 'wrongInput:duplicatePropertiesSpec
'); 539 mxberry.core.parseparams(... 540 {1,2,'prop1
',1,'prop2
',2,'prop2
',3},{'prop1
','prop2
'},[0 2]); 543 mxberry.core.parseparams(... 544 {1,2,'prop1
',1,'prop2
',2,'prop2
',3}); 547 function test_parseparext_isdefspecvec(self) 548 self.runAndCheckError(@check,... 549 'wrongInput:defPropSpecVecNotInListMode
'); 550 self.runAndCheckError(@check2,... 551 'wrongInput:defPropSpecVecNoDefValues
'); 553 [regList,isRegSpecVec,propList,isPropSpecVec]=check3(); 554 expPropList={'prop1
',1,'prop3
',2}; 556 isExpRegSpecVec=[true,true]; 557 isExpPropSpecVec=[true,false,false]; 561 [regList,isRegSpecVec,propList,isPropSpecVec]=check4(); 563 expPropList={'prop1
',1,'prop2
',1,'prop3
',2}; 566 function expCompare() 567 self.verifyEqual(true,isequal(expRegList,regList)); 568 self.verifyEqual(true,isequal(expPropList,propList)); 569 self.verifyEqual(true,isequal(isExpRegSpecVec,isRegSpecVec)); 570 self.verifyEqual(true,isequal(isExpPropSpecVec,isPropSpecVec)); 573 mxberry.core.parseparext(... 575 {'prop1
','prop2
','prop3
';... 576 [],1,2},'isDefaultPropSpecVec
',[false,false,true],'propRetMode
','separate
'); 579 mxberry.core.parseparext(... 581 {'prop1
','prop2
','prop3
'},'isDefaultPropSpecVec
',[false,false,true],'propRetMode
','list
'); 583 function [regList,isRegSpec,propList,isPropSpec]=check3() 584 [regList,isRegSpec,propList,isPropSpec]=mxberry.core.parseparext(... 586 {'prop1
','prop2
','prop3
';... 587 [],1,2},'isDefaultPropSpecVec
',[false,false,true],'propRetMode
','list
'); 589 function [regList,isRegSpec,propList,isPropSpec]=check4() 590 [regList,isRegSpec,propList,isPropSpec]=mxberry.core.parseparext(... 592 {'prop1
','prop2
','prop3
';... 593 [],1,2},'propRetMode
','list
'); 596 function test_parseparext_duplicate(self) 597 self.runAndCheckError(@check,... 598 'wrongInput:duplicatePropertiesSpec
'); 599 self.runAndCheckError(@check1,... 600 'wrongInput:duplicatePropertiesSpec
'); 602 mxberry.core.parseparext(... 603 {1,2,'prop1
',1,'prop2
',2,'prop2
',3},{'prop1
','prop2
'},[0 2]); 606 mxberry.core.parseparext(... 607 {1,2,'prop1
',1,'prop2
',2,'prop2
',3},[],[0 2],... 608 'propRetMode
','list
'); 610 mxberry.core.parseparext({'prop0
',1,'prop1
',1,'prop2
',2},... 611 {'prop1
','prop2
'},[0 2]); 613 function self=test_parseparext_simple(self) 615 inpFirstProp={'aa
',1}; 616 inpSecProp={'bb
',2,'cc
',3}; 617 inpProp=[inpFirstProp,inpSecProp]; 618 self.runAndCheckError(... 619 'mxberry.
core.parseparext(inpReg,[],
''propRetMode
'',
''separate
'')
',... 622 [reg,isRegSpec,prop,isPropSpec]=... 623 mxberry.core.parseparext([inpReg,inpProp],[],... 624 'propRetMode
','list
'); 625 self.verifyEqual(3,length(isPropSpec)); 626 self.verifyEqual(true,all(isPropSpec)); 627 self.verifyEqual(true,isRegSpec); 628 self.verifyEqual(true,isequal(reg,inpReg));% 629 self.verifyEqual(true,isequal(prop,inpProp));% 631 [reg,isRegSpec,prop,isPropSpec]=... 632 mxberry.core.parseparext([inpReg,inpProp],{'bb
','cc
'},... 633 'propRetMode
','list
'); 634 self.verifyEqual([true,true,true],isRegSpec); 635 self.verifyEqual(true,isequal(reg,[inpReg,inpFirstProp]));% 636 self.verifyEqual(true,isequal(prop,inpSecProp));% 637 self.verifyEqual(true,all(isPropSpec)); 638 self.verifyEqual(2,length(isPropSpec)); 640 [reg,isRegSpec,prop,isPropSpec]=... 641 mxberry.core.parseparext({},{'bb
','cc
'},... 642 'propRetMode
','list
'); 643 self.verifyEqual(true,isempty(reg)); 644 self.verifyEqual(true,isempty(prop)); 645 self.verifyEqual(true,isempty(isRegSpec)); 646 self.verifyEqual(false,any(isPropSpec)); 647 self.verifyEqual(2,length(isPropSpec)); 649 [reg,isRegSpec,prop,isPropSpec]=... 650 mxberry.core.parseparext({},[],... 651 'propRetMode
','list
'); 652 self.verifyEqual(true,isempty(reg)); 653 self.verifyEqual(true,isempty(prop)); 654 self.verifyEqual(true,isempty(isRegSpec)); 655 self.verifyEqual(true,isempty(isPropSpec)); 660 initInpArgList={1,'joinByInst
',true,'keepJoinId
',true}; 661 propCheckMat={'joinByInst
','keepJoinId
';... 663 'isscalar(x)&&islogical(x)
','isscalar(x)&&islogical(x)
'}; 670 checkN('regCheckList
',{'true','true'}); 672 checkN('regCheckList
',{'true','true'}); 674 propCheckMat={'joinByInst
','keepJoinId
';... 676 @(x)isscalar(x)&&islogical(x),... 677 @(x)isscalar(x)&&islogical(x)}; 684 initInpArgList={'joinByInst
',true,'keepJoinId
',true}; 687 function checkMaster() 689 checkP('regCheckList
',{'true'}); 690 checkP('regCheckList
',{@true}); 691 checkN('regCheckList
','true'); 693 checkN('regCheckList
',{'false'}); 695 checkP('regCheckList
',{'true','true'}); 696 checkP('regCheckList
',{@true,@true}); 698 function checkN(varargin) 699 inpArgList={initInpArgList,propCheckMat,nRegExpMax,... 700 varargin{:}}; %#ok<CCAT,NASGU> 701 self.runAndCheckError(... 705 function checkP(varargin) 706 [reg1,isRegSpec1Vec]=checkPInt(varargin{:}); 707 [reg2,isRegSpec2Vec]=checkPInt(varargin{:},'regDefList
',regDefList); 709 self.verifyEqual(true,isequal(reg1{1},reg2{1})); 710 self.verifyEqual(true,... 711 isequal(isRegSpec1Vec(1),isRegSpec2Vec(1))); 713 self.verifyEqual(false,isRegSpec2Vec(2)); 714 self.verifyEqual(true,isequal(nRegs,length(isRegSpec1Vec))); 715 self.verifyEqual(true,isequal(2,length(isRegSpec2Vec))); 716 self.verifyEqual(true,isequal(nRegs,length(reg1))); 717 self.verifyEqual(true,isequal(2,length(reg2))); 718 self.verifyEqual(true,isequal(3,reg2{2})); 720 inpArgList={initInpArgList,... 721 varargin{:},'regDefList
',[regDefList,4]}; %#ok<CCAT,NASGU> 722 self.runAndCheckError(... 726 function [reg,isRegSpecVec]=checkPInt(varargin) 727 [reg,isRegSpecVec,isJoinByInst,isJoinIdKept]=... 728 mxberry.core.parseparext(initInpArgList,... 729 propCheckMat,nRegExpMax,... 732 self.verifyEqual(true,isRegSpecVec(1)); 733 self.verifyEqual(true,isequal(reg(1:nRegs),{1})); 735 [~,prop]=mxberry.core.parseparams(varargin,{'regDefList
'}); 737 self.verifyEqual(true,isempty(isRegSpecVec)); 738 self.verifyEqual(true,isempty(reg)); 740 self.verifyEqual(false,any(isRegSpecVec)) 741 self.verifyEqual(length(prop{2}),... 746 self.verifyEqual(true,isJoinByInst); 747 self.verifyEqual(true,isJoinIdKept); 752 function self=test_parseparams(self) 753 [reg,prop]=getparse({'alpha
'}); 754 self.verifyEqual(true,isequal(reg,{'alpha
'})); 755 self.verifyEqual(true,isequal(prop,{})); 757 [reg,prop]=getparse({'alpha
','beta
',1}); 758 self.verifyEqual(true,isequal(reg,{'alpha
'})); 759 self.verifyEqual(true,isequal(prop,{'beta
',1})); 761 [reg,prop]=getparse({'alpha
',1,3,'beta
',1}); 762 self.verifyEqual(true,isequal(reg,{'alpha
',1,3})); 763 self.verifyEqual(true,isequal(prop,{'beta
',1})); 765 [reg,prop]=getparse({'alpha
',1,3,'beta
',1},{'alpha
'}); 766 self.verifyEqual(true,isequal(reg,{3,'beta
',1})); 767 self.verifyEqual(true,isequal(prop,{'alpha
',1})); 769 [reg,prop]=getparse({'alpha
',1,3,'beta
',1},{}); 770 self.verifyEqual(true,isequal(reg,{'alpha
',1,3,'beta
',1})); 771 self.verifyEqual(true,isequal(prop,{})); 773 [reg,prop]=getparse({'alpha
',1,3,'beta
',1,'gamma
',1},'gamma
'); 774 self.verifyEqual(true,isequal(reg,{'alpha
',1,3,'beta
',1})); 775 self.verifyEqual(true,isequal(prop,{'gamma
',1})); 777 [reg,prop]=getparse({'alpha
',1,3,'gamma
',1,'beta
',1},'gamma
'); 778 self.verifyEqual(true,isequal(reg,{'alpha
',1,3,'beta
',1})); 779 self.verifyEqual(true,isequal(prop,{'gamma
',1})); 781 [reg,prop]=getparse({'alpha
',1,3,'beta
',1,'gamma
',1},'Gamma
'); 782 self.verifyEqual(true,isequal(reg,{'alpha
',1,3,'beta
',1})); 783 self.verifyEqual(true,isequal(prop,{'gamma
',1})); 785 [reg,prop]=getparse({'alpha
',1},'beta
'); 786 self.verifyEqual(true,isequal(reg,{'alpha
',1})); 787 self.verifyEqual(true,isequal(prop,{})); 789 [reg,prop]=getparse({'alpha
',1},'beta
',[0 2]); 790 self.verifyEqual(true,isequal(reg,{'alpha
',1})); 791 self.verifyEqual(true,isequal(prop,{})); 793 [reg,prop]=getparse({1,'alpha
'},'alpha
'); 794 self.verifyEqual(true,isequal(reg,{1,'alpha
'})); 795 self.verifyEqual(true,isequal(prop,{})); 797 [reg,prop]=getparse(... 798 {1,'alpha
',3,'beta
',3,'gamma
'},{'alpha
','gamma
'}); 799 self.verifyEqual(true,isequal(reg,{1,'beta
',3,'gamma
'})); 800 self.verifyEqual(true,isequal(prop,{'alpha
',3})); 801 function [reg,prop]=getparse(argList,varargin) 803 propInpNameList=varargin{1}; 804 if isnumeric(propInpNameList)&&isempty(propInpNameList) 805 isPropNameSpec=false; 807 if ischar(propInpNameList) 808 propInpNameList={lower(propInpNameList)}; 810 propInpNameList=lower(propInpNameList); 815 isPropNameSpec=false; 818 [reg,prop]=mxberry.core.parseparams(argList,varargin{:}); 820 if isPropNameSpec&&numel([varargin{:}])>0 821 nPairs=length(propInpNameList); 822 outCell=cell(1,2*nPairs); 823 [reg1,~,outCell{:}]=... 824 mxberry.core.parseparext(argList,varargin{:}); 826 [propValList,isSpecVec]=getval(outCell); 828 propNameList=propInpNameList; 830 self.verifyEqual(true,isequal(reg,reg1)); 831 isEqual=isequal(propNameList,... 832 propInpNameList)||isempty(propNameList)&&... 833 isempty(propInpNameList); 834 self.verifyEqual(true,isEqual); 835 pNameList=propNameList(isSpecVec); 836 pValList=propValList(isSpecVec); 837 inpArgList=[pNameList;pValList]; 838 s1=struct(inpArgList{:}); 840 isEqual=isequal(s1,s2); 841 self.verifyEqual(true,isEqual); 844 defValList=num2cell(rand(size(propNameList))); 845 [reg2,~,outCell{:}]=... 846 mxberry.core.parseparext(argList,... 847 [propNameList;defValList],varargin{2:end}); 848 self.verifyEqual(true,isequal(reg,reg2)); 849 [propValList,isSpecVec]=getval(outCell); 850 isEqual=isequal(propValList(~isSpecVec),... 851 defValList(~isSpecVec)); 852 self.verifyEqual(true,isEqual); 854 checkStrList=repmat({'false'},size(defValList)); 855 checkStrList(isSpecVec)={'true'}; 856 [reg3,~,outCell{:}]=... 857 mxberry.core.parseparext(argList,... 858 [propNameList;defValList;... 859 checkStrList],varargin{2:end}); 860 [propValList3,isSpecVec3]=getval(outCell); 861 self.verifyEqual(true,isequal(reg,reg3)); 862 self.verifyEqual(true,isequal(propValList3,propValList)); 863 self.verifyEqual(true,isequal(isSpecVec,isSpecVec3)); 867 function [propValList,isSpecVec]=getval(outCell) 868 propValList=outCell(1:nPairs); 869 isSpecVec=[outCell{nPairs+1:nPairs*2}]; 873 function self=test_parseparams_negative(self) 874 inpArgList={'alpha
',1,3,'beta
',1,'gamma
',1}; 876 [reg1,prop1]=mxberry.core.parseparams(inpArgList); 877 [reg2,prop2]=mxberry.core.parseparams(inpArgList,[]); 879 self.verifyEqual(true,isequal(reg1,reg2)); 880 self.verifyEqual(true,isequal(prop1,prop2)); 882 self.runAndCheckError(... 885 mxberry.core.parseparams(inpArgList,[],3); 886 mxberry.core.parseparams(inpArgList,[],3,[]); 887 mxberry.core.parseparams(inpArgList,[],3,2); 888 mxberry.core.parseparams(inpArgList,[],[],2); 889 mxberry.core.parseparams(inpArgList,[],[3,3]); 890 mxberry.core.parseparams(inpArgList,[],[3,3],[]); 891 mxberry.core.parseparams(inpArgList,[],[3,6],2); 892 mxberry.core.parseparams(inpArgList,[],[0,3],2); 893 self.runAndCheckError(... 897 self.runAndCheckError(... 898 'mxberry.
core.parseparams(inpArgList,[],[0,3],2.5);
',... 901 self.runAndCheckError(... 902 'mxberry.
core.parseparams(inpArgList,[],[],3);
',... 904 self.runAndCheckError(... 905 'mxberry.
core.parseparams(inpArgList,[],3.5,3);
',... 907 self.runAndCheckError(... 908 'mxberry.
core.parseparams(inpArgList,[],[-3 3],2);
',... 910 self.runAndCheckError(... 911 'mxberry.
core.parseparams(inpArgList,[],[3.5 3.4],3);
',... 913 self.runAndCheckError(... 914 'mxberry.
core.parseparams(inpArgList,[],[3.5 3.4],3);
',... 916 self.runAndCheckError(... 917 'mxberry.
core.parseparams(inpArgList,[],[4 4],2);
',... 919 self.runAndCheckError(... 920 'mxberry.
core.parseparams(inpArgList,[],[4 6],2);
',... 922 self.runAndCheckError(... 923 'mxberry.
core.parseparams(inpArgList,[],[0 2],2);
',... 926 function self=test_getfirstdimsize(self) 928 inpArray=rand([expSizeVec,4,5]); 929 self.verifyEqual(expSizeVec,... 930 mxberry.core.getfirstdimsize(inpArray,2)); 932 inpArray=rand([expSizeVec,1,1]); 933 self.verifyEqual(expSizeVec,... 934 mxberry.core.getfirstdimsize(inpArray,3)); 935 self.verifyEqual([expSizeVec,[1 1]],... 936 mxberry.core.getfirstdimsize(inpArray,5)); 937 self.verifyEqual(true,... 938 isempty(mxberry.core.getfirstdimsize(inpArray,0))); 939 self.runAndCheckError(... 944 function self=test_checksize(self) 946 self.verifyEqual(true,mxberry.core.checksize(rand(2,3),[2,3,1])); 947 self.verifyEqual(true,mxberry.core.checksize(rand(2,3),[2,3])); 948 self.verifyEqual(false,mxberry.core.checksize(rand(2,4),[2,3])); 949 self.verifyEqual(false,mxberry.core.checksize(rand(2,4,5),[2,4])); 950 self.verifyEqual(true,mxberry.core.checksize([],[])); 951 self.verifyEqual(false,mxberry.core.checksize(1,[])); 953 function self=test_cat(self) 954 typeList={'int8
','double','logical
','struct'}; 955 for iType=1:length(typeList) 956 for jType=1:length(typeList) 957 iObj=mxberry.core.createarray(typeList{iType},[]); 958 jObj=mxberry.core.createarray(typeList{jType},[]); 959 res=mxberry.core.cat(1,iObj,jObj); 960 self.verifyEqual(true,... 961 isa(res,typeList{iType})); 965 function self=test_getcallernameext(self) 966 testClassA=GetCallerNameExtTestClassA; 967 [methodName,className]=getCallerInfo(testClassA); %#ok<*NCOMMA> 968 self.verifyEqual(true,... 969 isequal(methodName,'GetCallerNameExtTestClassA
')&&... 970 isequal(className,'GetCallerNameExtTestClassA
')); 971 testClassA=simpleMethod(testClassA); 972 [methodName,className]=getCallerInfo(testClassA); 973 self.verifyEqual(true,... 974 isequal(methodName,'simpleMethod
')&&... 975 isequal(className,'GetCallerNameExtTestClassA
')); 976 testClassA=subFunctionMethod(testClassA); 977 [methodName,className]=getCallerInfo(testClassA); 978 self.verifyEqual(true,... 979 isequal(methodName,'subFunctionMethod/subFunction
')&&... 980 isequal(className,'GetCallerNameExtTestClassA
')); 981 testClassA=subFunctionMethod2(testClassA); 982 [methodName,className]=getCallerInfo(testClassA); 983 self.verifyEqual(true,... 984 isequal(methodName,'subFunctionMethod2/subFunction
')&&... 985 isequal(className,'GetCallerNameExtTestClassA
')); 986 testClassA=subFunctionMethod3(testClassA); 987 [methodName,className]=getCallerInfo(testClassA); 988 self.verifyEqual(true,... 989 isequal(methodName,'subFunctionMethod3/subFunction/subFunction2
')&&... 990 isequal(className,'GetCallerNameExtTestClassA
')); 992 testClassB=GetCallerNameExtTestClassB; 993 [methodName,className]=getCallerInfo(testClassB); 994 self.verifyEqual(true,... 995 isequal(methodName,'GetCallerNameExtTestClassB
')&&... 996 isequal(className,'GetCallerNameExtTestClassB
')); 997 simpleMethod(testClassB); 998 [methodName,className]=getCallerInfo(testClassB); 999 self.verifyEqual(true,... 1000 isequal(methodName,'simpleMethod
')&&... 1001 isequal(className,'GetCallerNameExtTestClassB
')); 1002 subFunctionMethod(testClassB); 1003 [methodName,className]=getCallerInfo(testClassB); 1004 self.verifyEqual(true,... 1005 isequal(methodName,'subFunctionMethod/subFunction
')&&... 1006 isequal(className,'GetCallerNameExtTestClassB
')); 1007 subFunctionMethod2(testClassB); 1008 [methodName,className]=getCallerInfo(testClassB); 1009 self.verifyEqual(true,... 1010 isequal(methodName,'subFunctionMethod2/subFunction
')&&... 1011 isequal(className,'GetCallerNameExtTestClassB
')); 1012 subFunctionMethod3(testClassB); 1013 [methodName,className]=getCallerInfo(testClassB); 1014 self.verifyEqual(true,... 1015 isequal(methodName,'subFunctionMethod3/subFunction/subFunction2
')&&... 1016 isequal(className,'GetCallerNameExtTestClassB
')); 1018 testClassB=getcallernameexttest.GetCallerNameExtTestClassB; 1019 [methodName,className]=getCallerInfo(testClassB); 1020 self.verifyEqual(true,... 1021 isequal(methodName,'GetCallerNameExtTestClassB
')&&... 1022 isequal(className,'getcallernameexttest.GetCallerNameExtTestClassB
')); 1023 simpleMethod(testClassB); 1024 [methodName,className]=getCallerInfo(testClassB); 1025 self.verifyEqual(true,... 1026 isequal(methodName,'simpleMethod
')&&... 1027 isequal(className,'getcallernameexttest.GetCallerNameExtTestClassB
')); 1028 subFunctionMethod(testClassB); 1029 [methodName,className]=getCallerInfo(testClassB); 1030 self.verifyEqual(true,... 1031 isequal(methodName,'subFunctionMethod/subFunction
')&&... 1032 isequal(className,'getcallernameexttest.GetCallerNameExtTestClassB
')); 1033 subFunctionMethod2(testClassB); 1034 [methodName,className]=getCallerInfo(testClassB); 1035 self.verifyEqual(true,... 1036 isequal(methodName,'subFunctionMethod2/subFunction
')&&... 1037 isequal(className,'getcallernameexttest.GetCallerNameExtTestClassB
')); 1038 subFunctionMethod3(testClassB); 1039 [methodName,className]=getCallerInfo(testClassB); 1040 self.verifyEqual(true,... 1041 isequal(methodName,'subFunctionMethod3/subFunction/subFunction2
')&&... 1042 isequal(className,'getcallernameexttest.GetCallerNameExtTestClassB
')); 1044 testClassC=GetCallerNameExtTestClassC; 1045 [methodName,className]=getCallerInfo(testClassC); 1046 self.verifyEqual(true,... 1047 isequal(methodName,'GetCallerNameExtTestClassB
')&&... 1048 isequal(className,'GetCallerNameExtTestClassB
')); 1049 testClassC=GetCallerNameExtTestClassC(false); 1050 [methodName,className]=getCallerInfo(testClassC); 1051 self.verifyEqual(true,... 1052 isequal(methodName,'GetCallerNameExtTestClassC
')&&... 1053 isequal(className,'GetCallerNameExtTestClassC
')); 1054 simpleMethod(testClassC); 1055 [methodName,className]=getCallerInfo(testClassC); 1056 self.verifyEqual(true,... 1057 isequal(methodName,'simpleMethod
')&&... 1058 isequal(className,'GetCallerNameExtTestClassC
')); 1059 subFunctionMethod(testClassC); 1060 [methodName,className]=getCallerInfo(testClassC); 1061 self.verifyEqual(true,... 1062 isequal(methodName,'subFunctionMethod/subFunction
')&&... 1063 isequal(className,'GetCallerNameExtTestClassC
')); 1064 subFunctionMethod2(testClassC); 1065 [methodName,className]=getCallerInfo(testClassC); 1066 self.verifyEqual(true,... 1067 isequal(methodName,'subFunctionMethod2/subFunction
')&&... 1068 isequal(className,'GetCallerNameExtTestClassB
')); 1069 subFunctionMethod3(testClassC); 1070 [methodName,className]=getCallerInfo(testClassC); 1071 self.verifyEqual(true,... 1072 isequal(methodName,'subFunctionMethod3/subFunction/subFunction2
')&&... 1073 isequal(className,'GetCallerNameExtTestClassC
')); 1075 testClassC=getcallernameexttest.GetCallerNameExtTestClassC; 1076 [methodName,className]=getCallerInfo(testClassC); 1077 self.verifyEqual(true,... 1078 isequal(methodName,'GetCallerNameExtTestClassB
')&&... 1079 isequal(className,'getcallernameexttest.GetCallerNameExtTestClassB
')); 1080 testClassC=getcallernameexttest.GetCallerNameExtTestClassC(false); 1081 [methodName,className]=getCallerInfo(testClassC); 1082 self.verifyEqual(true,... 1083 isequal(methodName,'GetCallerNameExtTestClassC
')&&... 1084 isequal(className,'getcallernameexttest.GetCallerNameExtTestClassC
')); 1085 simpleMethod(testClassC); 1086 [methodName,className]=getCallerInfo(testClassC); 1087 self.verifyEqual(true,... 1088 isequal(methodName,'simpleMethod
')&&... 1089 isequal(className,'getcallernameexttest.GetCallerNameExtTestClassC
')); 1090 subFunctionMethod(testClassC); 1091 [methodName,className]=getCallerInfo(testClassC); 1092 self.verifyEqual(true,... 1093 isequal(methodName,'subFunctionMethod/subFunction
')&&... 1094 isequal(className,'getcallernameexttest.GetCallerNameExtTestClassC
')); 1095 subFunctionMethod2(testClassC); 1096 [methodName,className]=getCallerInfo(testClassC); 1097 self.verifyEqual(true,... 1098 isequal(methodName,'subFunctionMethod2/subFunction
')&&... 1099 isequal(className,'getcallernameexttest.GetCallerNameExtTestClassB
')); 1100 subFunctionMethod3(testClassC); 1101 [methodName,className]=getCallerInfo(testClassC); 1102 self.verifyEqual(true,... 1103 isequal(methodName,'subFunctionMethod3/subFunction/subFunction2
')&&... 1104 isequal(className,'getcallernameexttest.GetCallerNameExtTestClassC
')); 1106 methodName='';className=''; 1107 s_getcallernameext_test; 1108 self.verifyEqual(true,... 1109 isequal(methodName,'s_getcallernameext_test
')&&... 1110 isequal(className,'')); 1112 methodName='';className=''; 1113 getcallernameexttest.s_getcallernameext_test; 1114 self.verifyEqual(true,... 1115 isequal(methodName,'getcallernameexttest.s_getcallernameext_test
')&&... 1116 isequal(className,'')); 1118 [methodName,className]=getcallernameext_simplefunction(); 1119 self.verifyEqual(true,... 1120 isequal(methodName,'getcallernameext_simplefunction
')&&... 1121 isequal(className,'')); 1122 [methodName,className]=getcallernameext_subfunction(); 1123 self.verifyEqual(true,... 1124 isequal(methodName,'getcallernameext_subfunction/subfunction
')&&... 1125 isequal(className,'')); 1126 [methodName,className]=getcallernameext_subfunction2(); 1127 self.verifyEqual(true,... 1128 isequal(methodName,'getcallernameext_subfunction2/subfunction
')&&... 1129 isequal(className,'')); 1130 [methodName,className]=getcallernameext_subfunction3(); 1131 self.verifyEqual(true,... 1132 isequal(methodName,'getcallernameext_subfunction3/subfunction/subfunction2
')&&... 1133 isequal(className,'')); 1135 [methodName,className]=getcallernameexttest.getcallernameext_simplefunction(); 1136 self.verifyEqual(true,... 1137 isequal(methodName,'getcallernameexttest.getcallernameext_simplefunction
')&&... 1138 isequal(className,'')); 1139 [methodName,className]=getcallernameexttest.getcallernameext_subfunction(); 1140 self.verifyEqual(true,... 1141 isequal(methodName,'getcallernameexttest.getcallernameext_subfunction/subfunction
')&&... 1142 isequal(className,'')); 1143 [methodName,className]=getcallernameexttest.getcallernameext_subfunction2(); 1144 self.verifyEqual(true,... 1145 isequal(methodName,'getcallernameexttest.getcallernameext_subfunction2/subfunction
')&&... 1146 isequal(className,'')); 1147 [methodName,className]=getcallernameexttest.getcallernameext_subfunction3(); 1148 self.verifyEqual(true,... 1149 isequal(methodName,'getcallernameexttest.getcallernameext_subfunction3/subfunction/subfunction2
')&&... 1150 isequal(className,''));
function throwerror(in msgTag, in varargin)
THROWERROR works similarly to built-in ERROR function in case when there is no output arguments but s...
function absrelcompare(in leftArr, in rightArr, in absTol, in relTol, in fNormOp)
ABSRELCOMPARE - compares two numerical arrays by user defined norm. For each two corresponding fNormO...
function ind2submat(in sizeVec, in indVec)
IND2SUBMAT works similarly to the built-in ind2sub function but returns all the indices in a single m...
function iscelloffunc(in inpArray)
function iscellofstring(in inpArray)
function throwwarn(in msgTag, in varargin)
THROWWARN works similarly to built-in WARNING function in case when there is no output arguments but ...
function isstring(in inpArray)
function genfilename(in inpStr)
GENFILENAME generates a valid file name based on a given string.