Mercurial > hg > ltpda
comparison testing/utp_1.1/utps/miir/utp_miir_get.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_MIIR_GET a set of UTPs for the miir/get method | |
2 % | |
3 % M Hewitson 06-08-08 | |
4 % | |
5 % $Id: utp_miir_get.m,v 1.3 2011/03/29 13:03:29 ingo Exp $ | |
6 % | |
7 | |
8 % <MethodDescription> | |
9 % | |
10 % The get method of the miir class returns the value of an object | |
11 % property. This is a very simple method which accepts only one miir as | |
12 % input thus are the most general units test not possible. | |
13 % | |
14 % </MethodDescription> | |
15 | |
16 function results = utp_miir_get(varargin) | |
17 | |
18 % Check the inputs | |
19 if nargin == 0 | |
20 | |
21 % Some keywords | |
22 class = 'miir'; | |
23 mthd = 'get'; | |
24 | |
25 results = []; | |
26 disp('******************************************************'); | |
27 disp(['**** Running UTPs for ' class '/' mthd]); | |
28 disp('******************************************************'); | |
29 | |
30 % Exception list for the UTPs: | |
31 [ple1,ple2,ple3,ple4,ple5,ple6] = get_test_ples(); | |
32 | |
33 % Run the tests | |
34 results = [results utp_01]; % getInfo call | |
35 results = [results utp_02]; % Algorithm test | |
36 results = [results utp_03]; % Algorithm test with a plist | |
37 results = [results utp_04]; % Negative test with more than one miir | |
38 | |
39 disp('Done.'); | |
40 disp('******************************************************'); | |
41 | |
42 elseif nargin == 1 % Check for UTP functions | |
43 if strcmp(varargin{1}, 'isutp') | |
44 results = 1; | |
45 else | |
46 results = 0; | |
47 end | |
48 else | |
49 error('### Incorrect inputs') | |
50 end | |
51 | |
52 %% UTP_01 | |
53 | |
54 % <TestDescription> | |
55 % | |
56 % Tests that the getInfo call works for this method. | |
57 % | |
58 % </TestDescription> | |
59 function result = utp_01 | |
60 | |
61 | |
62 % <SyntaxDescription> | |
63 % | |
64 % Test that the getInfo call works for no sets, all sets, and each set | |
65 % individually. | |
66 % | |
67 % </SyntaxDescription> | |
68 | |
69 try | |
70 % <SyntaxCode> | |
71 % Call for no sets | |
72 io(1) = eval([class '.getInfo(''' mthd ''', ''None'')']); | |
73 % Call for all sets | |
74 io(2) = eval([class '.getInfo(''' mthd ''')']); | |
75 % Call for each set | |
76 for kk=1:numel(io(2).sets) | |
77 io(kk+2) = eval([class '.getInfo(''' mthd ''', ''' io(2).sets{kk} ''')']); | |
78 end | |
79 % </SyntaxCode> | |
80 stest = true; | |
81 catch err | |
82 disp(err.message) | |
83 stest = false; | |
84 end | |
85 | |
86 % <AlgoDescription> | |
87 % | |
88 % 1) Check that getInfo call returned an minfo object in all cases. | |
89 % 2) Check that all plists have the correct parameters. | |
90 % | |
91 % </AlgoDescription> | |
92 | |
93 atest = true; | |
94 if stest | |
95 % <AlgoCode> | |
96 % check we have minfo objects | |
97 if isa(io, 'minfo') | |
98 %%% SET 'None' | |
99 if ~isempty(io(1).sets), atest = false; end | |
100 if ~isempty(io(1).plists), atest = false; end | |
101 %%% Check all Sets | |
102 if ~any(strcmpi(io(2).sets, 'Default')), atest = false; end | |
103 if numel(io(2).plists) ~= numel(io(2).sets), atest = false; end | |
104 %%%%%%%%%% SET 'Default' | |
105 if io(3).plists.nparams ~= 1, atest = false; end | |
106 % Check key | |
107 if ~io(3).plists.isparam('property'), atest = false; end | |
108 % Check default value | |
109 if ~isEmptyChar(io(3).plists.find('property')), atest = false; end | |
110 % Check options | |
111 if ~isequal(io(3).plists.getOptionsForParam('property'), {''}), atest = false; end | |
112 end | |
113 % </AlgoCode> | |
114 else | |
115 atest = false; | |
116 end | |
117 | |
118 % Return a result structure | |
119 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
120 end % END UTP_01 | |
121 | |
122 %% UTP_02 | |
123 | |
124 % <TestDescription> | |
125 % | |
126 % Tests the get method of the miir class. | |
127 % | |
128 % </TestDescription> | |
129 function result = utp_02 | |
130 | |
131 % <SyntaxDescription> | |
132 % | |
133 % Test that the get returns returns the value of the specified | |
134 % property. Do this for all properties of the MIIR object. | |
135 % | |
136 % </SyntaxDescription> | |
137 | |
138 try | |
139 % <SyntaxCode> | |
140 iir = miir(plist('type', 'lowpass')); | |
141 out1 = get(iir, 'b'); | |
142 out2 = get(iir, 'histin'); | |
143 out4 = get(iir, 'ntaps'); | |
144 out5 = get(iir, 'fs'); | |
145 out6 = get(iir, 'infile'); | |
146 out7 = get(iir, 'a'); | |
147 out8 = get(iir, 'histout'); | |
148 out9 = get(iir, 'iunits'); | |
149 out10= get(iir, 'ounits'); | |
150 out11= get(iir, 'hist'); | |
151 out12= get(iir, 'name'); | |
152 % </SyntaxCode> | |
153 stest = true; | |
154 catch err | |
155 disp(err.message) | |
156 stest = false; | |
157 end | |
158 | |
159 % <AlgoDescription> | |
160 % | |
161 % 1) Check the correct value of the output | |
162 % | |
163 % </AlgoDescription> | |
164 | |
165 atest = true; | |
166 if stest | |
167 % <AlgoCode> | |
168 if ~isequal(out1, iir.b), atest = false; end | |
169 if ~isequal(out2, iir.histin), atest = false; end | |
170 if ~isequal(out4, iir.ntaps), atest = false; end | |
171 if ~isequal(out5, iir.fs), atest = false; end | |
172 if ~isequal(out6, iir.infile), atest = false; end | |
173 if ~isequal(out7, iir.a), atest = false; end | |
174 if ~isequal(out8, iir.histout), atest = false; end | |
175 if ~eq(out9, iir.iunits), atest = false; end | |
176 if ~eq(out10,iir.ounits), atest = false; end | |
177 if ~eq(out11,iir.hist), atest = false; end | |
178 if ~isequal(out12,iir.name), atest = false; end | |
179 % </AlgoCode> | |
180 else | |
181 atest = false; | |
182 end | |
183 | |
184 % Return a result structure | |
185 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
186 end % END UTP_02 | |
187 | |
188 %% UTP_03 | |
189 | |
190 % <TestDescription> | |
191 % | |
192 % Tests that the get method works with a plist. | |
193 % | |
194 % </TestDescription> | |
195 function result = utp_03 | |
196 | |
197 % <SyntaxDescription> | |
198 % | |
199 % Test that the get returns returns the value of the specified | |
200 % property which is defined in a plist. | |
201 % | |
202 % </SyntaxDescription> | |
203 | |
204 try | |
205 % <SyntaxCode> | |
206 iir = miir(plist('type', 'lowpass')); | |
207 pl1 = plist('property', 'b'); | |
208 pl2 = plist('property', 'histin'); | |
209 pl4 = plist('property', 'ntaps'); | |
210 pl5 = plist('property', 'fs'); | |
211 pl6 = plist('property', 'infile'); | |
212 pl7 = plist('property', 'a'); | |
213 pl8 = plist('property', 'histout'); | |
214 pl9 = plist('property', 'iunits'); | |
215 pl10= plist('property', 'ounits'); | |
216 pl11= plist('property', 'hist'); | |
217 pl12= plist('property', 'name'); | |
218 out1 = get(iir, pl1); | |
219 out2 = get(iir, pl2); | |
220 out4 = get(iir, pl4); | |
221 out5 = get(iir, pl5); | |
222 out6 = get(iir, pl6); | |
223 out7 = get(iir, pl7); | |
224 out8 = get(iir, pl8); | |
225 out9 = get(iir, pl9); | |
226 out10= get(iir, pl10); | |
227 out11= get(iir, pl11); | |
228 out12= get(iir, pl12); | |
229 % </SyntaxCode> | |
230 stest = true; | |
231 catch err | |
232 disp(err.message) | |
233 stest = false; | |
234 end | |
235 | |
236 % <AlgoDescription> | |
237 % | |
238 % 1) Check the correct value of the output | |
239 % | |
240 % </AlgoDescription> | |
241 | |
242 atest = true; | |
243 if stest | |
244 % <AlgoCode> | |
245 if ~isequal(out1, iir.b), atest = false; end | |
246 if ~isequal(out2, iir.histin), atest = false; end | |
247 if ~isequal(out4, iir.ntaps), atest = false; end | |
248 if ~isequal(out5, iir.fs), atest = false; end | |
249 if ~isequal(out6, iir.infile), atest = false; end | |
250 if ~isequal(out7, iir.a), atest = false; end | |
251 if ~isequal(out8, iir.histout), atest = false; end | |
252 if ~eq(out9, iir.iunits), atest = false; end | |
253 if ~eq(out10,iir.ounits), atest = false; end | |
254 if ~eq(out11,iir.hist), atest = false; end | |
255 if ~isequal(out12,iir.name), atest = false; end | |
256 % </AlgoCode> | |
257 else | |
258 atest = false; | |
259 end | |
260 | |
261 % Return a result structure | |
262 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
263 end % END UTP_03 | |
264 | |
265 %% UTP_04 | |
266 | |
267 % <TestDescription> | |
268 % | |
269 % Tests the get method of the miir class. | |
270 % | |
271 % </TestDescription> | |
272 function result = utp_04 | |
273 | |
274 % <SyntaxDescription> | |
275 % | |
276 % Test that the get throws an error if the input are more than | |
277 % one MIIR object. | |
278 % | |
279 % </SyntaxDescription> | |
280 | |
281 try | |
282 % <SyntaxCode> | |
283 iir = miir(plist('type', 'lowpass')); | |
284 out = get([iir, iir], 'name'); | |
285 stest = false; | |
286 % </SyntaxCode> | |
287 catch | |
288 stest = true; | |
289 end | |
290 | |
291 % <AlgoDescription> | |
292 % | |
293 % 1) Nothing to test | |
294 % | |
295 % </AlgoDescription> | |
296 | |
297 atest = true; | |
298 if stest | |
299 % <AlgoCode> | |
300 % </AlgoCode> | |
301 else | |
302 atest = false; | |
303 end | |
304 | |
305 % Return a result structure | |
306 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
307 end % END UTP_04 | |
308 | |
309 end |