view testing/utp_1.1/utps/smodel/utp_smodel_setAliases.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

% UTP_SMODEL_SETALIASES a set of UTPs for the smodel/setAliases method
%
% M Hewitson 06-08-08
%
% $Id: utp_smodel_setAliases.m,v 1.1 2011/04/11 19:45:22 ingo Exp $
%

% <MethodDescription>
%
% The setAliases method of the smodel class sets the 'aliasNames' and
% 'aliasValues' properties.
%
% </MethodDescription>

function results = utp_smodel_setAliases(varargin)
  
  % Check the inputs
  if nargin == 0
    
    % Some keywords
    cl      = 'smodel';
    mthd    = 'setAliases';
    
    disp('******************************************************');
    disp(['****  Running UTPs for ' cl '/' mthd]);
    disp('******************************************************');
    
    % Test objects
    s1 = smodel('a1*x1 + a2*x2 + a3*x3');
    s1.setName();
    
    s2 = smodel('a1*x1 + a2*x2');
    s2.setName();
    
    s3 = smodel('a1*x1');
    s3.setName();
    
    sv = [s1, s2, s1];
    sm = [s1, s2, s1; s1, s2, s1];
    
    % Exception list for the UTPs:
    [ple1,ple2,ple3,ple4,ple5,ple6] = get_test_ples();
    
    % The setter method have different possibilities to set a property
    args1 = {'x1', 123};                  % obj.setAliases('x1', 123)
    args2 = {'x1', 123, 'x2', 'asd'};     % obj.setAliases('x1', 123, 'x2', 'asd')
    args3 = {{'x1', 'x2'}, {'asd', 123}}; % obj.setAliases({'x1', 'x2'}, {'asd', 123})
    args4 = {plist('names', 'x1', 'values', 123)}; % obj.setAliases(plist('names', 'x1', 'values', 123))
    args5 = {plist('names', {'x1', 'x2'}, 'values', {123, 'asd'})};
    
    % Run the general tests
    results(1)  = utp_01();
    results(2)  = utp_genericAnyShape(mthd, sv, args1, @algoTests);
    results(3)  = utp_genericAnyShape(mthd, sv, args2, @algoTests);
    results(4)  = utp_genericAnyShape(mthd, sv, args3, @algoTests);
    results(5)  = utp_genericAnyShape(mthd, sv, args4, @algoTests);
    results(6)  = utp_genericAnyShape(mthd, sv, args5, @algoTests);
    results(7)  = utp_genericAnyShape(mthd, sm, args2, @algoTests);
    results(8)  = utp_genericList(mthd, s1, s2, s3, args3, @algoTests);
    results(9)  = utp_genericHistory(mthd, s1, args2, ple2);
    results(10) = utp_genericModify(mthd, s1, args5, @algoTests, ple1);
    results(11) = utp_genericOutput(mthd, s1, s2, args2, @algoTests, ple2);        % test the outputs
    
    disp('Done.');
    disp('******************************************************');
    
  elseif nargin == 1 % Check for UTP functions
    if strcmp(varargin{1}, 'isutp')
      results = 1;
    else
      results = 0;
    end
  else
    error('### Incorrect inputs')
  end
  
  % Check that the property have the correct value
  function atest = algoTests(in, out, idx, argsin)
    atest = true;
    % Check that the input and output objects are the same except the
    % property 'aliases' and the history
    ple = plist('EXCEPTIONS', {'created', 'proctime', 'UUID', 'hist', 'aliasNames', 'aliasValues'});
    if ~eq(in(idx), out(idx), ple), atest = false; end
    if ~eq(in(idx).hist, out(idx).hist.inhists), atest = false; end
    % Check that the parameter gets the correct value.
    if isa(argsin{1}, 'plist') && argsin{1}.isparam('names') && argsin{1}.isparam('values')
      argsin = argsin{1};
      % The value was set with a plist.
      names  = cellstr(argsin.find('names'));
      values = argsin.find('values');
      if ~iscell(values)
        values = num2cell(values);
      end
    else
      if numel(argsin) == 2 && iscell(argsin{1}) && iscell(argsin{2})
        names  = argsin{1};
        values = argsin{2};
      else
        nArgsin = numel(argsin);
        names  = argsin(1:2:nArgsin);
        values = argsin(2:2:nArgsin);
      end
    end
    
    % Check 'aliasNames' and 'aliasValues'
    if ~isequal(out(idx).aliasNames,  names),  atest = false; end
    if ~isequal(out(idx).aliasValues, values), atest = false; end
  end
  
  %% UTP_01
  
  % <TestDescription>
  %
  % Tests that the getInfo call works for this method.
  %
  % </TestDescription>
  function result = utp_01
    
    
    % <SyntaxDescription>
    %
    % Test that the getInfo call works for no sets, all sets, and each set
    % individually.
    %
    % </SyntaxDescription>
    
    try
      % <SyntaxCode>
      % Call for no sets
      io(1) = feval('smodel.getInfo', mthd, 'none');
      % Call for all sets
      io(2) = feval('smodel.getInfo', mthd);
      % Call for each set
      for kk=1:numel(io(2).sets)
        io(kk+2) = feval('smodel.getInfo', mthd, io(2).sets{kk});
      end
      % </SyntaxCode>
      stest = true;
    catch err
      disp(err.message)
      stest = false;
    end
    
    % <AlgoDescription>
    %
    % 1) Check that getInfo call returned an minfo object in all cases.
    % 2) Check that all plists have the correct parameters.
    %
    % </AlgoDescription>
    
    atest = true;
    if stest
      % <AlgoCode>
      % check we have minfo objects
      if isa(io, 'minfo')
        % SET 'None'
        if ~isempty(io(1).sets), atest = false; end
        if ~isempty(io(1).plists), atest = false; end
        % Check all Sets
        if ~any(strcmpi(io(2).sets, 'Default')), atest = false; end
        if numel(io(2).plists) ~= numel(io(2).sets), atest = false; end
        % SET 'Default'
        if io(3).plists.nparams ~= 2, atest = false; end
        % Check key
        if ~io(3).plists.isparam('names'), atest = false; end
        if ~io(3).plists.isparam('values'), atest = false; end
        % Check default value
        if ~isEmptyCell(io(3).plists.find('names')), atest = false; end
        if ~isEmptyCell(io(3).plists.find('values')), atest = false; end
        % Check options
        if ~isequal(io(3).plists.getOptionsForParam('names'),  {{}}), atest = false; end
        if ~isequal(io(3).plists.getOptionsForParam('values'), {{}}), atest = false; end
      end
      % </AlgoCode>
    else
      atest = false;
    end
    
    % Return a result structure
    result = utp_prepare_result(atest, stest, dbstack, mfilename);
  end % END UTP_01
  
end