Skip to content

Unit Testing Function Template

Erik A. Roberts edited this page Apr 10, 2017 · 3 revisions

notice: local function uses different function: ds.saveAutoGenTestDataLocalFn

function [fout1, fout2] = fnName(fin1, fin2, varargin)

   %% localfn output
   if ~nargin
      fout1 = localfunctions;
      return
   end

    %% auto_gen_test_data_flag argin
    options = ds.checkOptions(varargin,{'auto_gen_test_data_flag',0,{0,1}},false);
    if options.auto_gen_test_data_flag
      % specific to this function
      varargs = varargin;
      varargs{find(strcmp(varargs, 'auto_gen_test_data_flag'))+1} = 0;
      argin = [{fin1},{fin2}, varargs];
    end

    %% main fn body here
    lOut = localfn(lIn, varargin);

    %% auto_gen_test_data_flag argout
    if options.auto_gen_test_data_flag
      % specific to this function
      argout = {output, fout2};
  
      ds.saveAutoGenTestData(argin, argout);
    end

end

%% local functions
function out1 = localfn(in1, varargin)
    if options.auto_gen_test_data_flag
      % specific to this function
      varargs = varargin;
      varargs{find(strcmp(varargs, 'auto_gen_test_data_flag'))+1} = 0;
      argin = [{in1}, varargs];
    end

    %% local fn body

    %% auto_gen_test_data_flag argout
    if options.auto_gen_test_data_flag
      % specific to this function
      argout = {out1};
  
      ds.saveAutoGenTestDataLocalFn(argin, argout); % localfn
    end

end
You can’t perform that action at this time.