Home > matpower7.1 > mptest > lib > t > t_have_feature.m

t_have_feature

PURPOSE ^

T_HAVE_FEATURE Tests for HAVE_FEATURE.

SYNOPSIS ^

function t_have_feature(quiet)

DESCRIPTION ^

T_HAVE_FEATURE  Tests for HAVE_FEATURE.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function t_have_feature(quiet)
0002 %T_HAVE_FEATURE  Tests for HAVE_FEATURE.
0003 
0004 %   MP-Test
0005 %   Copyright (c) 2004-2020, Power Systems Engineering Research Center (PSERC)
0006 %   by Ray Zimmerman, PSERC Cornell
0007 %
0008 %   This file is part of MP-Test.
0009 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0010 %   See https://github.com/MATPOWER/mptest 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_feature('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_feature(e, 'set_cache');
0027 t_ok(isequal(have_feature('all', 'get_cache'), e), t);
0028 have_feature(64, 'set_cache');
0029 t_ok(isequal(have_feature('all', 'get_cache'), 64), t);
0030 
0031 %% clear cache
0032 have_feature(struct(), 'set_cache');
0033 
0034 %% Matlab vs. Octave
0035 if exist('OCTAVE_VERSION', 'builtin') == 5
0036     t_ok(have_feature('octave'), 'Octave');
0037     t_ok(~have_feature('matlab'), 'not Matlab');
0038 else
0039     t_ok(~have_feature('octave'), 'not Octave');
0040     t_ok(have_feature('matlab'), 'Matlab');
0041 end
0042 
0043 t = '<MPOM>/lib/t/t_have_feature 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_feature'));
0049 
0050 %% initially not available
0051 t = 'have_feature(''rithmaticker'')';
0052 t_ok(have_feature('rithmaticker') == 0, [t ' : not available']);
0053 
0054 %% switch dir so it is available
0055 cd(fullfile(p, 't_have_feature'));
0056 cwd2 = pwd;
0057 
0058 t = '<MPOM>/lib/t/t_have_feature must be in path';
0059 t_ok(exist('rithmaticker') == 2, t);
0060 
0061 %% still not available (cached)
0062 t = 'have_feature(''rithmaticker'')';
0063 t_ok(have_feature('rithmaticker') == 0, [t ' : still not available (cached)']);
0064 
0065 %% clear cache, check again
0066 have_feature('rithmaticker', 'clear_cache');
0067 t_ok(have_feature('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_feature(''rithmaticker'')';
0074 t_ok(have_feature('rithmaticker') == 1, [t ' : still available (cached)']);
0075 
0076 t = 'have_feature(''rithmaticker'', ''vstr'')';
0077 t_ok(strcmp(have_feature('rithmaticker', 'vstr'), '3.1.4'), t);
0078 
0079 t = 'have_feature(''rithmaticker'', ''vnum'')';
0080 t_is(have_feature('rithmaticker', 'vnum'), 3.001004, 12, t);
0081 
0082 t = 'have_feature(''rithmaticker'', ''date'')';
0083 t_ok(strcmp(have_feature('rithmaticker', 'date'), '30-May-2019'), t);
0084 
0085 t = 'have_feature(''rithmaticker'', ''all'')';
0086 rv = have_feature('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_feature(''rithmaticker'')';
0095 have_feature('all', 'clear_cache');
0096 t_ok(have_feature('rithmaticker') == 0, [t ' : not available (cache cleared)']);
0097 
0098 %% restore cache
0099 have_feature(saved, 'set_cache');
0100 
0101 t_end;

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