comparison testing/utp_1.1/generic_utps/utp_generic_aop_rule5.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 5.
5 %
6 % </TestDescription>
7 function result = utp_generic_aop_rule5(fcn)
8
9 % <SyntaxDescription>
10 %
11 % Tests the arithmetic operators rule 5 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 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)];
34
35 % fsdata
36 a_fs = ao(plist('xvals', 1:n, 'yvals', abs(randn(n,1)), 'type', 'fsdata'));
37 a_fs.setDx(ones(n,1)*1.1);
38 a_fs.setDy((1:n)*2.2);
39 a_fs.setName();
40
41 b_fs = ao(plist('xvals', 1:n, 'yvals', abs(randn(n,1)), 'type', 'fsdata'));
42 b_fs.setDx(7);
43 b_fs.setDy(9);
44 b_fs.setName();
45
46 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)];
47
48 % xydata
49 a_xy = ao(plist('xvals', 1:n, 'yvals', abs(randn(n,1)), 'type', 'xydata'));
50 a_xy.setDx(ones(n,1)*1.1);
51 a_xy.setDy((1:n)*2.2);
52 a_xy.setYunits('Hz^(-1/2) V^2');
53 a_xy.setName();
54
55 b_xy = ao(plist('xvals', 1:n, 'yvals', abs(randn(n,1)), 'type', 'xydata'));
56 b_xy.setDx(7);
57 b_xy.setDy(9);
58 b_xy.setName();
59
60 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)];
61
62 % cdata
63 a_c = ao(8);
64 a_c.setDy(2);
65 a_c.setName();
66
67 b_c = ao(111:122);
68 b_c.setDy((111:122)/100);
69 b_c.setName();
70
71 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)];
72
73 % Define check functions
74 checkFcns = {...
75 @checkDataObjectRule5, ...
76 @checkValuesRule5, ...
77 @checkErrorsRule5, ...
78 @checkUnitsRule5, ...
79 @check_aop_history};
80
81 result = [];
82
83 % <AlgoDescription>
84 %
85 % Here we test element-wise operator rule5 as in S2-AEI-TN-3059.
86 %
87 % 1) Check the data type of the resulting object.
88 % 2) Check the resulting object contains the correct values.
89 % 3) Check the error propagation.
90 % 4) Check the units of the output object.
91 % 5) Check the resulting object can be rebuilt.
92 %
93 % </AlgoDescription>
94
95
96 % <AlgoCode>
97 % tsdata
98 result = [result utp_generic_aop_core(fcn, 'rule5', 'NxP tsdata and single tsdata', M_NP_ts, a_ts, checkFcns)];
99 result = [result utp_generic_aop_core(fcn, 'rule5', 'single tsdata and NxP tsdata', b_ts, M_NP_ts, checkFcns)];
100 result = [result utp_generic_aop_core(fcn, 'rule5', 'NxP tsdata and single xydata', M_NP_ts, a_xy, checkFcns)];
101 result = [result utp_generic_aop_core(fcn, 'rule5', 'single xydata and NxP tsdata', b_xy, M_NP_ts, checkFcns)];
102 result = [result utp_generic_aop_core(fcn, 'rule5', 'NxP tsdata and single cdata', M_NP_ts, a_c, checkFcns)];
103 result = [result utp_generic_aop_core(fcn, 'rule5', 'single cdata and NxP tsdata', b_c, M_NP_ts, checkFcns)];
104
105 % fsdata
106 result = [result utp_generic_aop_core(fcn, 'rule5', 'NxP fsdata and single fsdata', M_NP_fs, a_fs, checkFcns)];
107 result = [result utp_generic_aop_core(fcn, 'rule5', 'single fsdata and NxP fsdata', b_fs, M_NP_fs, checkFcns)];
108 result = [result utp_generic_aop_core(fcn, 'rule5', 'NxP fsdata and single xydata', M_NP_fs, a_xy, checkFcns)];
109 result = [result utp_generic_aop_core(fcn, 'rule5', 'single xydata and NxP fsdata', b_xy, M_NP_fs, checkFcns)];
110 result = [result utp_generic_aop_core(fcn, 'rule5', 'NxP fsdata and single cdata', M_NP_fs, a_c, checkFcns)];
111 result = [result utp_generic_aop_core(fcn, 'rule5', 'single cdata and NxP fsdata', b_c, M_NP_fs, checkFcns)];
112
113 % xydata
114 result = [result utp_generic_aop_core(fcn, 'rule5', 'NxP xydata and single xydata', M_NP_xy, a_xy, checkFcns)];
115 result = [result utp_generic_aop_core(fcn, 'rule5', 'single xydata and NxP xydata', b_xy, M_NP_xy, checkFcns)];
116 result = [result utp_generic_aop_core(fcn, 'rule5', 'NxP xydata and single cdata', M_NP_xy, a_c, checkFcns)];
117 result = [result utp_generic_aop_core(fcn, 'rule5', 'single cdata and NxP xydata', b_c, M_NP_xy, checkFcns)];
118
119 % cdata
120 result = [result utp_generic_aop_core(fcn, 'rule5', 'NxP cdata and single cdata', M_NP_c, a_c, checkFcns)];
121 result = [result utp_generic_aop_core(fcn, 'rule5', 'single cdata and NxP cdata', b_c, M_NP_c, checkFcns)];
122 % </AlgoCode>
123
124 end % END UTP_rule2
125
126 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
127 % Define here the checking functions %
128 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
129
130 %%%%%%%%%% Data object test %%%%%%%%%%
131 function atest = checkDataObjectRule5(fcn, in1, in2, out)
132
133 for ii = 1:max(numel(in1), numel(in2))
134 if numel(in1) > numel(in2)
135 atest = check_aop_data_object(fcn, in1(ii), in2, out(ii));
136 else
137 atest = check_aop_data_object(fcn, in1, in2(ii), out(ii));
138 end
139 if atest == 0
140 break;
141 end
142 end
143 end
144
145 %%%%%%%%%% Value test %%%%%%%%%%
146 function atest = checkValuesRule5(fcn, in1, in2, out)
147
148 atest = true;
149 for ii = 1:max(numel(in1), numel(in2))
150 if numel(in1) > numel(in2)
151 if ~isequal(fcn(in1(ii).data.getY, in2.data.getY), out(ii).data.getY), atest = false; end
152 else
153 if ~isequal(fcn(in1.data.getY, in2(ii).data.getY), out(ii).data.getY), atest = false; end
154 end
155 if atest == 0
156 break;
157 end
158 end
159 end
160
161 %%%%%%%%%% Errors test %%%%%%%%%%
162 function atest = checkErrorsRule5(fcn, in1, in2, out)
163
164 atest = true;
165 for ii = 1:max(numel(in1), numel(in2))
166 if numel(in1) > numel(in2)
167 atest = check_aop_errors(fcn, in1(ii), in2, out(ii));
168 else
169 atest = check_aop_errors(fcn, in1, in2(ii), out(ii));
170 end
171 if atest == 0
172 break;
173 end
174 end
175 end
176
177 %%%%%%%%%% Units test %%%%%%%%%%
178 function atest = checkUnitsRule5(fcn, in1, in2, out)
179
180 atest = true;
181 for ii = 1:max(numel(in1), numel(in2))
182 if numel(in1) > numel(in2)
183 atest = check_aop_units(fcn, in1(ii), in2, out(ii));
184 else
185 atest = check_aop_units(fcn, in1, in2(ii), out(ii));
186 end
187 if atest == 0
188 break;
189 end
190 end
191 end