comparison testing/utp_1.1/utps/plist/utp_plist_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_PLIST_GET a set of UTPs for the plist/get method
2 %
3 % M Hewitson 06-08-08
4 %
5 % $Id: utp_plist_get.m,v 1.5 2011/03/29 13:03:29 ingo Exp $
6 %
7
8 % <MethodDescription>
9 %
10 % The get method of the plist class returns the value of an object
11 % property. This is a very simple method which accepts only one plist as
12 % input thus are the most general units test not possible.
13 %
14 % </MethodDescription>
15
16 function results = utp_plist_get(varargin)
17
18 % Check the inputs
19 if nargin == 0
20
21 % Some keywords
22 class = 'plist';
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 plist
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 plist 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 PLIST object.
135 %
136 % </SyntaxDescription>
137
138 try
139 % <SyntaxCode>
140 pl = plist('a', 1, 'b', 2, 'c', 3);
141 out1 = get(pl, 'params');
142 out5 = get(pl, 'name');
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 correct value of the output
153 %
154 % </AlgoDescription>
155
156 atest = true;
157 if stest
158 % <AlgoCode>
159 if ~eq(out1, pl.params), atest = false; end
160 if ~isequal(out5, pl.name), 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 that the get method works with a plist.
175 %
176 % </TestDescription>
177 function result = utp_03
178
179 % <SyntaxDescription>
180 %
181 % Test that the get returns returns the value of the specified
182 % property which is defined in a plist.
183 %
184 % </SyntaxDescription>
185
186 try
187 % <SyntaxCode>
188 pl = plist('a', 1, 'b', 2, 'c', 3);
189 pl1 = plist('property', 'params');
190 pl5 = plist('property', 'name');
191 out1 = get(pl, pl1);
192 out5 = get(pl, pl5);
193 % </SyntaxCode>
194 stest = true;
195 catch err
196 disp(err.message)
197 stest = false;
198 end
199
200 % <AlgoDescription>
201 %
202 % 1) Check the correct value of the output
203 %
204 % </AlgoDescription>
205
206 atest = true;
207 if stest
208 % <AlgoCode>
209 if ~eq(out1, pl.params), atest = false; end
210 if ~isequal(out5, pl.name), atest = false; end
211 % </AlgoCode>
212 else
213 atest = false;
214 end
215
216 % Return a result structure
217 result = utp_prepare_result(atest, stest, dbstack, mfilename);
218 end % END UTP_03
219
220 %% UTP_04
221
222 % <TestDescription>
223 %
224 % Tests the get method of the plist class.
225 %
226 % </TestDescription>
227 function result = utp_04
228
229 % <SyntaxDescription>
230 %
231 % Test that the get throws an error if the input are more than
232 % one PLIST object.
233 %
234 % </SyntaxDescription>
235
236 try
237 % <SyntaxCode>
238 pl = plist('a', 1, 'b', 2, 'c', 3);
239 out = get([pl, pl], 'name');
240 stest = false;
241 % </SyntaxCode>
242 catch
243 stest = true;
244 end
245
246 % <AlgoDescription>
247 %
248 % 1) Nothing to test
249 %
250 % </AlgoDescription>
251
252 atest = true;
253 if stest
254 % <AlgoCode>
255 % </AlgoCode>
256 else
257 atest = false;
258 end
259
260 % Return a result structure
261 result = utp_prepare_result(atest, stest, dbstack, mfilename);
262 end % END UTP_04
263
264 end