# HG changeset patch # User Rik # Date 1548263173 28800 # Node ID eaebee6d4f56a10207b152109fa0dbe2ffc00884 # Parent 0f187a956d47b23067690340551118c5a0d6f0ba verLessThan.m: review newly added function (bug #55525). * verLessThan.m: Use standard documentation phrasing for a function which returns true/false. Use @qcode instead of @code for strings in documentation. Use standard variable name "retval" for output. Validate number of input arguments to function. Use rows() rather than "size (..., 1)" for clarity. Capitalize input variable names in error() strings. Do not end error strings with a period. Use single quotes for strings containing double quotes to avoid the unclarity of doubling '"'. Add input validation BIST tests for number of arguments. * __unimplemented__.m: Remove verLessThan from list of unimplemented functions. diff -r 0f187a956d47 -r eaebee6d4f56 scripts/help/__unimplemented__.m --- a/scripts/help/__unimplemented__.m Mon Jan 21 17:52:20 2019 -0500 +++ b/scripts/help/__unimplemented__.m Wed Jan 23 09:06:13 2019 -0800 @@ -1328,7 +1328,6 @@ "varfun", "vartype", "verctrl", - "verLessThan", "vertexAttachments", "vertexNormal", "VideoReader", diff -r 0f187a956d47 -r eaebee6d4f56 scripts/miscellaneous/verLessThan.m --- a/scripts/miscellaneous/verLessThan.m Mon Jan 21 17:52:20 2019 -0500 +++ b/scripts/miscellaneous/verLessThan.m Wed Jan 23 09:06:13 2019 -0800 @@ -17,17 +17,20 @@ ## . ## -*- texinfo -*- -## @deftypefn {} {@var{out} =} verLessThan (@var{package}, @var{version}) -## True if the installed version of the package is less than @var{version}. +## @deftypefn {} {} verLessThan (@var{package}, @var{version}) +## Return true if the installed version of the package is less than +## @var{version}. ## -## @var{package} is the name of the package to check the version of. Use -## @code{"Octave"} as the @var{package} to check the version of Octave itself. +## @var{package} is the name of the package to check. Use @qcode{"Octave"} as +## the @var{package} to check the version of Octave itself. ## -## @var{version} is the version to compare it to. A version is a string in the -## format accepted by @ref{XREFcompare_versions, ,compare_versions function}: -## an arbitrarily long string made of numeric and period characters possibly -## followed by an arbitrary string (e.g., @code{"1.2.3"}, @code{"0.3"}, -## @code{"0.1.2+"}, or @code{"1.2.3.4-test1"}). +## @var{version} is the version to compare it to. A version is a string in the +## format accepted by @code{compare_versions}: an arbitrarily long string +## composed of numeric and period characters, possibly followed by an arbitrary +## string (e.g., @qcode{"1.2.3"}, @qcode{"0.3"}, @qcode{"0.1.2+"}, or +## @qcode{"1.2.3.4-test1"}). +## +## Examples: ## ## @example ## @group @@ -43,25 +46,35 @@ ## @seealso{compare_versions, version, ver, pkg} ## @end deftypefn -function out = verLessThan(package, version) +function retval = verLessThan (package, version) - if (! ischar (package) || size (package, 1) > 1) - error ("verLessThan: package must be a char vector"); + if (nargin != 2) + print_usage (); + endif + + if (! ischar (package) || rows (package) != 1) + error ("verLessThan: PACKAGE must be a string"); endif v = ver (); idx = find (strcmpi (package, {v.Name})); if (isempty (idx)) - error ("verLessThan: Package ""%s"" is not installed.", package); + error ('verLessThan: package "%s" is not installed', package); endif - out = compare_versions (v(idx).Version, version, "<"); + retval = compare_versions (v(idx).Version, version, "<"); endfunction + %!assert (! verLessThan ("Octave", "3.0.0")) %!assert (verLessThan ("Octave", "99.9.9")) -%!error + +## Test input validation +%!error verLessThan () +%!error verLessThan ("a") +%!error verLessThan ("a", "1", "b") +%!error %! verLessThan ("no-such-package", "1.1.1") %!error %! verLessThan ("Octave", 4.1)