view testing/utp_1.1/generic_utps/utp_genericAnyShape.m @ 52:daf4eab1a51e database-connection-manager tip

Fix. Default password should be [] not an empty string
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Wed, 07 Dec 2011 17:29:47 +0100
parents 409a22968d5e
children
line wrap: on
line source

% <TestDescription>
%
% Tests that the <METHOD> method works with any shape of objects as input.
%
% </TestDescription>
function result = utp_genericAnyShape(method, objs, args, algo)
  
  % <SyntaxDescription>
  %
  % Test that the <METHOD> method works for any shape of objects as input.
  %
  % </SyntaxDescription>
  
  try
    % <SyntaxCode>
    if isempty(args)
      out = feval(method, objs);
    else
      if iscell(args)
        out = feval(method, objs, args{:});
      else
        out = feval(method, objs, args);
      end
    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 'objs'
  % 2) Check that each output object contains the correct data.
  % 3) Rebuild the object
  %
  % </AlgoDescription>
  
  atest = true;
  if stest
    % <AlgoCode>
    % 1. Check we have the correct number of outputs
    if ~isequal(size(out), size(objs)), atest = false; end
    
    % 2. Check each output against the correct value
    for kk=1:numel(out)
      atest = algo(objs, out, kk, args);
      if ~atest
        break;
      end
    end
    
    % 3. Check that we can rebuild the data
    r = out.rebuild();
    for ii = 1:numel(out)
      if ~eq(r(ii),out(ii), 'UUID', 'proctime', 'methodInvars'), atest = false; end
    end
    
    % </AlgoCode>
  else
    atest = false;
  end
  
  % Return a result structure
  stack = dbstack;
  if numel(objs) > 1
    stack(1).name = sprintf('%s %dx%d', stack(1).name, size(objs));
  end
  result = utp_prepare_result(atest, stest, stack, ['utp_' class(objs) '_' method]);
end