comparison testing/utp_1.1/utps/parfrac/utp_parfrac_getlowerFreq.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_GETLOWERFREQ a set of UTPs for the parfrac/getlowerFreq method
2 %
3 % M Hewitson 06-08-08
4 %
5 % $Id: utp_parfrac_getlowerFreq.m,v 1.3 2011/04/04 13:39:11 ingo Exp $
6 %
7
8 % <MethodDescription>
9 %
10 % The getlowerFreq method of the parfrac class gets the frequency of the
11 % lowest pole in the model. This is a very simple method which accepts only
12 % one parfrac as input thus are the most general units test not possible.
13 %
14 % </MethodDescription>
15
16 function results = utp_parfrac_getlowerFreq(varargin)
17
18 % Check the inputs
19 if nargin == 0
20
21 % Some keywords
22 class = 'parfrac';
23 mthd = 'getlowerFreq';
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]; % Negative test with more than one parfrac
37
38 disp('Done.');
39 disp('******************************************************');
40
41 elseif nargin == 1 % Check for UTP functions
42 if strcmp(varargin{1}, 'isutp')
43 results = 1;
44 else
45 results = 0;
46 end
47 else
48 error('### Incorrect inputs')
49 end
50
51 %% UTP_01
52
53 % <TestDescription>
54 %
55 % Tests that the getInfo call works for this method.
56 %
57 % </TestDescription>
58 function result = utp_01
59
60
61 % <SyntaxDescription>
62 %
63 % Test that the getInfo call works for no sets, all sets, and each set
64 % individually.
65 %
66 % </SyntaxDescription>
67
68 try
69 % <SyntaxCode>
70 % Call for no sets
71 io(1) = eval([class '.getInfo(''' mthd ''', ''None'')']);
72 % Call for all sets
73 io(2) = eval([class '.getInfo(''' mthd ''')']);
74 % Call for each set
75 for kk=1:numel(io(2).sets)
76 io(kk+2) = eval([class '.getInfo(''' mthd ''', ''' io(2).sets{kk} ''')']);
77 end
78 % </SyntaxCode>
79 stest = true;
80 catch err
81 disp(err.message)
82 stest = false;
83 end
84
85 % <AlgoDescription>
86 %
87 % 1) Check that getInfo call returned an minfo object in all cases.
88 % 2) Check that all plists have the correct parameters.
89 %
90 % </AlgoDescription>
91
92 atest = true;
93 if stest
94 % <AlgoCode>
95 % check we have minfo objects
96 if isa(io, 'minfo')
97 % SET 'None'
98 if ~isempty(io(1).sets), atest = false; end
99 if ~isempty(io(1).plists), atest = false; end
100 % Check all Sets
101 if ~any(strcmpi(io(2).sets, 'Default')), atest = false; end
102 if numel(io(2).plists) ~= numel(io(2).sets), atest = false; end
103 % SET 'Default'
104 if io(3).plists.nparams ~= 0, atest = false; end
105 % Check key
106 % Check default value
107 % Check options
108 end
109 % </AlgoCode>
110 else
111 atest = false;
112 end
113
114 % Return a result structure
115 result = utp_prepare_result(atest, stest, dbstack, mfilename);
116 end % END UTP_01
117
118 %% UTP_02
119
120 % <TestDescription>
121 %
122 % Tests the getlowerFreq method of the parfrac class.
123 %
124 % </TestDescription>
125 function result = utp_02
126
127 % <SyntaxDescription>
128 %
129 % Test that the getlowerFreq returns the lowest frequence of the pole
130 % in the parfrac object.
131 %
132 % </SyntaxDescription>
133
134 try
135 % <SyntaxCode>
136 p1 = pz(3,2); % f = 3
137 p2 = pz(40); % f = 40
138 p3 = pz(2,3); % f = 2
139 p4 = pz(100); % f = 100
140 pole_ri = [p1.ri.', p2.ri.', p3.ri.', p4.ri.'];
141 res = [1 2 3 4 5 6];
142 pf = parfrac(res, pole_ri);
143 out = getlowerFreq(pf);
144 % </SyntaxCode>
145 stest = true;
146 catch err
147 disp(err.message)
148 stest = false;
149 end
150
151 % <AlgoDescription>
152 %
153 % 1) Check the output
154 %
155 % </AlgoDescription>
156
157 atest = true;
158 TOL = 1e-15;
159 if stest
160 % <AlgoCode>
161 if abs(out-2)>TOL, atest = false; end
162 % </AlgoCode>
163 else
164 atest = false;
165 end
166
167 % Return a result structure
168 result = utp_prepare_result(atest, stest, dbstack, mfilename);
169 end % END UTP_02
170
171 %% UTP_03
172
173 % <TestDescription>
174 %
175 % Tests the getlowerFreq method of the parfrac class.
176 %
177 % </TestDescription>
178 function result = utp_03
179
180 % <SyntaxDescription>
181 %
182 % Test that the getlowerFreq throws an error if the input are more than
183 % one parfrac.
184 %
185 % </SyntaxDescription>
186
187 try
188 % <SyntaxCode>
189 p1 = pz(3,2); % f = 3
190 p2 = pz(40); % f = 40
191 p3 = pz(2,3); % f = 2
192 p4 = pz(100); % f = 100
193 pole_ri = [p1.ri.', p2.ri.', p3.ri.', p4.ri.'];
194 res = [1 2 3 4 5 6];
195 pf = parfrac(res, pole_ri, []);
196 out = getlowerFreq([pf, pf]);
197 stest = false;
198 % </SyntaxCode>
199 catch
200 stest = true;
201 end
202
203 % <AlgoDescription>
204 %
205 % 1) Nothing to test
206 %
207 % </AlgoDescription>
208
209 atest = true;
210 if stest
211 % <AlgoCode>
212 % </AlgoCode>
213 else
214 atest = false;
215 end
216
217 % Return a result structure
218 result = utp_prepare_result(atest, stest, dbstack, mfilename);
219 end % END UTP_03
220
221 end