Debian Codegraph @

test/suites/private/isEnvironment.m

raw
1 function bool = isEnvironment(wantedEnvironment, varargin)
2 % ISENVIRONMENT check for a particular environment (MATLAB/Octave)
3 %
4 % This function returns TRUE when it is run within the "wantedEnvironment"
5 % (e.g. MATLAB or Octave). This environment can be tested to be a particular
6 % version or be older/newer than a specified version.
7 %
8 % Usage:
9 %
10 % ISENVIRONMENT(ENV)
11 % ISENVIRONMENT(ENV, VERSION)
12 % ISENVIRONMENT(ENV, OP, VERSION)
13 %
14 % Parameters:
15 % - `ENV`: the expected environment (e.g. 'MATLAB' or 'Octave')
16 % - `VERSION`: a version number or string to compare against
17 % e.g. "3.4" or equivalently [3,4]
18 % - `OP`: comparison operator (e.g. '==', '<=', '<', ...) to define a range
19 % of version numbers that return a TRUE value
20 %
21 % When `OP` is not specified, "==" is used.
22 % When no `VERSION` is specified, all versions pass the check.
23 %
24 % See also: isMATLAB, isOctave, versionCompare
25 [env, thisVersion] = getEnvironment();
26 bool = strcmpi(env, wantedEnvironment);
27
28 switch numel(varargin)
29 case 0 % nothing to be done
30 return
31
32 case 1 % check equality
33 version = varargin{1};
34 operator = '==';
35 bool = bool && versionCompare(thisVersion, operator, version);
36
37 case 2
38 operator = varargin{1};
39 version = varargin{2};
40 bool = bool && versionCompare(thisVersion, operator, version);
41
42 otherwise
43 error('isEnvironment:BadNumberOfArguments', ...
44 '"isEnvironment" was called with an incorrect number of arguments.');
45 end
46 end