3 function self = CreateArraySuite(varargin)
6 function self = test_checkvaluematchisnull_mixedcell_sametype(
self)
7 value={{1 2 3};{1,2};{1}};
10 self.verifyEqual(isOk,
true);
13 function self = test_checkvaluematchisnull_mixedcell_differenttype(
self)
14 value={{1 2 3};{
'a',
'b'};{1}};
17 self.verifyEqual(isOk,
false);
20 function aux_test_classname2typeinfo(
self,typeList,sizeCVec)
21 for iSize=1:length(sizeCVec)
22 sizeVec=sizeCVec{iSize};
27 STypeInfoCheckVec,
'UniformOutput',
false);
33 isEqualVec=cellfun(@isequal,
num2cell(STypeInfoVec),...
36 self.verifyEqual(all(isEqualVec),...
37 true,[
'failed for size ',num2str(sizeVec)]);
40 function self=test_classname2typeinfo(
self)
42 self.aux_test_classname2typeinfo(
self.typeList,sizeCVec);
47 function self=test_typeinfo2classname(
self)
48 typeList=self.typeList;
53 num2cell(STypeInfoCheckVec),'UniformOutput',false);
54 self.verifyEqual(true,isequal(typeList,resTypeList));
57 function aux_test_generatetypeinfostruct(self,typeList,sizeCVec,isRelaxedComparison)
59 isRelaxedComparison=false;
61 for iSize=1:length(sizeCVec)
62 sizeVec=sizeCVec{iSize};
67 STypeInfoCheckVec,
'UniformOutput',
false);
69 [isUniformVec,STypeInfoVec]=...
73 self.verifyEqual(all(isUniformVec),
true);
75 if isRelaxedComparison
76 fCompare=@isequal_relaxed;
80 isEqualVec=arrayfun(fCompare,STypeInfoVec,STypeInfoCheckVec);
82 self.verifyEqual(all(isEqualVec),
true,...
83 [
'failed for size ',mat2str(sizeVec)]);
85 function isPositive=isequal_relaxed(s1,s2)
87 isPositive=s1.depth<=s2.depth;
89 isPositive=isequal(s1,s2);
93 function self=test_generatetypeinfostruct(self)
95 self.aux_test_generatetypeinfostruct(
self.typeList,sizeCVec);
97 self.aux_test_generatetypeinfostruct(
self.typeList,sizeCVec,
true);
100 function self=test_generatetypeinfostruct_mixedtype(
self)
101 objCell={{{[1 2 3],{
'aa',
'bb'}};{[1 2],[3 4]}}};
104 [isUniformCheckVec,STypeInfoCheckVec]=...
109 [isUniformVec,STypeInfoVec]=...
113 self.verifyEqual(isUniformCheckVec,isUniformVec);
114 if any(isUniformVec)&&isequal(isUniformCheckVec,isUniformVec)
115 isEqualVec=arrayfun(@isequal,STypeInfoVec(isUniformVec),STypeInfoCheckVec(isUniformVec));
116 self.verifyEqual(all(isEqualVec),
true);
120 function self=test_createarraybytypesizeinfo(
self)
121 sizeCVec=self.sizeCVec;
122 typeList=self.typeList;
123 for iSize=1:length(sizeCVec)
124 sizeVec=sizeCVec{iSize};
125 STypeInfoCheckVec=cellfun(...
131 STypeInfoCheckVec,
'UniformOutput',
false);
133 isOkVec=cellfun(@(x)isequal(size(x),sizeVec),...
135 self.verifyEqual(
true,all(isOkVec));
137 STypeSizeInfoVec=cellfun(...
143 STypeSizeInfoVec,
'UniformOutput',
false);
144 self.verifyEqual(isequal(objCell,obj2Cell),...
145 true,[
'failed for size ',num2str(sizeVec)]);
148 function self=test_createvaluearray(
self)
149 sizeCVec=self.sizeCVec;
150 typeList=self.typeList;
151 for iSize=1:length(sizeCVec)
153 sizeVec=sizeCVec{iSize};
154 STypeInfoCheckVec=cellfun(...
161 STypeInfoCheckVec,
'UniformOutput',
false);
163 isOkVec=cellfun(@(x)isequal(size(x),sizeVec),...
165 self.verifyEqual(
true,all(isOkVec));
167 objEthalonCell=arrayfun(...
170 STypeInfoCheckVec,
'UniformOutput',
false);
172 obj2Cell=arrayfun(...
175 typeList,objEthalonCell,
'UniformOutput',
false);
177 self.verifyEqual(
true,isequann(objCell,obj2Cell));
180 function self=test_createvaluearray_handleType(
self)
183 '
mxberry.core.type.test.TestHandleType',[nElem 1]);
185 '
mxberry.core.type.test.TestHandleType',...
186 mxberry.core.type.test.TestHandleType,[nElem 1]);
188 obj1Vec(1).setValue(value);
189 obj2Vec(1).setValue(value);
190 obj2Vec(1).setValue(value);
192 self.verifyEqual(false,...
193 isequal(obj1Vec(1),obj1Vec(iElem)));
196 self.verifyEqual(true,isequaln(obj1Vec,obj2Vec));
198 function self=test_createarraybytypeinfo_redundancy(self)
199 sizeCVec=self.sizeCVec;
200 typeList=self.typeList;
201 for iSize=1:length(sizeCVec)
203 sizeVec=sizeCVec{iSize};
204 STypeInfoCheckVec=cellfun(...
211 STypeInfoCheckVec,
'UniformOutput',
false);
212 isOkVec=cellfun(@checkRedundancy,objCell);
213 self.verifyEqual(
true,all(isOkVec));
215 function isOk=checkRedundancyNested(inpArray)
217 isOkArray=cellfun(@checkRedundancyNested,inpArray);
218 isOk=all(isOkArray(:));
220 isOk=isempty(inpArray);
223 function isOk=checkRedundancy(inpArray)
225 isOk=checkRedundancyNested(inpArray);
231 function self=test_generatetypeinfostruct_Precise(
self)
232 self.checkGenTypeInfo({},
true,1,
'');
233 self.checkGenTypeInfo({{}},
true,2,
'');
234 self.checkGenTypeInfo({{},{}},
true,2,
'');
235 self.checkGenTypeInfo({{},{{}}},
true,3,
'');
236 self.checkGenTypeInfo({{1},{2}},
true,2,
'double');
237 self.checkGenTypeInfo({{1},{}},
true,2,
'double');
238 self.checkGenTypeInfo({{
'1'},{
'2'}},
true,2,
'char');
239 self.checkGenTypeInfo({{},{{1}},{}},
true,3,
'double');
240 self.checkGenTypeInfo(1,
true,0,
'double');
242 self.checkGenTypeInfo({{1},{{}}},
false);
243 self.checkGenTypeInfo({{1},{{1}}},
false);
244 self.checkGenTypeInfo({{1},{
'a'}},
false);
245 self.checkGenTypeInfo({{{
'a'}},{
'a'}},
false);
246 self.checkGenTypeInfo({{1},{
true}},
false);
248 function self=checkGenTypeInfo(
self,value,isUniformExp,expDepth,expType)
254 STypeInfoExp=
struct(
'type',expType,
'depth',expDepth);
255 [isUniform,STypeInfo]=...
257 self.verifyEqual(isUniformExp,isUniform);
258 self.verifyEqual(
true,isequaln(STypeInfoExp,STypeInfo));
261 function self=test_createarray_negative(
self)
262 inpArgCombList={{{
'int8'},[1 2]},...
266 for iArgComb=1:length(inpArgCombList)
267 self.runAndCheckError(...
268 'mxberry.core.type.createarray(inpArgCombList{iArgComb})',...
272 function self=test_createarray(
self)
274 sizeCVec=[self.sizeCVec,{[]}];
275 typeList=
self.simpleTypeNoCharList;
276 for iSize=1:length(sizeCVec)
277 for iType=1:length(typeList)
278 className=typeList{iType}{1};
279 errorMsg=sprintf(
'failed for type %s and size %s',...
280 className,mat2str(sizeCVec{iSize}));
284 className,sizeCVec{iSize});
288 newObj=addCause(newObj,meObj);
293 self.verifyEqual(
true,...
295 sizeCVec{iSize}),errorMsg);
297 self.verifyEqual(
true,...
298 isa(resArray,className),errorMsg);
function num2cell(in inpArray, in varargin)
NUM2CELL is an extension of Matlab built-in function "num2cell" designed to work correctly with empty...
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 createarray(in className, in sizeVec)
CREATEARRAY creates an array of specified size and type filling it with some values.
function createvaluearray(in className, in value, in sizeVec)
CREATEVALUEARRAY is designed for creating arrays of a specified type and size filled with a specified...
function generatetypeinfostruct(in value)
GENERATETYPEINFOSTRUCT constructs a meta structure containing a complete (recursive for cells) inform...
function classname2typeinfo(in classNameList)
CLASSNAME2TYPEINFO translates built-in class names into STypeInfo definitions.
function typeinfo2classname(in STypeInfo)