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