comparison testing/utp_1.1/generic_utps/utp_generic_aop_rule6.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
2 % <TestDescription>
3 %
4 % Tests the arithmetic operators rule 6.
5 %
6 % </TestDescription>
7 function result = utp_generic_aop_rule6(fcn)
8
9 % <SyntaxDescription>
10 %
11 % Tests the arithmetic operators rule 6 for each data type: xydata,
12 % fsdata, tsdata, cdata and useful combinations.
13 %
14 % </SyntaxDescription>
15
16 % Test AOs
17 % tsdata
18 n = 12;
19 fs = 12.1;
20 x = 0:(1/fs):(n/fs)-1/fs;
21 a_ts = ao(x,randn(n,1), fs);
22 a_ts.setDx(ones(n,1)*1.1);
23 a_ts.setDy((1:n)*2.2);
24 a_ts.setYunits('Hz^(-1/2) V^2');
25 a_ts.setName();
26
27 b_ts = ao(x,randn(n,1), fs);
28 b_ts.setDx(7);
29 b_ts.setDy(9);
30 b_ts.setYunits('Hz^(-1/2) V^2');
31 b_ts.setName();
32
33 V_N_ts = [copy(a_ts, 1); copy(b_ts, 1)];
34 M_NP_ts = [copy(a_ts, 1), copy(a_ts, 1), copy(b_ts, 1); copy(b_ts, 1), copy(a_ts, 1), copy(a_ts, 1)];
35
36 % fsdata
37 a_fs = ao(plist('xvals', 1:12, 'yvals', abs(randn(n,1)), 'type', 'fsdata'));
38 a_fs.setDx(ones(n,1)*1.1);
39 a_fs.setDy((1:n)*2.2);
40 a_fs.setName();
41
42 b_fs = ao(plist('xvals', 1:n, 'yvals', abs(randn(n,1)), 'type', 'fsdata'));
43 b_fs.setDx(7);
44 b_fs.setDy(9);
45 b_fs.setName();
46
47 V_N_fs = [copy(a_fs, 1); copy(b_fs, 1)];
48 M_NP_fs = [copy(a_fs, 1), copy(a_fs, 1), copy(b_fs, 1); copy(b_fs, 1), copy(a_fs, 1), copy(a_fs, 1)];
49
50 % xydata
51 a_xy = ao(plist('xvals', 1:n, 'yvals', abs(randn(n,1)), 'type', 'xydata'));
52 a_xy.setDx(ones(n,1)*1.1);
53 a_xy.setDy((1:n)*2.2);
54 a_xy.setYunits('Hz^(-1/2) V^2');
55 a_xy.setName();
56
57 b_xy = ao(plist('xvals', 1:n, 'yvals', abs(randn(n,1)), 'type', 'xydata'));
58 b_xy.setDx(7);
59 b_xy.setDy(9);
60 b_xy.setName();
61
62 V_N_xy = [copy(a_xy, 1); copy(b_xy, 1)];
63 M_NP_xy = [copy(a_xy, 1), copy(a_xy, 1), copy(b_xy, 1); copy(b_xy, 1), copy(a_xy, 1), copy(a_xy, 1)];
64
65 % cdata
66 a_c = ao(8);
67 a_c.setDy(2);
68 a_c.setName();
69
70 b_c = ao(111:122);
71 b_c.setDy((111:122)/100);
72 b_c.setName();
73
74 V_N_c = [copy(a_c, 1); copy(b_c, 1)];
75 M_NP_c = [copy(a_c, 1), copy(a_c, 1), copy(b_c, 1); copy(b_c, 1), copy(a_c, 1), copy(a_c, 1)];
76
77 % Define check functions
78 checkFcns = {...
79 @checkDataObjectRule6, ...
80 @checkValuesRule6, ...
81 @checkErrorsRule6, ...
82 @checkUnitsRule6, ...
83 @check_aop_history};
84
85 result = [];
86
87 % <AlgoDescription>
88 %
89 % Here we test element-wise operator rule6 as in S2-AEI-TN-3059.
90 %
91 % 1) Check the data type of the resulting object.
92 % 2) Check the resulting object contains the correct values.
93 % 3) Check the error propagation.
94 % 4) Check the units of the output object.
95 % 5) Check the resulting object can be rebuilt.
96 %
97 % </AlgoDescription>
98
99
100 % <AlgoCode>
101 % tsdata
102 result = [result utp_generic_aop_core(fcn, 'rule6', 'NxP tsdata and vector tsdata', M_NP_ts, V_N_ts, checkFcns)];
103 result = [result utp_generic_aop_core(fcn, 'rule6', 'vector tsdata and NxP tsdata', V_N_ts, M_NP_ts, checkFcns)];
104 result = [result utp_generic_aop_core(fcn, 'rule6', 'NxP tsdata and vector xydata', M_NP_ts, V_N_xy, checkFcns)];
105 result = [result utp_generic_aop_core(fcn, 'rule6', 'vector xydata and NxP tsdata', V_N_xy, M_NP_ts, checkFcns)];
106 result = [result utp_generic_aop_core(fcn, 'rule6', 'NxP tsdata and vector cdata', M_NP_ts, V_N_c, checkFcns)];
107 result = [result utp_generic_aop_core(fcn, 'rule6', 'vector cdata and NxP tsdata', V_N_c, M_NP_ts, checkFcns)];
108
109 % fsdata
110 result = [result utp_generic_aop_core(fcn, 'rule6', 'NxP fsdata and vector fsdata', M_NP_fs, V_N_fs, checkFcns)];
111 result = [result utp_generic_aop_core(fcn, 'rule6', 'vector fsdata and NxP fsdata', V_N_fs, M_NP_fs, checkFcns)];
112 result = [result utp_generic_aop_core(fcn, 'rule6', 'NxP fsdata and vector xydata', M_NP_fs, V_N_xy, checkFcns)];
113 result = [result utp_generic_aop_core(fcn, 'rule6', 'vector xydata and NxP fsdata', V_N_xy, M_NP_fs, checkFcns)];
114 result = [result utp_generic_aop_core(fcn, 'rule6', 'NxP fsdata and vector cdata', M_NP_fs, V_N_c, checkFcns)];
115 result = [result utp_generic_aop_core(fcn, 'rule6', 'vector cdata and NxP fsdata', V_N_c, M_NP_fs, checkFcns)];
116
117 % xydata
118 result = [result utp_generic_aop_core(fcn, 'rule6', 'NxP xydata and vector xydata', M_NP_xy, V_N_xy, checkFcns)];
119 result = [result utp_generic_aop_core(fcn, 'rule6', 'vector xydata and NxP xydata', V_N_xy, M_NP_xy, checkFcns)];
120 result = [result utp_generic_aop_core(fcn, 'rule6', 'NxP xydata and vector cdata', M_NP_xy, V_N_c, checkFcns)];
121 result = [result utp_generic_aop_core(fcn, 'rule6', 'vector cdata and NxP xydata', V_N_c, M_NP_xy, checkFcns)];
122
123 % cdata
124 result = [result utp_generic_aop_core(fcn, 'rule6', 'NxP cdata and vector cdata', M_NP_c, V_N_c, checkFcns)];
125 result = [result utp_generic_aop_core(fcn, 'rule6', 'vector cdata and NxP cdata', V_N_c, M_NP_c, checkFcns)];
126 % </AlgoCode>
127
128 end % END UTP_rule6
129
130 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
131 % Define here the checking functions %
132 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
133
134 %%%%%%%%%% Data object test %%%%%%%%%%
135 function atest = checkDataObjectRule6(fcn, in1, in2, out)
136
137 for nn = 1:size(in1,1)
138 for pp = 1:size(in1,2)
139 if numel(in1) > numel(in2)
140 atest = check_aop_data_object(fcn, in1(nn,pp), in2(nn), out(nn,pp));
141 else
142 atest = check_aop_data_object(fcn, in1(nn), in2(nn,pp), out(nn,pp));
143 end
144 if atest == 0
145 break;
146 end
147 end
148 end
149 end
150
151 %%%%%%%%%% Value test %%%%%%%%%%
152 function atest = checkValuesRule6(fcn, in1, in2, out)
153
154 atest = true;
155 for nn = 1:size(in1,1)
156 for pp = 1:size(in1,2)
157 if isMatrix(in1) && isVector(in2)
158 if ~isequal(fcn(in1(nn,pp).data.getY, in2(nn).data.getY), out(nn,pp).data.getY), atest = false; end
159 else
160 if ~isequal(fcn(in1(nn).data.getY, in2(nn,pp).data.getY), out(nn,pp).data.getY), atest = false; end
161 end
162 if atest == 0
163 break;
164 end
165 end
166 end
167 end
168
169 %%%%%%%%%% Errors test %%%%%%%%%%
170 function atest = checkErrorsRule6(fcn, in1, in2, out)
171
172 atest = true;
173 for nn = 1:size(in1,1)
174 for pp = 1:size(in1,2)
175 if isMatrix(in1) && isVector(in2)
176 atest = check_aop_errors(fcn, in1(nn,pp), in2(nn), out(nn,pp));
177 else
178 atest = check_aop_errors(fcn, in1(nn), in2(nn,pp), out(nn,pp));
179 end
180 if atest == 0
181 break;
182 end
183 end
184 end
185 end
186
187 %%%%%%%%%% Units test %%%%%%%%%%
188 function atest = checkUnitsRule6(fcn, in1, in2, out)
189
190 atest = true;
191 for nn = 1:size(in1,1)
192 for pp = 1:size(in1,2)
193 if isMatrix(in1) && isVector(in2)
194 atest = check_aop_units(fcn, in1(nn,pp), in2(nn), out(nn,pp));
195 else
196 atest = check_aop_units(fcn, in1(nn), in2(nn,pp), out(nn,pp));
197 end
198 if atest == 0
199 break;
200 end
201 end
202 end
203 end
204
205 function [a1, a2] = findMatrix(in1, in2)
206 if numel(in1) > numel(in2)
207 a1 = in1;
208 a2 = in2;
209 else
210 a1 = in2;
211 a2 = in1;
212 end
213 end
214
215 function res = isMatrix(a)
216 res = all(size(a) > 1);
217 end
218
219 function res = isVector(a)
220 res = any(size(a) > 1) && any(size(a) == 1);
221 end
222