comparison testing/utp_1.1/utps/smodel/utp_smodel_addAliases.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_ADDALIASES a set of UTPs for the smodel/addAliases method
2 %
3 % M Hewitson 06-08-08
4 %
5 % $Id: utp_smodel_addAliases.m,v 1.1 2011/04/11 19:45:22 ingo Exp $
6 %
7
8 % <MethodDescription>
9 %
10 % The addAliases method of the smodel class sets the 'aliasNames' and
11 % 'aliasValues' properties.
12 %
13 % </MethodDescription>
14
15 function results = utp_smodel_addAliases(varargin)
16
17 % Check the inputs
18 if nargin == 0
19
20 % Some keywords
21 cl = 'smodel';
22 mthd = 'addAliases';
23
24 disp('******************************************************');
25 disp(['**** Running UTPs for ' cl '/' mthd]);
26 disp('******************************************************');
27
28 % Test objects
29 s1 = smodel('a1*x1 + a2*x2 + a3*x3');
30 s1.setName();
31 s1.setAliases('x1', 'b', 'c', 123);
32
33 s2 = smodel('a1*x1 + a2*x2');
34 s2.setName();
35
36 s3 = smodel('a1*x1');
37 s3.setName();
38
39 sv = [s1, s2, s1];
40 sm = [s1, s2, s1; s1, s2, s1];
41
42 % Exception list for the UTPs:
43 [ple1,ple2,ple3,ple4,ple5,ple6] = get_test_ples();
44
45 % The setter method have different possibilities to set a property
46 args1 = {'x1', 123}; % obj.addAliases('x1', 123)
47 args2 = {'x1', 123, 'x2', 'asd'}; % obj.addAliases('x1', 123, 'x2', 'asd')
48 args3 = {{'x1', 'x2'}, {'asd', 123}}; % obj.addAliases({'x1', 'x2'}, {'asd', 123})
49 args4 = {plist('names', 'x1', 'values', 123)}; % obj.addAliases(plist('names', 'x1', 'values', 123))
50 args5 = {plist('names', {'x1', 'x2'}, 'values', {123, 'asd'})};
51
52 % Run the general tests
53 results(1) = utp_01();
54 results(2) = utp_genericAnyShape(mthd, sv, args1, @algoTests);
55 results(3) = utp_genericAnyShape(mthd, sv, args2, @algoTests);
56 results(4) = utp_genericAnyShape(mthd, sv, args3, @algoTests);
57 results(5) = utp_genericAnyShape(mthd, sv, args4, @algoTests);
58 results(6) = utp_genericAnyShape(mthd, sv, args5, @algoTests);
59 results(7) = utp_genericAnyShape(mthd, sm, args2, @algoTests);
60 results(8) = utp_genericList(mthd, s1, s2, s3, args3, @algoTests);
61 results(9) = utp_genericHistory(mthd, s1, args2, ple2);
62 results(10) = utp_genericModify(mthd, s1, args5, @algoTests, ple1);
63 results(11) = utp_genericOutput(mthd, s1, s2, args2, @algoTests, ple2); % test the outputs
64
65 disp('Done.');
66 disp('******************************************************');
67
68 elseif nargin == 1 % Check for UTP functions
69 if strcmp(varargin{1}, 'isutp')
70 results = 1;
71 else
72 results = 0;
73 end
74 else
75 error('### Incorrect inputs')
76 end
77
78 % Check that the property have the correct value
79 function atest = algoTests(in, out, idx, argsin)
80 atest = true;
81 % Check that the input and output objects are the same except the
82 % property 'aliases' and the history
83 ple = plist('EXCEPTIONS', {'created', 'proctime', 'UUID', 'hist', 'aliasNames', 'aliasValues'});
84 if ~eq(in(idx), out(idx), ple), atest = false; end
85 if ~eq(in(idx).hist, out(idx).hist.inhists), atest = false; end
86 % Check that the parameter gets the correct value.
87 if isa(argsin{1}, 'plist') && argsin{1}.isparam('names') && argsin{1}.isparam('values')
88 argsin = argsin{1};
89 % The value was set with a plist.
90 names = cellstr(argsin.find('names'));
91 values = argsin.find('values');
92 if ~iscell(values)
93 values = num2cell(values);
94 end
95 else
96 if numel(argsin) == 2 && iscell(argsin{1}) && iscell(argsin{2})
97 names = argsin{1};
98 values = argsin{2};
99 else
100 nArgsin = numel(argsin);
101 names = argsin(1:2:nArgsin);
102 values = argsin(2:2:nArgsin);
103 end
104 end
105
106 n = in(idx).aliasNames;
107 v = in(idx).aliasValues;
108
109 for ll = 1:numel(names)
110 namesIdx = strcmp(n, names{ll});
111 if any(namesIdx)
112 % Change at the index the value
113 v{namesIdx} = values{ll};
114 else
115 % Append the alias key-value pair
116 n = [n names(ll)];
117 v = [v values(ll)];
118 end
119 end
120
121 % Check 'aliasNames' and 'aliasValues'
122 if ~isequal(out(idx).aliasNames, n), atest = false; end
123 if ~isequal(out(idx).aliasValues, v), atest = false; end
124 end
125
126 %% UTP_01
127
128 % <TestDescription>
129 %
130 % Tests that the getInfo call works for this method.
131 %
132 % </TestDescription>
133 function result = utp_01
134
135
136 % <SyntaxDescription>
137 %
138 % Test that the getInfo call works for no sets, all sets, and each set
139 % individually.
140 %
141 % </SyntaxDescription>
142
143 try
144 % <SyntaxCode>
145 % Call for no sets
146 io(1) = feval('smodel.getInfo', mthd, 'none');
147 % Call for all sets
148 io(2) = feval('smodel.getInfo', mthd);
149 % Call for each set
150 for kk=1:numel(io(2).sets)
151 io(kk+2) = feval('smodel.getInfo', mthd, io(2).sets{kk});
152 end
153 % </SyntaxCode>
154 stest = true;
155 catch err
156 disp(err.message)
157 stest = false;
158 end
159
160 % <AlgoDescription>
161 %
162 % 1) Check that getInfo call returned an minfo object in all cases.
163 % 2) Check that all plists have the correct parameters.
164 %
165 % </AlgoDescription>
166
167 atest = true;
168 if stest
169 % <AlgoCode>
170 % check we have minfo objects
171 if isa(io, 'minfo')
172 % SET 'None'
173 if ~isempty(io(1).sets), atest = false; end
174 if ~isempty(io(1).plists), atest = false; end
175 % Check all Sets
176 if ~any(strcmpi(io(2).sets, 'Default')), atest = false; end
177 if numel(io(2).plists) ~= numel(io(2).sets), atest = false; end
178 % SET 'Default'
179 if io(3).plists.nparams ~= 2, atest = false; end
180 % Check key
181 if ~io(3).plists.isparam('names'), atest = false; end
182 if ~io(3).plists.isparam('values'), atest = false; end
183 % Check default value
184 if ~isEmptyCell(io(3).plists.find('names')), atest = false; end
185 if ~isEmptyCell(io(3).plists.find('values')), atest = false; end
186 % Check options
187 if ~isequal(io(3).plists.getOptionsForParam('names'), {{}}), atest = false; end
188 if ~isequal(io(3).plists.getOptionsForParam('values'), {{}}), atest = false; end
189 end
190 % </AlgoCode>
191 else
192 atest = false;
193 end
194
195 % Return a result structure
196 result = utp_prepare_result(atest, stest, dbstack, mfilename);
197 end % END UTP_01
198
199 end