Mercurial > hg > ltpda
comparison testing/utp_1.1/utps/ao/utp_ao_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_AO_GET a set of UTPs for the ao/get method | |
2 % | |
3 % M Hewitson 06-08-08 | |
4 % | |
5 % $Id: utp_ao_get.m,v 1.4 2011/03/29 13:03:28 ingo Exp $ | |
6 % | |
7 | |
8 % <MethodDescription> | |
9 % | |
10 % The get method of the ao class returns the value of an object | |
11 % property. This is a very simple method which accepts only one ao as | |
12 % input thus are the most general units test not possible. | |
13 % | |
14 % </MethodDescription> | |
15 | |
16 function results = utp_ao_get(varargin) | |
17 | |
18 % Check the inputs | |
19 if nargin == 0 | |
20 | |
21 % Some keywords | |
22 class = 'ao'; | |
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 ao | |
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 ao 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 AO. | |
135 % | |
136 % </SyntaxDescription> | |
137 | |
138 try | |
139 % <SyntaxCode> | |
140 aa = ao(plist('tsfcn', 'randn(size(t))', 'nsecs', 30, 'fs', 10)); | |
141 out1 = get(aa, 'data'); | |
142 out4 = get(aa, 'mdlfile'); | |
143 out6 = get(aa, 'procinfo'); | |
144 out7 = get(aa, 'plotinfo'); | |
145 out8 = get(aa, 'description'); | |
146 out10= get(aa, 'hist'); | |
147 out11= get(aa, 'name'); | |
148 % </SyntaxCode> | |
149 stest = true; | |
150 catch err | |
151 disp(err.message) | |
152 stest = false; | |
153 end | |
154 | |
155 % <AlgoDescription> | |
156 % | |
157 % 1) Check the correct value of the output | |
158 % | |
159 % </AlgoDescription> | |
160 | |
161 atest = true; | |
162 if stest | |
163 % <AlgoCode> | |
164 if ~eq(out1, aa.data), atest = false; end | |
165 if ~isequal(out4, aa.mdlfile), atest = false; end | |
166 if ~eq(out6, aa.procinfo), atest = false; end | |
167 if ~eq(out7, aa.plotinfo), atest = false; end | |
168 if ~isequal(out8, aa.description), atest = false; end | |
169 if ~eq(out10,aa.hist), atest = false; end | |
170 if ~isequal(out11,aa.name), atest = false; end | |
171 % </AlgoCode> | |
172 else | |
173 atest = false; | |
174 end | |
175 | |
176 % Return a result structure | |
177 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
178 end % END UTP_02 | |
179 | |
180 %% UTP_03 | |
181 | |
182 % <TestDescription> | |
183 % | |
184 % Tests that the get method works with a plist. | |
185 % | |
186 % </TestDescription> | |
187 function result = utp_03 | |
188 | |
189 % <SyntaxDescription> | |
190 % | |
191 % Test that the get returns returns the value of the specified | |
192 % property which is defined in a plist. | |
193 % | |
194 % </SyntaxDescription> | |
195 | |
196 try | |
197 % <SyntaxCode> | |
198 aa = ao(plist('tsfcn', 'randn(size(t))', 'nsecs', 30, 'fs', 10)); | |
199 pl1 = plist('property', 'data'); | |
200 pl4 = plist('property', 'mdlfile'); | |
201 pl6 = plist('property', 'procinfo'); | |
202 pl7 = plist('property', 'plotinfo'); | |
203 pl8 = plist('property', 'description'); | |
204 pl10= plist('property', 'hist'); | |
205 pl11= plist('property', 'name'); | |
206 out1 = get(aa, pl1); | |
207 out4 = get(aa, pl4); | |
208 out6 = get(aa, pl6); | |
209 out7 = get(aa, pl7); | |
210 out8 = get(aa, pl8); | |
211 out10= get(aa, pl10); | |
212 out11= get(aa, pl11); | |
213 % </SyntaxCode> | |
214 stest = true; | |
215 catch err | |
216 disp(err.message) | |
217 stest = false; | |
218 end | |
219 | |
220 % <AlgoDescription> | |
221 % | |
222 % 1) Check the correct value of the output | |
223 % | |
224 % </AlgoDescription> | |
225 | |
226 atest = true; | |
227 if stest | |
228 % <AlgoCode> | |
229 if ~eq(out1, aa.data), atest = false; end | |
230 if ~isequal(out4, aa.mdlfile), atest = false; end | |
231 if ~eq(out6, aa.procinfo), atest = false; end | |
232 if ~eq(out7, aa.plotinfo), atest = false; end | |
233 if ~isequal(out8, aa.description), atest = false; end | |
234 if ~eq(out10,aa.hist), atest = false; end | |
235 if ~isequal(out11,aa.name), atest = false; end | |
236 % </AlgoCode> | |
237 else | |
238 atest = false; | |
239 end | |
240 | |
241 % Return a result structure | |
242 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
243 end % END UTP_03 | |
244 | |
245 %% UTP_04 | |
246 | |
247 % <TestDescription> | |
248 % | |
249 % Tests the get method of the ao class. | |
250 % | |
251 % </TestDescription> | |
252 function result = utp_04 | |
253 | |
254 % <SyntaxDescription> | |
255 % | |
256 % Test that the get throws an error if the input are more than | |
257 % one AO. | |
258 % | |
259 % </SyntaxDescription> | |
260 | |
261 try | |
262 % <SyntaxCode> | |
263 aa = ao(plist('tsfcn', 'randn(size(t))', 'nsecs', 30, 'fs', 10)); | |
264 out = get([aa, aa], 'name'); | |
265 stest = false; | |
266 % </SyntaxCode> | |
267 catch | |
268 stest = true; | |
269 end | |
270 | |
271 % <AlgoDescription> | |
272 % | |
273 % 1) Nothing to test | |
274 % | |
275 % </AlgoDescription> | |
276 | |
277 atest = true; | |
278 if stest | |
279 % <AlgoCode> | |
280 % </AlgoCode> | |
281 else | |
282 atest = false; | |
283 end | |
284 | |
285 % Return a result structure | |
286 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
287 end % END UTP_04 | |
288 | |
289 end |