runElkTest

PURPOSE ^

unit testing module for ELK

SYNOPSIS ^

function result = runElkTest(testCase, mode)

DESCRIPTION ^

 unit testing module for ELK

 Syntax: runElkTest

 A set of test cases is executed that covers a large percentage of the
   provided features. It is recommended to execute it once for a new
   installation to become aware of issues that cannot be covered during
   development: MATLAB version, compiler version, operating system.

 You need to install the MATLAB xunit Test Framework to run this function.
   It can be obtained, in the <a href="http://www.mathworks.com/matlabcentral/fileexchange/22846-matlab-xunit-test-framework">MATLAB Central</a>.

 See also: configElk

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function result = runElkTest(testCase, mode)
0002 % unit testing module for ELK
0003 %
0004 % Syntax: runElkTest
0005 %
0006 % A set of test cases is executed that covers a large percentage of the
0007 %   provided features. It is recommended to execute it once for a new
0008 %   installation to become aware of issues that cannot be covered during
0009 %   development: MATLAB version, compiler version, operating system.
0010 %
0011 % You need to install the MATLAB xunit Test Framework to run this function.
0012 %   It can be obtained, in the <a href="http://www.mathworks.com/matlabcentral/fileexchange/22846-matlab-xunit-test-framework">MATLAB Central</a>.
0013 %
0014 % See also: configElk
0015 
0016 % The elk-library: convex geometry applied to crystallization modeling.
0017 %   Copyright (C) 2012 Alexander Reinhold
0018 %
0019 % This program is free software: you can redistribute it and/or modify it
0020 %   under the terms of the GNU General Public License as published by the
0021 %   Free Software Foundation, either version 3 of the License, or (at your
0022 %   option) any later version.
0023 %
0024 % This program is distributed in the hope that it will be useful, but
0025 %   WITHOUT ANY WARRANTY; without even the implied warranty of
0026 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0027 %   General Public License for more details.
0028 %
0029 % You should have received a copy of the GNU General Public License along
0030 %   with this program.  If not, see <http://www.gnu.org/licenses/>.
0031 
0032 %% Setup test sets
0033 % the following registers folder and case-name pairs OR aggregates already
0034 %   registered pais to test-sets
0035 testList.tmpThis =  {'polytope/test', 'testPolytopeConversion:testConvertHrepToVrepUnbounded'};
0036 testList.polytopeCore = {'polytope/test', 'testPolytopeCore'};
0037 testList.polytopeConversion = {'polytope/test', 'testPolytopeConversion'};
0038 testList.polytopeOperation = {'polytope/test', 'testPolytopeOperation'};
0039 testList.polytopeView = {'polytope/test', 'testPolytopeView'};
0040 testList.polytopeMeasure = {'polytope/test', 'testPolytopeMeasure'};
0041 testList.polytopeBugList = {'polytope/test', 'testPolytopeBugList'};
0042 testList.crystalCore = {'crystal/test', 'testCrystal'};
0043 testList.decompositionCore = {'decomposition/test', 'testDecompositionCore'};
0044 testList.distributionCore = {'distribution/test', 'testDistributionCore'};
0045 testList.basicTest = {...
0046     testList.polytopeCore, ...
0047     testList.polytopeConversion, ...
0048     testList.polytopeOperation, ...
0049     testList.polytopeView, ...
0050     testList.polytopeMeasure, ...
0051     testList.crystalCore, ...
0052     testList.decompositionCore, ...
0053     testList.distributionCore};
0054 testList.extraTest = {...
0055     testList.polytopeBugList};
0056 
0057 %% Input handling
0058 if ~exist('mode', 'var') || isempty(mode)
0059     mode = 'manual';
0060 end
0061 if ~exist('testCase', 'var') || isempty(testCase)
0062     testCase = 'basicTest';
0063 end
0064 if ~isfield(testList, testCase)
0065     error('elk:test:invalidCase', 'The specified test case does not exist, try ''basicTest''.');
0066 end
0067 result = 0;
0068 
0069 %% Initialize utilities and location
0070 callLocation = pwd;
0071 myLocation = fileparts(mfilename('fullpath'));
0072 cd(myLocation);
0073 run ../../extern/mxunit/configMxUnit
0074 
0075 %% Start tests
0076 clc
0077 % ensure expected format: cell array of cell arrays of path/case-name
0078 %   pairs.
0079 thisTestSet = testList.(testCase);
0080 if ischar(thisTestSet{1})
0081     thisTestSet = {thisTestSet};
0082 end
0083 % cycle through file/case-name pairs
0084 for iTestCase = 1:length(thisTestSet)
0085     thisFolder = fullfile(['..' filesep thisTestSet{iTestCase}{1}]);
0086     thisFile = thisTestSet{iTestCase}{2};
0087     thisLogFile = [thisTestSet{iTestCase}{2} '.log'];
0088     
0089     % execute from test-file location (these are private functions)
0090     cd(thisFolder)
0091     switch mode
0092         case 'auto'
0093             thisResult = runtests(thisFile, '-verbose', ...
0094                 '-logfile', thisLogFile);
0095             type(thisLogFile);
0096         case 'manual'
0097             thisResult = runtests(thisFile);
0098             disp(' ')
0099             disp('--------------------------------------------------------------------------');
0100         otherwise
0101             error('elk:test:invalidCase', ...
0102                 'The specified test mode does not exist, try ''manual'' or ''auto''.');
0103     end
0104     % go back to /test folder
0105     cd(myLocation);
0106     
0107     % store number of passed tests
0108     result = result + thisResult;
0109 end
0110 
0111 %% post conditioning
0112 % give a wanring on changed search path
0113 warning OFF BACKTRACE
0114 warning('elk:searchPath', 'MATLAB search path was changed to use mxunit.');
0115 warning ON BACKTRACE
0116 % go back to callers location
0117 cd(callLocation)
0118 
0119 %% display summary
0120 disp('');
0121 if result == length(thisTestSet)
0122     disp(['SUMMARY: PASSED (' num2str(result) ' out of ' ...
0123           num2str(length(thisTestSet)) ')']);
0124 else
0125     disp(['SUMMARY: FAILED (' num2str(result) ' out of ' ...
0126           num2str(length(thisTestSet)) ')']);
0127     error('elk:test:issuesFound', 'unit testing found issues (see above)');
0128 end
0129 
0130 %% handle output
0131 if nargout == 0
0132     clear result;
0133 end
0134 
0135 end

Generated on Sat 18-Jul-2015 16:45:31 by m2html © 2005