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