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