Mercurial > hg > ltpda
view 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 |
line wrap: on
line source
% <TestDescription> % % Tests the arithmetic operators rule 5. % % </TestDescription> function result = utp_generic_aop_rule5(fcn) % <SyntaxDescription> % % Tests the arithmetic operators rule 5 for each data type: xydata, % fsdata, tsdata, cdata and useful combinations. % % </SyntaxDescription> % Test AOs % tsdata n = 12; fs = 12.1; x = 0:(1/fs):(n/fs)-1/fs; a_ts = ao(x,randn(n,1), fs); a_ts.setDx(ones(n,1)*1.1); a_ts.setDy((1:n)*2.2); a_ts.setYunits('Hz^(-1/2) V^2'); a_ts.setName(); b_ts = ao(x,randn(n,1), fs); b_ts.setDx(7); b_ts.setDy(9); b_ts.setYunits('Hz^(-1/2) V^2'); b_ts.setName(); 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)]; % fsdata a_fs = ao(plist('xvals', 1:n, 'yvals', abs(randn(n,1)), 'type', 'fsdata')); a_fs.setDx(ones(n,1)*1.1); a_fs.setDy((1:n)*2.2); a_fs.setName(); b_fs = ao(plist('xvals', 1:n, 'yvals', abs(randn(n,1)), 'type', 'fsdata')); b_fs.setDx(7); b_fs.setDy(9); b_fs.setName(); 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)]; % xydata a_xy = ao(plist('xvals', 1:n, 'yvals', abs(randn(n,1)), 'type', 'xydata')); a_xy.setDx(ones(n,1)*1.1); a_xy.setDy((1:n)*2.2); a_xy.setYunits('Hz^(-1/2) V^2'); a_xy.setName(); b_xy = ao(plist('xvals', 1:n, 'yvals', abs(randn(n,1)), 'type', 'xydata')); b_xy.setDx(7); b_xy.setDy(9); b_xy.setName(); 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)]; % cdata a_c = ao(8); a_c.setDy(2); a_c.setName(); b_c = ao(111:122); b_c.setDy((111:122)/100); b_c.setName(); 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)]; % Define check functions checkFcns = {... @checkDataObjectRule5, ... @checkValuesRule5, ... @checkErrorsRule5, ... @checkUnitsRule5, ... @check_aop_history}; result = []; % <AlgoDescription> % % Here we test element-wise operator rule5 as in S2-AEI-TN-3059. % % 1) Check the data type of the resulting object. % 2) Check the resulting object contains the correct values. % 3) Check the error propagation. % 4) Check the units of the output object. % 5) Check the resulting object can be rebuilt. % % </AlgoDescription> % <AlgoCode> % tsdata result = [result utp_generic_aop_core(fcn, 'rule5', 'NxP tsdata and single tsdata', M_NP_ts, a_ts, checkFcns)]; result = [result utp_generic_aop_core(fcn, 'rule5', 'single tsdata and NxP tsdata', b_ts, M_NP_ts, checkFcns)]; result = [result utp_generic_aop_core(fcn, 'rule5', 'NxP tsdata and single xydata', M_NP_ts, a_xy, checkFcns)]; result = [result utp_generic_aop_core(fcn, 'rule5', 'single xydata and NxP tsdata', b_xy, M_NP_ts, checkFcns)]; result = [result utp_generic_aop_core(fcn, 'rule5', 'NxP tsdata and single cdata', M_NP_ts, a_c, checkFcns)]; result = [result utp_generic_aop_core(fcn, 'rule5', 'single cdata and NxP tsdata', b_c, M_NP_ts, checkFcns)]; % fsdata result = [result utp_generic_aop_core(fcn, 'rule5', 'NxP fsdata and single fsdata', M_NP_fs, a_fs, checkFcns)]; result = [result utp_generic_aop_core(fcn, 'rule5', 'single fsdata and NxP fsdata', b_fs, M_NP_fs, checkFcns)]; result = [result utp_generic_aop_core(fcn, 'rule5', 'NxP fsdata and single xydata', M_NP_fs, a_xy, checkFcns)]; result = [result utp_generic_aop_core(fcn, 'rule5', 'single xydata and NxP fsdata', b_xy, M_NP_fs, checkFcns)]; result = [result utp_generic_aop_core(fcn, 'rule5', 'NxP fsdata and single cdata', M_NP_fs, a_c, checkFcns)]; result = [result utp_generic_aop_core(fcn, 'rule5', 'single cdata and NxP fsdata', b_c, M_NP_fs, checkFcns)]; % xydata result = [result utp_generic_aop_core(fcn, 'rule5', 'NxP xydata and single xydata', M_NP_xy, a_xy, checkFcns)]; result = [result utp_generic_aop_core(fcn, 'rule5', 'single xydata and NxP xydata', b_xy, M_NP_xy, checkFcns)]; result = [result utp_generic_aop_core(fcn, 'rule5', 'NxP xydata and single cdata', M_NP_xy, a_c, checkFcns)]; result = [result utp_generic_aop_core(fcn, 'rule5', 'single cdata and NxP xydata', b_c, M_NP_xy, checkFcns)]; % cdata result = [result utp_generic_aop_core(fcn, 'rule5', 'NxP cdata and single cdata', M_NP_c, a_c, checkFcns)]; result = [result utp_generic_aop_core(fcn, 'rule5', 'single cdata and NxP cdata', b_c, M_NP_c, checkFcns)]; % </AlgoCode> end % END UTP_rule2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Define here the checking functions % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%% Data object test %%%%%%%%%% function atest = checkDataObjectRule5(fcn, in1, in2, out) for ii = 1:max(numel(in1), numel(in2)) if numel(in1) > numel(in2) atest = check_aop_data_object(fcn, in1(ii), in2, out(ii)); else atest = check_aop_data_object(fcn, in1, in2(ii), out(ii)); end if atest == 0 break; end end end %%%%%%%%%% Value test %%%%%%%%%% function atest = checkValuesRule5(fcn, in1, in2, out) atest = true; for ii = 1:max(numel(in1), numel(in2)) if numel(in1) > numel(in2) if ~isequal(fcn(in1(ii).data.getY, in2.data.getY), out(ii).data.getY), atest = false; end else if ~isequal(fcn(in1.data.getY, in2(ii).data.getY), out(ii).data.getY), atest = false; end end if atest == 0 break; end end end %%%%%%%%%% Errors test %%%%%%%%%% function atest = checkErrorsRule5(fcn, in1, in2, out) atest = true; for ii = 1:max(numel(in1), numel(in2)) if numel(in1) > numel(in2) atest = check_aop_errors(fcn, in1(ii), in2, out(ii)); else atest = check_aop_errors(fcn, in1, in2(ii), out(ii)); end if atest == 0 break; end end end %%%%%%%%%% Units test %%%%%%%%%% function atest = checkUnitsRule5(fcn, in1, in2, out) atest = true; for ii = 1:max(numel(in1), numel(in2)) if numel(in1) > numel(in2) atest = check_aop_units(fcn, in1(ii), in2, out(ii)); else atest = check_aop_units(fcn, in1, in2(ii), out(ii)); end if atest == 0 break; end end end