Mercurial > hg > ltpda
comparison testing/utp_1.1/utps/matrix/utp_matrix_matrix.m @ 44:409a22968d5e default
Add unit tests
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Tue, 06 Dec 2011 18:42:11 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
43:bc767aaa99a8 | 44:409a22968d5e |
---|---|
1 % UTP_MATRIX_MATRIX a set of UTPs for the matrix/matrix method | |
2 % | |
3 % M Hewitson 06-08-08 | |
4 % | |
5 % $Id: utp_matrix_matrix.m,v 1.6 2009/07/30 17:27:31 ingo Exp $ | |
6 % | |
7 | |
8 % <MethodDescription> | |
9 % | |
10 % The matrix method of the matrix class constructs MATRIX objects. | |
11 % | |
12 % </MethodDescription> | |
13 | |
14 function results = utp_matrix_matrix(varargin) | |
15 | |
16 % Check the inputs | |
17 if nargin == 0 | |
18 | |
19 % Some keywords | |
20 class = 'matrix'; | |
21 mthd = 'matrix'; | |
22 | |
23 results = []; | |
24 disp('******************************************************'); | |
25 disp(['**** Running UTPs for ' class '/' mthd]); | |
26 disp('******************************************************'); | |
27 | |
28 % Test MATRIX objects | |
29 [ma1,ma2,ma3,ma4,mav,mam] = get_test_objects_matrix; | |
30 | |
31 % Exception list for the UTPs: | |
32 [ple1,ple2,ple3,ple4,ple5,ple6] = get_test_ples(); | |
33 | |
34 % Run the tests | |
35 results = [results utp_01]; % getInfo call | |
36 results = [results utp_02(mthd, mav, [], [], ple3)]; % Vector input | |
37 results = [results utp_03(mthd, mam, [], [], ple3)]; % Matrix input | |
38 results = [results utp_04(mthd, ma1, ma2, ma3, [], [], ple3)]; % List input | |
39 results = [results utp_05(mthd, ma1, mav, mam, [], [], ple3)]; % Test with mixed input | |
40 results = [results utp_06(mthd, ma1, [], ple2)]; % Test history is working | |
41 | |
42 % Old format | |
43 results = [results utp_07]; % Test history is working with different numbers of input | |
44 | |
45 % constructor specific tests | |
46 results = [results utp_60(class, ma3, ple2)]; % Test history is properly handled with MAT file constructor | |
47 results = [results utp_61(class, ma1, ple2)]; % Test history is properly handled with XML file constructor | |
48 results = [results utp_62(class, ma1, ma2, ple2)]; % Test history is working with struct constructor | |
49 results = [results utp_64(class, ma1, ple1, ple2)]; % Test history is working with plist(filename) constructor | |
50 results = [results utp_65(class, ma1, ple3)]; % Test history is working with plist(hostname) constructor | |
51 results = [results utp_68(class, ma1, ple3)]; % Test history is working with conn+Id constructor | |
52 results = [results utp_70(class, ma1, ple2)]; % Test history is working with plist(plist) constructor | |
53 | |
54 disp('Done.'); | |
55 disp('******************************************************'); | |
56 | |
57 elseif nargin == 1 % Check for UTP functions | |
58 if strcmp(varargin{1}, 'isutp') | |
59 results = 1; | |
60 elseif strcmpi(varargin{1}, 'needs repository') | |
61 results = 2; | |
62 else | |
63 results = 0; | |
64 end | |
65 else | |
66 error('### Incorrect inputs') | |
67 end | |
68 | |
69 %% UTP_01 | |
70 | |
71 % <TestDescription> | |
72 % | |
73 % Tests that the getInfo call works for this method. | |
74 % | |
75 % </TestDescription> | |
76 function result = utp_01 | |
77 | |
78 | |
79 % <SyntaxDescription> | |
80 % | |
81 % Test that the getInfo call works for no sets, all sets, and each set | |
82 % individually. | |
83 % | |
84 % </SyntaxDescription> | |
85 | |
86 try | |
87 % <SyntaxCode> | |
88 % Call for no sets | |
89 io(1) = eval([class '.getInfo(''' mthd ''', ''None'')']); | |
90 % Call for all sets | |
91 io(2) = eval([class '.getInfo(''' mthd ''')']); | |
92 % Call for each set | |
93 for kk=1:numel(io(2).sets) | |
94 io(kk+2) = eval([class '.getInfo(''' mthd ''', ''' io(2).sets{kk} ''')']); | |
95 end | |
96 % </SyntaxCode> | |
97 stest = true; | |
98 catch err | |
99 disp(err.message) | |
100 stest = false; | |
101 end | |
102 | |
103 % <AlgoDescription> | |
104 % | |
105 % 1) Check that getInfo call returned an minfo object in all cases. | |
106 % 2) Check that all plists have the correct parameters. | |
107 % | |
108 % </AlgoDescription> | |
109 | |
110 atest = true; | |
111 if stest | |
112 % <AlgoCode> | |
113 % check we have minfo objects | |
114 if isa(io, 'minfo') | |
115 %%% SET 'None' | |
116 if ~isempty(io(1).sets), atest = false; end | |
117 if ~isempty(io(1).plists), atest = false; end | |
118 %%% Check all Sets | |
119 if ~any(strcmpi(io(2).sets, 'Default')), atest = false; end | |
120 if ~any(strcmpi(io(2).sets, 'From XML File')), atest = false; end | |
121 if ~any(strcmpi(io(2).sets, 'From MAT File')), atest = false; end | |
122 if ~any(strcmpi(io(2).sets, 'From Repository')), atest = false; end | |
123 if ~any(strcmpi(io(2).sets, 'From Built-in Model')), atest = false; end | |
124 if numel(io(2).plists) ~= numel(io(2).sets), atest = false; end | |
125 %%%%%%%%%% SET 'Default' | |
126 pn = 3; | |
127 if io(pn).plists.nparams ~= 5, atest = false; end | |
128 % Check key | |
129 if ~io(pn).plists.isparam('name'), atest = false; end | |
130 if ~io(pn).plists.isparam('description'), atest = false; end | |
131 if ~io(pn).plists.isparam('plotinfo'), atest = false; end | |
132 if ~io(pn).plists.isparam('shape'), atest = false; end | |
133 if ~io(pn).plists.isparam('objs'), atest = false; end | |
134 % Check default value | |
135 if ~isEmptyChar(io(pn).plists.find('name')), atest = false; end | |
136 if ~isEmptyChar(io(pn).plists.find('description')), atest = false; end | |
137 if ~isEmptyDouble(io(pn).plists.find('plotinfo')), atest = false; end | |
138 if ~isEmptyDouble(io(pn).plists.find('shape')), atest = false; end | |
139 if ~isEmptyDouble(io(pn).plists.find('objs')), atest = false; end | |
140 %%%%%%%%%% SET 'From MAT File' | |
141 pn = 4; | |
142 if io(pn).plists.nparams ~= 4, atest = false; end | |
143 % Check key | |
144 if ~io(pn).plists.isparam('name'), atest = false; end | |
145 if ~io(pn).plists.isparam('description'), atest = false; end | |
146 if ~io(pn).plists.isparam('plotinfo'), atest = false; end | |
147 if ~io(pn).plists.isparam('filename'), atest = false; end | |
148 % Check default value | |
149 if ~isEmptyChar(io(pn).plists.find('name')), atest = false; end | |
150 if ~isEmptyChar(io(pn).plists.find('description')), atest = false; end | |
151 if ~isEmptyDouble(io(pn).plists.find('plotinfo')), atest = false; end | |
152 if ~isEmptyChar(io(pn).plists.find('filename')), atest = false; end | |
153 %%%%%%%%%% SET 'From XML File' | |
154 pn = 5; | |
155 if io(pn).plists.nparams ~= 4, atest = false; end | |
156 % Check key | |
157 if ~io(pn).plists.isparam('name'), atest = false; end | |
158 if ~io(pn).plists.isparam('description'), atest = false; end | |
159 if ~io(pn).plists.isparam('plotinfo'), atest = false; end | |
160 if ~io(pn).plists.isparam('filename'), atest = false; end | |
161 % Check default value | |
162 if ~isEmptyChar(io(pn).plists.find('name')), atest = false; end | |
163 if ~isEmptyChar(io(pn).plists.find('description')), atest = false; end | |
164 if ~isEmptyDouble(io(pn).plists.find('plotinfo')), atest = false; end | |
165 if ~isEmptyChar(io(pn).plists.find('filename')), atest = false; end | |
166 %%%%%%%%%% SET 'From Repository' | |
167 pn = 6; | |
168 if io(pn).plists.nparams ~= 10, atest = false; end | |
169 % Check key | |
170 if ~io(pn).plists.isparam('name'), atest = false; end | |
171 if ~io(pn).plists.isparam('description'), atest = false; end | |
172 if ~io(pn).plists.isparam('plotinfo'), atest = false; end | |
173 if ~io(pn).plists.isparam('hostname'), atest = false; end | |
174 if ~io(pn).plists.isparam('id'), atest = false; end | |
175 if ~io(pn).plists.isparam('cid'), atest = false; end | |
176 if ~io(pn).plists.isparam('database'), atest = false; end | |
177 if ~io(pn).plists.isparam('binary'), atest = false; end | |
178 if ~io(pn).plists.isparam('username'), atest = false; end | |
179 if ~io(pn).plists.isparam('password'), atest = false; end | |
180 % Check default value | |
181 if ~isEmptyChar(io(pn).plists.find('name')), atest = false; end | |
182 if ~isEmptyChar(io(pn).plists.find('description')), atest = false; end | |
183 if ~isEmptyDouble(io(pn).plists.find('plotinfo')), atest = false; end | |
184 if ~isEmptyDouble(io(pn).plists.find('id')), atest = false; end | |
185 if ~isEmptyDouble(io(pn).plists.find('cid')), atest = false; end | |
186 if ~isequal(io(pn).plists.find('binary'), 'yes'), atest = false; end | |
187 %%%%%%%%%% SET 'From Built-in Model' | |
188 pn = 7; | |
189 if io(pn).plists.nparams ~= 4, atest = false; end | |
190 % Check key | |
191 if ~io(pn).plists.isparam('name'), atest = false; end | |
192 if ~io(pn).plists.isparam('description'), atest = false; end | |
193 if ~io(pn).plists.isparam('plotinfo'), atest = false; end | |
194 if ~io(pn).plists.isparam('built-in'), atest = false; end | |
195 % Check default value | |
196 if ~isEmptyChar(io(pn).plists.find('name')), atest = false; end | |
197 if ~isEmptyChar(io(pn).plists.find('description')), atest = false; end | |
198 if ~isEmptyDouble(io(pn).plists.find('plotinfo')), atest = false; end | |
199 if ~isEmptyChar(io(pn).plists.find('built-in')), atest = false; end | |
200 %%%%%%%%%% SET 'From Input' | |
201 pn = 8; | |
202 if io(pn).plists.nparams ~= 5, atest = false; end | |
203 % Check key | |
204 if ~io(pn).plists.isparam('name'), atest = false; end | |
205 if ~io(pn).plists.isparam('description'), atest = false; end | |
206 if ~io(pn).plists.isparam('plotinfo'), atest = false; end | |
207 if ~io(pn).plists.isparam('shape'), atest = false; end | |
208 if ~io(pn).plists.isparam('objs'), atest = false; end | |
209 % Check default value | |
210 if ~isEmptyChar(io(pn).plists.find('name')), atest = false; end | |
211 if ~isEmptyChar(io(pn).plists.find('description')), atest = false; end | |
212 if ~isEmptyDouble(io(pn).plists.find('plotinfo')), atest = false; end | |
213 if ~isEmptyDouble(io(pn).plists.find('shape')), atest = false; end | |
214 if ~isEmptyDouble(io(pn).plists.find('objs')), atest = false; end | |
215 end | |
216 % </AlgoCode> | |
217 else | |
218 atest = false; | |
219 end | |
220 | |
221 % Return a result structure | |
222 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
223 end % END UTP_01 | |
224 | |
225 %% UTP_07 | |
226 | |
227 % <TestDescription> | |
228 % | |
229 % Tests that the matrix method properly applies history to the | |
230 % constructor with different numbers of inputs. | |
231 % | |
232 % </TestDescription> | |
233 function result = utp_07 | |
234 | |
235 % <SyntaxDescription> | |
236 % | |
237 % Test that the output can be processed back with the rebuild method. | |
238 % | |
239 % </SyntaxDescription> | |
240 | |
241 try | |
242 % <SyntaxCode> | |
243 a1 = ao(1); | |
244 a2 = ao(2); | |
245 a3 = ao(3); | |
246 out1 = matrix(a1); | |
247 out2 = matrix(a1, a2); | |
248 out3 = matrix(a1, a2, a3); | |
249 mout1 = rebuild(out1); | |
250 mout2 = rebuild(out2); | |
251 mout3 = rebuild(out3); | |
252 % </SyntaxCode> | |
253 stest = true; | |
254 catch err | |
255 disp(err.message) | |
256 stest = false; | |
257 end | |
258 | |
259 % <AlgoDescription> | |
260 % | |
261 % 1) Check that the last entry in the history of 'out' corresponds to | |
262 % 'matrix'. | |
263 % 2) Check that the rebuilt objects are the same | |
264 % | |
265 % </AlgoDescription> | |
266 | |
267 atest = true; | |
268 if stest | |
269 % <AlgoCode> | |
270 % Check the last step in the history of 'out' | |
271 if ~strcmp(out1.hist.methodInfo.mname, 'matrix'), atest = false; end | |
272 if ~strcmp(out2.hist.methodInfo.mname, 'matrix'), atest = false; end | |
273 if ~strcmp(out3.hist.methodInfo.mname, 'matrix'), atest = false; end | |
274 % Check that output contains the right values | |
275 if ~eq(out1.objs, a1), atest = false; end | |
276 if ~eq(out2.objs, [a1, a2]), atest = false; end | |
277 if ~eq(out3.objs, [a1, a2, a3]), atest = false; end | |
278 % Check the rebuilt object | |
279 if ~eq(mout1, out1, ple2), atest = false; end | |
280 if ~eq(mout2, out2, ple2), atest = false; end | |
281 if ~eq(mout3, out3, ple2), atest = false; end | |
282 % </AlgoCode> | |
283 else | |
284 atest = false; | |
285 end | |
286 | |
287 % Return a result structure | |
288 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
289 end % END UTP_07 | |
290 | |
291 | |
292 end |