% <TestDescription>
%
% Tests that the <METHOD> method works with a vector of objects as input.
%
% </TestDescription>
% 
% $Id: utp_02.m,v 1.3 2010/07/27 07:13:59 hewitson Exp $
%

function result = utp_02(method, vec, algo, pli, ple3)
  
  % <SyntaxDescription>
  %
  % Test that the <METHOD> method works for a vector of objects as input.
  %
  % </SyntaxDescription>
  
  try
    % <SyntaxCode>
    if isempty(pli)
      out = feval(method, vec);
    else
      out = feval(method, vec, pli);
    end
    % </SyntaxCode>
    stest = true;
  catch err
    disp(err.message)
    stest = false;
  end
  
  % <AlgoDescription>
  %
  % 1) Check that the number of elements in 'out' is the same as in 'vec'
  % 2) Check that each output object contains the correct data.
  %
  % </AlgoDescription>
  
  atest = true;
  if stest
    % <AlgoCode>
    % Check we have the correct number of outputs
    if ~isequal(size(out), size(vec)), atest = false; end
    % Check each output against the correct value
    for kk=1:numel(out)
      
      % extra tests for constructors
      if utils.helper.ismember(method, utils.helper.ltpda_userclasses)
        
        % Check that the output is the same except the history
        if ~eq(vec(kk), out(kk), ple3), atest = false; end
        % Check the history
        if ~eq(vec(kk).hist, out(kk).hist.inhists), atest = false; end
        % Change the output to make sure that it is a 'real' copy
        out(kk).setDescription('my desc');
        if eq(vec(kk), out(kk), ple3), atest = false; end
        
      else
        atest = algo(vec(kk), out(kk), pli);
        if ~atest
          break;
        end
        
      end
    end
    
    % </AlgoCode>
  else
    atest = false;
  end
  
  % Return a result structure
  dd = dbstack;
  mfilename = dd(2).file(1:end-2);  
  result = utp_prepare_result(atest, stest, dbstack, mfilename);
end % END UTP_02