
% <TestDescription>
%
% Tests the arithmetic operators rule 8.
%
% </TestDescription>
function result = utp_generic_aop_rule8(fcn)
  
  % <SyntaxDescription>
  %
  % Tests the arithmetic operators rule 8 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();
  
  V_Q_ts = [copy(a_ts, 1), copy(a_ts, 1), copy(b_ts, 1), copy(b_ts, 1)];
  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();
  
  V_Q_fs = [copy(a_fs, 1), copy(a_fs, 1), copy(b_fs, 1), copy(b_fs, 1)];
  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();
  
  V_Q_xy = [copy(a_xy, 1), copy(a_xy, 1), copy(b_xy, 1), copy(b_xy, 1)];
  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();
  
  V_Q_c = [copy(a_c, 1), copy(a_c, 1), copy(b_c, 1), copy(b_c, 1)];
  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
  
  result = [];
  
  % <AlgoDescription>
  %
  % Here we test  element-wise operator rule8 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_negative_core(fcn, 'rule8', 'NxP tsdata and vector tsdata', M_NP_ts, V_Q_ts)];
  result = [result utp_generic_aop_negative_core(fcn, 'rule8', 'vector tsdata and NxP tsdata', V_Q_ts, M_NP_ts)];
  result = [result utp_generic_aop_negative_core(fcn, 'rule8', 'NxP tsdata and vector xydata', M_NP_ts, V_Q_xy)];
  result = [result utp_generic_aop_negative_core(fcn, 'rule8', 'vector xydata and NxP tsdata', V_Q_xy, M_NP_ts)];
  result = [result utp_generic_aop_negative_core(fcn, 'rule8', 'NxP tsdata and vector cdata', M_NP_ts, V_Q_c)];
  result = [result utp_generic_aop_negative_core(fcn, 'rule8', 'vector cdata and NxP tsdata', V_Q_c, M_NP_ts)];
  
  % fsdata
  result = [result utp_generic_aop_negative_core(fcn, 'rule8', 'NxP fsdata and vector fsdata', M_NP_fs, V_Q_fs)];
  result = [result utp_generic_aop_negative_core(fcn, 'rule8', 'vector fsdata and NxP fsdata', V_Q_fs, M_NP_fs)];
  result = [result utp_generic_aop_negative_core(fcn, 'rule8', 'NxP fsdata and vector xydata', M_NP_fs, V_Q_xy)];
  result = [result utp_generic_aop_negative_core(fcn, 'rule8', 'vector xydata and NxP fsdata', V_Q_xy, M_NP_fs)];
  result = [result utp_generic_aop_negative_core(fcn, 'rule8', 'NxP fsdata and vector cdata', M_NP_fs, V_Q_c)];
  result = [result utp_generic_aop_negative_core(fcn, 'rule8', 'vector cdata and NxP fsdata', V_Q_c, M_NP_fs)];
  
  % xydata
  result = [result utp_generic_aop_negative_core(fcn, 'rule8', 'NxP xydata and vector xydata', M_NP_xy, V_Q_xy)];
  result = [result utp_generic_aop_negative_core(fcn, 'rule8', 'vector xydata and NxP xydata', V_Q_xy, M_NP_xy)];
  result = [result utp_generic_aop_negative_core(fcn, 'rule8', 'NxP xydata and vector cdata', M_NP_xy, V_Q_c)];
  result = [result utp_generic_aop_negative_core(fcn, 'rule8', 'vector cdata and NxP xydata', V_Q_c, M_NP_xy)];
  
  % cdata
  result = [result utp_generic_aop_negative_core(fcn, 'rule8', 'NxP cdata and vector cdata', M_NP_c, V_Q_c)];
  result = [result utp_generic_aop_negative_core(fcn, 'rule8', 'vector cdata and NxP cdata', V_Q_c, M_NP_c)];
  % </AlgoCode>
  
end % END UTP_rule8



