Mercurial > hg > ltpda
comparison testing/utp_1.1/utps/rational/utp_rational_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_RATIONAL_GETLOWERFREQ a set of UTPs for the rational/getlowerFreq method | |
2 % | |
3 % M Hewitson 06-08-08 | |
4 % | |
5 % $Id: utp_rational_getlowerFreq.m,v 1.2 2009/07/27 19:28:59 ingo Exp $ | |
6 % | |
7 | |
8 % <MethodDescription> | |
9 % | |
10 % The getlowerFreq method of the rational class gets the frequency of the | |
11 % lowest pole in the model. This is a very simple method which accepts only | |
12 % one rational as input thus are the most general units test not possible. | |
13 % | |
14 % </MethodDescription> | |
15 | |
16 function results = utp_rational_getlowerFreq(varargin) | |
17 | |
18 % Check the inputs | |
19 if nargin == 0 | |
20 | |
21 % Some keywords | |
22 class = 'rational'; | |
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 rational | |
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 rational 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 rational object. | |
131 % | |
132 % </SyntaxDescription> | |
133 | |
134 try | |
135 % <SyntaxCode> | |
136 p1 = pz(3,2); % f = 3 | |
137 p2 = pz(40); % f = 40 | |
138 z3 = pz(2,3); % f = 2 | |
139 z4 = pz(100); % f = 100 | |
140 pzm = pzmodel(10, [p1 p2], [z3 z4]); | |
141 ra = rational(pzm); | |
142 out = getlowerFreq(ra); | |
143 % </SyntaxCode> | |
144 stest = true; | |
145 catch err | |
146 disp(err.message) | |
147 stest = false; | |
148 end | |
149 | |
150 % <AlgoDescription> | |
151 % | |
152 % 1) Check the output | |
153 % | |
154 % </AlgoDescription> | |
155 | |
156 atest = true; | |
157 TOL = 1e-15; | |
158 if stest | |
159 % <AlgoCode> | |
160 if abs(out-2)>TOL, atest = false; end | |
161 % </AlgoCode> | |
162 else | |
163 atest = false; | |
164 end | |
165 | |
166 % Return a result structure | |
167 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
168 end % END UTP_02 | |
169 | |
170 %% UTP_03 | |
171 | |
172 % <TestDescription> | |
173 % | |
174 % Tests the getlowerFreq method of the rational class. | |
175 % | |
176 % </TestDescription> | |
177 function result = utp_03 | |
178 | |
179 % <SyntaxDescription> | |
180 % | |
181 % Test that the getlowerFreq throws an error if the input are more than | |
182 % one rational. | |
183 % | |
184 % </SyntaxDescription> | |
185 | |
186 try | |
187 % <SyntaxCode> | |
188 p1 = pz(3,2); % f = 3 | |
189 p2 = pz(40); % f = 40 | |
190 z3 = pz(2,3); % f = 2 | |
191 z4 = pz(100); % f = 100 | |
192 pzm = pzmodel(10, [p1 p2], [z3 z4]); | |
193 ra = rational(pzm); | |
194 out = getlowerFreq([ra, ra]); | |
195 stest = false; | |
196 % </SyntaxCode> | |
197 catch | |
198 stest = true; | |
199 end | |
200 | |
201 % <AlgoDescription> | |
202 % | |
203 % 1) Nothing to test | |
204 % | |
205 % </AlgoDescription> | |
206 | |
207 atest = true; | |
208 if stest | |
209 % <AlgoCode> | |
210 % </AlgoCode> | |
211 else | |
212 atest = false; | |
213 end | |
214 | |
215 % Return a result structure | |
216 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
217 end % END UTP_03 | |
218 | |
219 end |