
% <TestDescription>
%
% Tests the arithmetic operators rule 11.
%
% </TestDescription>
function result = utp_generic_aop_rule11(fcn)
  
  % <SyntaxDescription>
  %
  % Tests the arithmetic operators rule 11 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();
  
  c_ts = ao(x,randn(n,1), fs);
  c_ts.setDx(7);
  c_ts.setDy(9);
  c_ts.setYunits('Hz^(-1/2) V^2');
  c_ts.setName();
  
  V_N_ts = [copy(a_ts, 1), copy(b_ts, 1), copy(c_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();
  
  c_fs = ao(plist('xvals', 1:n, 'yvals', abs(randn(n,1)), 'type', 'fsdata'));
  c_fs.setDx(ones(n,1)*1.1);
  c_fs.setDy((1:n)*2.2);
  c_fs.setName();
  
  V_N_fs = [copy(a_fs, 1), copy(b_fs, 1), copy(c_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();
  
  c_xy = ao(plist('xvals', 1:n, 'yvals', abs(randn(n,1)), 'type', 'xydata'));
  c_xy.setDx(ones(n,1)*1.1);
  c_xy.setDy((1:n)*2.2);
  c_xy.setYunits('Hz^(-1/2) V^2');
  c_xy.setName();
  
  V_N_xy = [copy(a_xy, 1), copy(b_xy, 1), copy(c_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();
  
  c_c = ao(111:122);
  c_c.setDy((111:122)/100);
  c_c.setName();
  
  V_N_c = [copy(a_c, 1), copy(b_c, 1), copy(c_c, 1)];
  
  % <SyntaxDescription>
  %
  % Tests that for more than two inputs the result will be as if the
  % commands are nested. For example: plus(a, b, c) == plus(plus(a, b), c)
  %
  % </SyntaxDescription>
  
  try
    % <SyntaxCode>
    %tsdata
    o_ts1 = fcn(a_ts, b_ts, c_ts);
    o_ts2 = fcn(fcn(a_ts, b_ts), c_ts);
    o_ts3 = fcn(a_ts, V_N_ts, c_ts);
    o_ts4 = fcn(fcn(a_ts, V_N_ts), c_ts);
    
    %fsdata
    o_fs1 = fcn(a_fs, b_fs, c_fs);
    o_fs2 = fcn(fcn(a_fs, b_fs), c_fs);
    o_fs3 = fcn(a_fs, V_N_fs, c_fs);
    o_fs4 = fcn(fcn(a_fs, V_N_fs), c_fs);
    
    %xydata
    o_xy1 = fcn(a_xy, b_xy, c_xy);
    o_xy2 = fcn(fcn(a_xy, b_xy), c_xy);
    o_xy3 = fcn(a_xy, V_N_xy, c_xy);
    o_xy4 = fcn(fcn(a_xy, V_N_xy), c_xy);
    
    %cdata
    o_c1 = fcn(a_c, b_c, c_c);
    o_c2 = fcn(fcn(a_c, b_c), c_c);
    o_c3 = fcn(a_c, V_N_c, c_c);
    o_c4 = fcn(fcn(a_c, V_N_c), c_c);
    
    % </SyntaxCode>
    stest = true;
  catch err
    disp(err.message)
    stest = false;
  end
  
  % <AlgoDescription>
  %
  % 1) Check that for more than two inputs the result will be as if the
  %    commands are nested.
  %
  % </AlgoDescription>
  
  atest = true;
  if stest
    try
      ple = plist('Exceptions', {'created', 'proctime', 'UUID'});
      % <AlgoCode>
      if ~eq(o_ts1, o_ts2, ple), atest = false; end
      if ~eq(o_ts3, o_ts4, ple), atest = false; end
      if ~eq(o_fs1, o_fs2, ple), atest = false; end
      if ~eq(o_fs3, o_fs4, ple), atest = false; end
      if ~eq(o_xy1, o_xy2, ple), atest = false; end
      if ~eq(o_xy3, o_xy4, ple), atest = false; end
      if ~eq(o_c1, o_c2, ple), atest = false; end
      if ~eq(o_c3, o_c4, ple), atest = false; end
      % </AlgoCode>
    catch err
      disp(err.message)
      atest = false;
    end
  else
    atest = false;
  end
  
  % Return a result structure
  dbs = dbstack;
  %   dbs(1).name = sprintf('%s/%s (%s/%s)', func2str(fcn), ruleName, aCl(1:end-4), bCl(1:end-4));
  dbs(1).name = sprintf('%s/rule11', func2str(fcn));
  result = utp_prepare_result(atest, stest, dbs, mfilename);
  
end % END UTP_rule11

