comparison testing/utp_1.1/utps/smodel/utp_smodel_smodel.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_SMODEL_SMODEL a set of UTPs for the smodel/smodel method
2 %
3 % M Hewitson 06-08-08
4 %
5 % $Id: utp_ssm_ssm.m,v 1.4 2009/08/07 07:31:46 hewitson Exp $
6 %
7
8 % <MethodDescription>
9 %
10 % The smodel method of the smodel class constructs smodel objects.
11 %
12 % </MethodDescription>
13
14 function results = utp_smodel_smodel(varargin)
15
16 % Check the inputs
17 if nargin == 0
18
19 % Some keywords
20 class = 'smodel';
21 mthd = 'smodel';
22
23 results = [];
24 disp('******************************************************');
25 disp(['**** Running UTPs for ' class '/' mthd]);
26 disp('******************************************************');
27
28 % Test objects
29 sm1 = smodel('a');
30 sm1.setName;
31 sm2 = smodel('a+b');
32 sm2.setName;
33
34 % Exception list for the UTPs:
35 [ple1,ple2,ple3,ple4,ple5,ple6] = get_test_ples();
36
37 % Run the general tests
38 results = [results utp_01]; % getInfo call
39 results = [results utp_02(mthd, [sm1 sm2 sm1], [], [], ple3)]; % Vector input
40 results = [results utp_03(mthd, [sm1 sm2 sm1; sm2 sm2 sm1], [], [], ple3)]; % Matrix input
41 results = [results utp_04(mthd, sm1, sm2, sm1, [], [], ple3)]; % List input
42 results = [results utp_05(mthd, sm1, [sm1 sm2], [sm1 sm2 sm1; sm2 sm2 sm1], [], [], ple3)]; % Test with mixed input
43 results = [results utp_06(mthd, sm1, [], ple2)]; % Test history is working
44 results = [results utp_07]; % Read older MAT-files
45 % constructor specific tests
46 results = [results utp_60(class, sm1, ple2)]; % Test history is properly handled with MAT file constructor
47 results = [results utp_61(class, sm1, ple2)]; % Test history is properly handled with XML file constructor
48 results = [results utp_62(class, sm1, sm2, ple2)]; % Test history is working with struct constructor
49 results = [results utp_64(class, sm1, ple2, ple2)]; % Test history is working with plist(filename) constructor
50 results = [results utp_65(class, sm2, ple3)]; % Test history is working with plist(hostname) constructor
51 results = [results utp_68(class, sm1, ple3)]; % Test history is working with conn+Id constructor
52
53 disp('Done.');
54 disp('******************************************************');
55
56 elseif nargin == 1 % Check for UTP functions
57 if strcmp(varargin{1}, 'isutp')
58 results = 1;
59 elseif strcmpi(varargin{1}, 'needs repository')
60 results = 2;
61 else
62 results = 0;
63 end
64 else
65 error('### Incorrect inputs')
66 end
67
68 %% UTP_01
69
70 % <TestDescription>
71 %
72 % Tests that the getInfo call works for this method.
73 %
74 % </TestDescription>
75 function result = utp_01
76
77
78 % <SyntaxDescription>
79 %
80 % Test that the getInfo call works for no sets, all sets, and each set
81 % individually.
82 %
83 % </SyntaxDescription>
84
85 try
86 % <SyntaxCode>
87 % Call for no sets
88 io(1) = eval([class '.getInfo(''' mthd ''', ''None'')']);
89 % Call for all sets
90 io(2) = eval([class '.getInfo(''' mthd ''')']);
91 % Call for each set
92 for kk=1:numel(io(2).sets)
93 io(kk+2) = eval([class '.getInfo(''' mthd ''', ''' io(2).sets{kk} ''')']);
94 end
95 % </SyntaxCode>
96 stest = true;
97 catch err
98 disp(err.message)
99 stest = false;
100 end
101
102 % <AlgoDescription>
103 %
104 % 1) Check that getInfo call returned an minfo object in all cases.
105 % 2) Check that all plists have the correct parameters.
106 %
107 % </AlgoDescription>
108
109 atest = true;
110 if stest
111 % <AlgoCode>
112 % check we have minfo objects
113 if isa(io, 'minfo')
114 %%% SET 'None'
115 if ~isempty(io(1).sets), atest = false; end
116 if ~isempty(io(1).plists), atest = false; end
117 %%% Check all Sets
118 if ~any(strcmpi(io(2).sets, 'Default')), atest = false; end
119 if ~any(strcmpi(io(2).sets, 'From Expression')), atest = false; end
120 if ~any(strcmpi(io(2).sets, 'From XML File')), atest = false; end
121 if ~any(strcmpi(io(2).sets, 'From MAT File')), atest = false; end
122 if ~any(strcmpi(io(2).sets, 'From ASCII File')), atest = false; end
123 if ~any(strcmpi(io(2).sets, 'From Repository')), atest = false; end
124 if ~any(strcmpi(io(2).sets, 'From Built-in Model')), atest = false; end
125 if numel(io(2).plists) ~= numel(io(2).sets), atest = false; end
126 %%%%%%%%%% SET 'Default'
127 pn = 3;
128 if io(pn).plists.nparams ~= 3, atest = false; end
129 % Check key
130 % Check default value
131 % Check options
132 %%%%%%%%%% SET 'From MAT File'
133 pn = 4;
134 if io(pn).plists.nparams ~= 4, atest = false; end
135 % Check key
136 if ~io(pn).plists.isparam('filename'), atest = false; end
137 % Check default value
138 if ~isEmptyChar(io(pn).plists.find('filename')), atest = false; end
139 % Check options
140 if ~isequal(io(pn).plists.getOptionsForParam('filename'), {''}), atest = false; end
141 %%%%%%%%%% SET 'From XML File'
142 pn = 5;
143 if io(pn).plists.nparams ~= 4, atest = false; end
144 % Check key
145 if ~io(pn).plists.isparam('filename'), atest = false; end
146 % Check default value
147 if ~isEmptyChar(io(pn).plists.find('filename')), atest = false; end
148 % Check options
149 if ~isequal(io(pn).plists.getOptionsForParam('filename'), {''}), atest = false; end
150 %%%%%%%%%% SET 'From Repository'
151 pn = 6;
152 if io(pn).plists.nparams ~= 10, atest = false; end
153 % Check key
154 if ~io(pn).plists.isparam('hostname'), atest = false; end
155 if ~io(pn).plists.isparam('id'), atest = false; end
156 if ~io(pn).plists.isparam('cid'), atest = false; end
157 if ~io(pn).plists.isparam('database'), atest = false; end
158 if ~io(pn).plists.isparam('binary'), atest = false; end
159 if ~io(pn).plists.isparam('username'), atest = false; end
160 if ~io(pn).plists.isparam('password'), atest = false; end
161 % Check default value
162 if ~isEmptyDouble(io(pn).plists.find('id')), atest = false; end
163 if ~isEmptyDouble(io(pn).plists.find('cid')), atest = false; end
164 if ~isequal(io(pn).plists.find('binary'), 'yes'), atest = false; end
165 % Check options
166 if ~isequal(io(pn).plists.getOptionsForParam('id'), {[]}), atest = false; end
167 if ~isequal(io(pn).plists.getOptionsForParam('cid'), {[]}), atest = false; end
168 if ~isequal(io(pn).plists.getOptionsForParam('binary'), {'yes', 'no'}), atest = false; end
169 %%%%%%%%%% SET 'From Built-in Model'
170 pn = 7;
171 if io(pn).plists.nparams ~= 4, atest = false; end
172 % Check key
173 if ~io(pn).plists.isparam('BUILT-IN'), atest = false; end
174 % Check default value
175 if ~isEmptyChar(io(pn).plists.find('built-in')), atest = false; end
176 % Check options
177 if ~isequal(io(pn).plists.getOptionsForParam('built-in'), {''}), atest = false; end
178 %%%%%%%%%% SET 'From Expression'
179 pn = 8;
180 if io(pn).plists.nparams ~= 10, atest = false; end
181 % Check key
182 if ~io(pn).plists.isparam('name'), atest = false; end
183 if ~io(pn).plists.isparam('description'), atest = false; end
184 if ~io(pn).plists.isparam('EXPRESSION'), atest = false; end
185 if ~io(pn).plists.isparam('params'), atest = false; end
186 if ~io(pn).plists.isparam('values'), atest = false; end
187 if ~io(pn).plists.isparam('xvar'), atest = false; end
188 if ~io(pn).plists.isparam('xvals'), atest = false; end
189 if ~io(pn).plists.isparam('xunits'), atest = false; end
190 if ~io(pn).plists.isparam('yunits'), atest = false; end
191 % Check default value
192 % Check options
193 %%%%%%%%%% SET 'From ASCII File'
194 pn = 9;
195 if io(pn).plists.nparams ~= 7, atest = false; end
196 % Check key
197 if ~io(pn).plists.isparam('Name'), atest = false; end
198 if ~io(pn).plists.isparam('description'), atest = false; end
199 if ~io(pn).plists.isparam('filename'), atest = false; end
200 if ~io(pn).plists.isparam('xvals'), atest = false; end
201 if ~io(pn).plists.isparam('yunits'), atest = false; end
202 if ~io(pn).plists.isparam('xunits'), atest = false; end
203 % Check default value
204 % Check options
205 end
206 % </AlgoCode>
207 else
208 atest = false;
209 end
210
211 % Return a result structure
212 result = utp_prepare_result(atest, stest, dbstack, mfilename);
213 end % END UTP_01
214
215 %% UTP_07
216
217 % <TestDescription>
218 %
219 % Tests that the smodel can read older MAT files which have different
220 % values in 'xvals'
221 %
222 % </TestDescription>
223 function result = utp_07
224
225 % <SyntaxDescription>
226 %
227 % Tests that the smodel can read older MAT files which have different
228 % values in 'xvals'
229 % The smodel object was created with the commands:
230 % s = smodel('A.*(t >= toff)');
231 % s.setXvar('t');
232 % s.setParams({'A','toff'}, {5,300});
233 % s.setName('Step at toff');
234 % s.setDescription('Step function of amplitude A at time toff');
235 % s.setXunits('Hz^1/2 km^2');
236 % s.setYunits('s^2 m^-1');
237 % s.setXvals(1:1e3);
238 % s.setAliasNames('a');
239 % s.setAliasValues(8);
240 %
241 % </SyntaxDescription>
242
243 try
244 % <SyntaxCode>
245 p = mfilename('fullpath');
246 % p = regexp(p, '.*(?=/\w+$)', 'match');
247 p = p(1:end-(numel(mfilename)+1));
248 p = fullfile(p, 'reference_files');
249
250 fn1 = 'smodel_231_xvals_cdata.mat';
251 fn2 = 'smodel_231_xvals_fsdata.mat';
252 fn3 = 'smodel_231_xvals_double.mat';
253 fn4 = 'smodel_231_xvals_tsdata.mat';
254 fn5 = 'smodel_231_xvals_double.xml';
255
256 s1 = smodel(fullfile(p, fn1));
257 s2 = smodel(fullfile(p, fn2));
258 s3 = smodel(fullfile(p, fn3));
259 s4 = smodel(fullfile(p, fn4));
260 s5 = smodel(fullfile(p, fn5));
261
262 % </SyntaxCode>
263 stest = true;
264 catch err
265 disp(err.message)
266 stest = false;
267 end
268
269 % <AlgoDescription>
270 %
271 % 1) Check that the objects are quite the same
272 %
273 % 2) Check that 'xvals' is a cell-array with the numbers from 1 to 1000
274 %
275 % </AlgoDescription>
276
277 atest = true;
278 if stest
279 % <AlgoCode>
280 try
281 assert(eq(s1, s2, 'UUID', 'proctime', 'mversion', 'plistUsed'));
282 assert(eq(s1, s3, 'UUID', 'proctime', 'mversion', 'plistUsed'));
283 assert(eq(s1, s4, 'UUID', 'proctime', 'mversion', 'plistUsed'));
284 assert(eq(s1, s5, 'UUID', 'proctime', 'mversion', 'plistUsed', 'mpackage', 'creator'));
285
286 assert(isequal(s1.xvals{1}, 1:1e3));
287 assert(isequal(s2.xvals{1}, 1:1e3));
288 assert(isequal(s3.xvals{1}, 1:1e3));
289 assert(isequal(s4.xvals{1}, 1:1e3));
290 assert(isequal(s5.xvals{1}, 1:1e3));
291 catch
292 atest = false;
293 end
294 % </AlgoCode>
295 else
296 atest = false;
297 end
298
299 % Return a result structure
300 result = utp_prepare_result(atest, stest, dbstack, mfilename);
301 end % END UTP_07
302
303
304 end