Home > matpower7.0 > lib > t > t_have_fcn.m

t_have_fcn

PURPOSE ^

T_HAVE_FCN Tests for HAVE_FCN.

SYNOPSIS ^

function t_have_fcn(quiet)

DESCRIPTION ^

T_HAVE_FCN  Tests for HAVE_FCN.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function t_have_fcn(quiet)
0002 %T_HAVE_FCN  Tests for HAVE_FCN.
0003 
0004 %   MATPOWER
0005 %   Copyright (c) 2019, Power Systems Engineering Research Center (PSERC)
0006 %   by Ray Zimmerman, PSERC Cornell
0007 %
0008 %   This file is part of MATPOWER.
0009 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0010 %   See https://matpower.org for more info.
0011 
0012 if nargin < 1
0013     quiet = 0;
0014 end
0015 
0016 n_tests = 20;
0017 
0018 t_begin(n_tests, quiet);
0019 
0020 %% save cache
0021 saved = have_fcn('all', 'get_cache');
0022 
0023 %% test set_cache/get_cache
0024 t = 'set_cache/get_cache';
0025 e = struct('foo', 2, 'bar', 3, 'baz', 'boz');
0026 have_fcn(e, 'set_cache');
0027 t_ok(isequal(have_fcn('all', 'get_cache'), e), t);
0028 have_fcn(64, 'set_cache');
0029 t_ok(isequal(have_fcn('all', 'get_cache'), 64), t);
0030 
0031 %% clear cache
0032 have_fcn(struct(), 'set_cache');
0033 
0034 %% Matlab vs. Octave
0035 if exist('OCTAVE_VERSION', 'builtin') == 5
0036     t_ok(have_fcn('octave'), 'Octave');
0037     t_ok(~have_fcn('matlab'), 'not Matlab');
0038 else
0039     t_ok(~have_fcn('octave'), 'not Octave');
0040     t_ok(have_fcn('matlab'), 'Matlab');
0041 end
0042 
0043 t = '$MATPOWER/t/t_feval_w_path must not be in path';
0044 t_ok(exist('rithmaticker') ~= 2, t);
0045 
0046 %% find path to this test file
0047 cwd = pwd;
0048 [p, n, e] = fileparts(which('t_have_fcn'));
0049 
0050 %% initially not available
0051 t = 'have_fcn(''rithmaticker'')';
0052 t_ok(have_fcn('rithmaticker') == 0, [t ' : not available']);
0053 
0054 %% switch dir so it is available
0055 cd(fullfile(p, 't_feval_w_path'));
0056 cwd2 = pwd;
0057 
0058 t = '$MATPOWER/t/t_feval_w_path must be in path';
0059 t_ok(exist('rithmaticker') == 2, t);
0060 
0061 %% still not available (cached)
0062 t = 'have_fcn(''rithmaticker'')';
0063 t_ok(have_fcn('rithmaticker') == 0, [t ' : still not available (cached)']);
0064 
0065 %% clear cache, check again
0066 have_fcn('rithmaticker', 'clear_cache');
0067 t_ok(have_fcn('rithmaticker') == 1, [t ' : available (cache cleared)']);
0068 
0069 cd(cwd);
0070 t = 'successful switch to original working directory';
0071 t_ok(strcmp(cwd, pwd), t);
0072 
0073 t = 'have_fcn(''rithmaticker'')';
0074 t_ok(have_fcn('rithmaticker') == 1, [t ' : still available (cached)']);
0075 
0076 t = 'have_fcn(''rithmaticker'', ''vstr'')';
0077 t_ok(strcmp(have_fcn('rithmaticker', 'vstr'), '3.1.4'), t);
0078 
0079 t = 'have_fcn(''rithmaticker'', ''vnum'')';
0080 t_is(have_fcn('rithmaticker', 'vnum'), 3.001004, 12, t);
0081 
0082 t = 'have_fcn(''rithmaticker'', ''date'')';
0083 t_ok(strcmp(have_fcn('rithmaticker', 'date'), '30-May-2019'), t);
0084 
0085 t = 'have_fcn(''rithmaticker'', ''all'')';
0086 rv = have_fcn('rithmaticker', 'all');
0087 t_ok(isstruct(rv), [t ' : isstruct']);
0088 t_is(rv.av, 1, 12, [t ' : av']);
0089 t_ok(strcmp(rv.vstr, '3.1.4'), [t ' : vstr']);
0090 t_is(rv.vnum, 3.001004, 12, [t ' : vnum']);
0091 t_ok(strcmp(rv.date, '30-May-2019'), [t ' : date']);
0092 
0093 %% clear cache, check again
0094 t = 'have_fcn(''rithmaticker'')';
0095 have_fcn('all', 'clear_cache');
0096 t_ok(have_fcn('rithmaticker') == 0, [t ' : not available (cache cleared)']);
0097 
0098 %% restore cache
0099 have_fcn(saved, 'set_cache');
0100 
0101 t_end;

Generated on Mon 24-Jun-2019 15:58:45 by m2html © 2005