0001 function t_have_fcn(quiet)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 if nargin < 1
0013 quiet = 0;
0014 end
0015
0016 n_tests = 20;
0017
0018 t_begin(n_tests, quiet);
0019
0020
0021 saved = have_fcn('all', 'get_cache');
0022
0023
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
0032 have_fcn(struct(), 'set_cache');
0033
0034
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
0047 cwd = pwd;
0048 [p, n, e] = fileparts(which('t_have_fcn'));
0049
0050
0051 t = 'have_fcn(''rithmaticker'')';
0052 t_ok(have_fcn('rithmaticker') == 0, [t ' : not available']);
0053
0054
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
0062 t = 'have_fcn(''rithmaticker'')';
0063 t_ok(have_fcn('rithmaticker') == 0, [t ' : still not available (cached)']);
0064
0065
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
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
0099 have_fcn(saved, 'set_cache');
0100
0101 t_end;