No BSD License  

Highlights from
MATLAB/Simulink Unit Test Framework

from MATLAB/Simulink Unit Test Framework by Carl Kritzinger
A unit test framework for matlab and simulink components

test_case_result_generator(test_case)
function result = test_case_result_generator(test_case)

% test_case_result_generator - analise the result of a of a
% praticular test case, resturning a string detailing the result
%
% Inputs:
%    test_case - structure containing details of the unit test case
%
% Outputs:
%    result - string containing the result.
%
% Example:
%    result = test_case_result_generator(test_case)
%
% Other m-files required: none
%
% See also: unit_test,  run_unit_test_batch, make_simulink_unit_test

% Author: Carl Kritzinger
% KAT DSP Team
% email address: carl@ska.ac.za
% November 2005

  %------------- MAIN --------------

  %each comparator is represented by a string 
  %for every comparator we have to write a new test function 
if ~strcmp(test_case.unhandled_error,'')
    
    result = ['TEST FAILED : caused unhandled error : ' test_case.unhandled_error ];
    
elseif strcmp(test_case.comparator,'exactly equal')
    
    result = test_exactly_equal(test_case);
    
elseif strcmp(test_case.comparator,'approximately equal')

    result = test_approximately_equal(test_case);

else
    
    result = 'INVALID TEST CASE';
        
end


function result = test_exactly_equal(test_case)

    okay = 1;
    for kk = 1:length(test_case.outputs)

        if(any(test_case.expected_outputs{kk}.signals.values ~= test_case.outputs{kk}))
            okay = 0;
        end

    end

    if(okay == 1)
        result = 'test passed';
    else
        result = 'test failed';
    end
    
function result = test_approximately_equal(test_case)
      
    okay = 1;
    for kk = 1:length(test_case.outputs)

        if(any((test_case.expected_outputs{kk}.signals.values - test_case.outputs{kk}) > test_case.tolerance))
            okay = 0;
        end

    end

    if(okay == 1)
        result = 'test passed';
    else
        result = 'test failed';
    end

Contact us at files@mathworks.com