Home > matpower7.1 > mptest > lib > t_run_tests.m

t_run_tests

PURPOSE ^

T_RUN_TESTS Run a series of tests.

SYNOPSIS ^

function all_ok_ = t_run_tests(test_names, verbose)

DESCRIPTION ^

T_RUN_TESTS  Run a series of tests.
   ALL_OK = T_RUN_TESTS(TEST_NAMES, VERBOSE)

   Runs a set of tests whose names are given in the cell array TEST_NAMES.
   If the optional parameter VERBOSE is true, it prints the details of the
   individual tests. Optionally returns an ALL_OK flag, equal to 1 if all
   tests pass (and the number matches the expected number), 0 otherwise.

   Example:
       tests{end+1} = 't_loadcase';
       tests{end+1} = 't_jacobian';
       tests{end+1} = 't_hessian';
       t_run_tests( tests, verbose );

   See also T_BEGIN, T_END.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function all_ok_ = t_run_tests(test_names, verbose)
0002 %T_RUN_TESTS  Run a series of tests.
0003 %   ALL_OK = T_RUN_TESTS(TEST_NAMES, VERBOSE)
0004 %
0005 %   Runs a set of tests whose names are given in the cell array TEST_NAMES.
0006 %   If the optional parameter VERBOSE is true, it prints the details of the
0007 %   individual tests. Optionally returns an ALL_OK flag, equal to 1 if all
0008 %   tests pass (and the number matches the expected number), 0 otherwise.
0009 %
0010 %   Example:
0011 %       tests{end+1} = 't_loadcase';
0012 %       tests{end+1} = 't_jacobian';
0013 %       tests{end+1} = 't_hessian';
0014 %       t_run_tests( tests, verbose );
0015 %
0016 %   See also T_BEGIN, T_END.
0017 
0018 %   MP-Test
0019 %   Copyright (c) 2004-2020, Power Systems Engineering Research Center (PSERC)
0020 %   by Ray Zimmerman, PSERC Cornell
0021 %
0022 %   This file is part of MP-Test.
0023 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0024 %   See https://github.com/MATPOWER/mptest for more info.
0025 
0026 if nargin < 2
0027     verbose = 0;
0028 end
0029 
0030 global t_num_of_tests;
0031 global t_counter;
0032 global t_ok_cnt;
0033 global t_not_ok_cnt;
0034 global t_skip_cnt;
0035 
0036 %% figure out padding for printing
0037 if ~verbose
0038     len = zeros(length(test_names), 1);
0039     for k = 1:length(test_names)
0040         len(k) = length(test_names{k});
0041     end
0042     maxlen = max(len);
0043 end
0044 
0045 %% initialize statistics
0046 num_of_tests = 0;
0047 counter = 0;
0048 ok_cnt = 0;
0049 not_ok_cnt = 0;
0050 skip_cnt = 0;
0051 
0052 t0 = tic;
0053 for k = 1:length(test_names)
0054     if verbose
0055         fprintf('\n----------  %s  ----------\n', test_names{k});
0056     else
0057         pad = maxlen + 4 - length(test_names{k});
0058         fprintf('%s', test_names{k});
0059         for m = 1:pad, fprintf('.'); end
0060     end
0061     feval( test_names{k}, ~verbose );
0062     
0063     num_of_tests    = num_of_tests  + t_num_of_tests;
0064     counter         = counter       + t_counter;
0065     ok_cnt          = ok_cnt        + t_ok_cnt;
0066     not_ok_cnt      = not_ok_cnt    + t_not_ok_cnt;
0067     skip_cnt        = skip_cnt      + t_skip_cnt;
0068 end
0069 
0070 if verbose
0071     fprintf('\n\n----------  Summary  ----------\n');
0072 end
0073 if counter == num_of_tests && counter == ok_cnt + skip_cnt && not_ok_cnt == 0
0074     all_ok = 1;
0075     if skip_cnt
0076         fprintf('All tests successful (%d passed, %d skipped of %d)', ...
0077             ok_cnt, skip_cnt, num_of_tests);
0078     else
0079         fprintf('All tests successful (%d of %d)', ok_cnt, num_of_tests);
0080     end
0081 else
0082     all_ok = 0;
0083     fprintf('Ran %d of %d tests: %d passed, %d failed', ...
0084         counter, num_of_tests, ok_cnt, not_ok_cnt);
0085     if skip_cnt
0086         fprintf(', %d skipped', skip_cnt);
0087     end
0088 end
0089 fprintf('\nElapsed time %.2f seconds.\n', toc(t0));
0090 
0091 if nargout
0092     all_ok_ = all_ok;   %% copy to optional output arg
0093 end

Generated on Fri 09-Oct-2020 11:21:31 by m2html © 2005