changeset 28723:dd9efd873596 stable

maint: Use Octave coding conventions in mustBe* functions. * mustBeFinite.m, mustBeGreaterThan.m, mustBeGreaterThanOrEqual.m, mustBeInteger.m, mustBeLessThan.m, mustBeLessThanOrEqual.m, mustBeMember.m, mustBeNegative.m, mustBeNonNan.m, mustBeNonempty.m, mustBeNonnegative.m, mustBeNonpositive.m, mustBeNonsparse.m, mustBeNonzero.m, mustBeNumeric.m, mustBeNumericOrLogical.m, mustBePositive.m, mustBeReal.m: Use parentheses around conditional in if statement. Use space between not operator '!' and argument. Use two newlines after "endfunction" before starting BIST tests. Use semicolons in statements within %!test blocks. Don't use semicolons in %!error tests. Add expected string for %!error BIST tests. Add input validation for number of inputs and BIST tests to check validation.
author Rik <rik@octave.org>
date Fri, 11 Sep 2020 20:01:56 -0700
parents a2177e663979
children 08049eff8733 07c0df93ff9d
files scripts/miscellaneous/mustBeFinite.m scripts/miscellaneous/mustBeGreaterThan.m scripts/miscellaneous/mustBeGreaterThanOrEqual.m scripts/miscellaneous/mustBeInteger.m scripts/miscellaneous/mustBeLessThan.m scripts/miscellaneous/mustBeLessThanOrEqual.m scripts/miscellaneous/mustBeMember.m scripts/miscellaneous/mustBeNegative.m scripts/miscellaneous/mustBeNonNan.m scripts/miscellaneous/mustBeNonempty.m scripts/miscellaneous/mustBeNonnegative.m scripts/miscellaneous/mustBeNonpositive.m scripts/miscellaneous/mustBeNonsparse.m scripts/miscellaneous/mustBeNonzero.m scripts/miscellaneous/mustBeNumeric.m scripts/miscellaneous/mustBeNumericOrLogical.m scripts/miscellaneous/mustBePositive.m scripts/miscellaneous/mustBeReal.m
diffstat 18 files changed, 421 insertions(+), 312 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/miscellaneous/mustBeFinite.m	Fri Sep 11 15:39:17 2020 -0700
+++ b/scripts/miscellaneous/mustBeFinite.m	Fri Sep 11 20:01:56 2020 -0700
@@ -35,25 +35,33 @@
 ## @end deftypefn
 
 function mustBeFinite (x)
-  tf = isfinite (x);
-  if ! all (tf)
+
+  if (nargin != 1)
+    print_usage ();
+  endif
+
+  tf = isfinite (x(:));
+  if (! all (tf))
     label = inputname (1);
-    if isempty (label)
+    if (isempty (label))
       label = "input";
     endif
-    ix_bad = find (!tf);
-    error ("%s must be finite; got Infs in %d elements: indexes %s", ...
-      label, numel (ix_bad), mat2str (ix_bad));
+    bad_idx = find (! tf);
+    error ("%s must be finite; found %d non-finite elements: indexes %s",
+           label, numel (bad_idx), mat2str (bad_idx));
   endif
+
 endfunction
 
+
 %!test
 %! mustBeFinite ([]);
 %! mustBeFinite (42);
 %! mustBeFinite (-100:.1:100);
-%! mustBeFinite (int32(42))
+%! mustBeFinite (int32 (42));
 
-%!error mustBeFinite ();
-%!error mustBeFinite (Inf);
-%!error mustBeFinite ([1 2 3 Inf]);
-%!error mustBeFinite ([-Inf -1 0 1]);
+%!error <Invalid call> mustBeFinite ()
+%!error <found 1 non-finite> mustBeFinite (Inf)
+%!error <indexes 4> mustBeFinite ([1 2 3 Inf])
+%!error <indexes 1> mustBeFinite ([-Inf -1 0 1])
+%!error <indexes 1> mustBeFinite ([NaN -1])
--- a/scripts/miscellaneous/mustBeGreaterThan.m	Fri Sep 11 15:39:17 2020 -0700
+++ b/scripts/miscellaneous/mustBeGreaterThan.m	Fri Sep 11 20:01:56 2020 -0700
@@ -35,30 +35,39 @@
 ## @end deftypefn
 
 function mustBeGreaterThan (x, c)
-  tf = x > c;
-  tf = tf(:);
-  if ! all (tf)
+
+  if (nargin != 2)
+    print_usage ();
+  endif
+
+  tf = (x > c)(:);
+  if (! all (tf))
     label = inputname (1);
-    if isempty (label)
+    if (isempty (label))
       label = "input";
     endif
-    ix_bad = find (! tf);
+    bad_idx = find (! tf);
     try
-      bad = x(ix_bad);
-      errmsg = sprintf ("%s must be greater than %f; got %d elements that were not: values %s", ...
-        label, c, numel (ix_bad), mat2str (bad));
-    catch err
-      errmsg = sprintf ("%s must be greater than %f; got %d elements that were not: indexes %s", ...
-        label, c, numel (ix_bad), mat2str (ix_bad));
+      bad_val = x(bad_idx);
+      errmsg = sprintf ("%s must be greater than %f; found %d elements that were not: values %s", ...
+                        label, c, numel (bad_idx), mat2str (bad_val));
+    catch
+      errmsg = sprintf ("%s must be greater than %f; found %d elements that were not: indexes %s", ...
+                        label, c, numel (bad_idx), mat2str (bad_idx));
     end_try_catch
     error (errmsg);
   endif
+
 endfunction
 
+
 %!test
-%! mustBeGreaterThan (42, 0)
-%! mustBeGreaterThan (Inf, 9999)
+%! mustBeGreaterThan (42, 0);
+%! mustBeGreaterThan (Inf, 9999);
 
-%!error mustBeGreaterThan (42, 42)
-%!error mustBeGreaterThan (Inf, Inf)
-%!error mustBeGreaterThan (NaN, 0)
+%!error <Invalid call> mustBeGreaterThan ()
+%!error <Invalid call> mustBeGreaterThan (1)
+%!error <Invalid call> mustBeGreaterThan (1,2,3)
+%!error <input must be greater than 42> mustBeGreaterThan (42, 42)
+%!error <found 1 elements that were not> mustBeGreaterThan (Inf, Inf)
+%!error <must be greater than 0> mustBeGreaterThan (NaN, 0)
--- a/scripts/miscellaneous/mustBeGreaterThanOrEqual.m	Fri Sep 11 15:39:17 2020 -0700
+++ b/scripts/miscellaneous/mustBeGreaterThanOrEqual.m	Fri Sep 11 20:01:56 2020 -0700
@@ -31,38 +31,44 @@
 ## Raise an error if any element of the input @var{x} is not greater than
 ## or equal to @var{c}, as determined by @code{@var{x} >= @var{c}}.
 ##
-## @seealso{mustBeGreaterThan, mustBeLessThanOrEqual}
+## @seealso{mustBeGreaterThan, mustBeLessThanOrEqual, ge}
 ## @end deftypefn
 
 function mustBeGreaterThanOrEqual (x, c)
-  tf = x >= c;
-  tf = tf(:);
-  if ! all (tf)
+
+  if (nargin != 2)
+    print_usage ();
+  endif
+
+  tf = (x >= c)(:);
+  if (! all (tf))
     label = inputname (1);
-    if isempty (label)
+    if (isempty (label))
       label = "input";
     endif
-    ix_bad = find (! tf);
+    bad_idx = find (! tf);
     try
-      bad = x(ix_bad);
-      errmsg = sprintf ( ...
-        "%s must be greater than or equal to %f; got %d elements that were not: values %s", ...
-        label, c, numel (ix_bad), mat2str (bad));
-    catch err
-      errmsg = sprintf ( ...
-        "%s must be greater than or equal to %f; got %d elements that were not: indexes %s", ...
-        label, c, numel (ix_bad), mat2str (ix_bad));
+      bad_val = x(bad_idx);
+      errmsg = sprintf ("%s must be greater than or equal to %f; found %d elements that were not: values %s", ...
+                        label, c, numel (bad_idx), mat2str (bad_val));
+    catch
+      errmsg = sprintf ("%s must be greater than or equal to %f; found %d elements that were not: indexes %s", ...
+                        label, c, numel (bad_idx), mat2str (bad_idx));
     end_try_catch
     error (errmsg);
   endif
+
 endfunction
 
+
 %!test
-%! mustBeGreaterThanOrEqual (42, 0)
-%! mustBeGreaterThanOrEqual (Inf, 9999)
-%! mustBeGreaterThanOrEqual (42, 42)
-%! mustBeGreaterThanOrEqual (Inf, Inf)
+%! mustBeGreaterThanOrEqual (42, 0);
+%! mustBeGreaterThanOrEqual (Inf, 9999);
+%! mustBeGreaterThanOrEqual (42, 42);
+%! mustBeGreaterThanOrEqual (Inf, Inf);
 
-%!error mustBeGreaterThanOrEqual ()
-%!error mustBeGreaterThanOrEqual (42)
-%!error mustBeGreaterThanOrEqual (NaN, 0)
+%!error <Invalid call> mustBeGreaterThanOrEqual ()
+%!error <Invalid call> mustBeGreaterThanOrEqual (1)
+%!error <Invalid call> mustBeGreaterThanOrEqual (1,2,3)
+%!error <must be greater than or equal to 2> mustBeGreaterThanOrEqual (1, 2)
+%!error <must be greater than or equal to 0> mustBeGreaterThanOrEqual (NaN, 0)
--- a/scripts/miscellaneous/mustBeInteger.m	Fri Sep 11 15:39:17 2020 -0700
+++ b/scripts/miscellaneous/mustBeInteger.m	Fri Sep 11 20:01:56 2020 -0700
@@ -36,36 +36,47 @@
 ## @end deftypefn
 
 function mustBeInteger (x)
-  if isinteger (x) || islogical (x)
-    return
+
+  if (nargin != 1)
+    print_usage ();
   endif
+
+  if (isinteger (x) || islogical (x))
+    return;
+  endif
+
   but = [];
-  if ! isnumeric (x)
-    but = sprintf ("it was non-numeric (got a %s)", class (x));
-  elseif any (! isfinite (x))
-    but = "there were Inf values";
-  elseif ! isreal (x)
+  if (! isnumeric (x))
+    but = sprintf ("it was non-numeric (found a %s)", class (x));
+  elseif (! isreal (x))
     but = "it was complex";
-  elseif ! all (floor (x) == x)
+  elseif (any (! isfinite (x)))
+    but = "there were non-finite values";
+  elseif (any (x != fix (x)))
     but = "it had fractional values in some elements";
   end
-  if ! isempty (but)
+
+  if (! isempty (but))
     label = inputname (1);
-    if isempty (label)
+    if (isempty (label))
       label = "input";
     endif
     error ("%s must be integer-valued; but %s", label, but);
   endif
+
 endfunction
 
+
 %!test
-%! mustBeInteger ([])
-%! mustBeInteger (42)
-%! mustBeInteger (1:1000)
-%! mustBeInteger (int32(42))
+%! mustBeInteger ([]);
+%! mustBeInteger (42);
+%! mustBeInteger (1:1000);
+%! mustBeInteger (int32 (42));
+%! mustBeInteger (true);
 
-%!error mustBeInteger ()
-%!error mustBeInteger (1.23)
-%!error mustBeInteger ([1 2 3 4.4])
-%!error mustBeInteger (Inf)
-%!error mustBeInteger (NaN)
+%!error <Invalid call> mustBeInteger ()
+%!error <it was non-numeric> mustBeInteger ("Hello World")
+%!error <it was complex> mustBeInteger ([1, 2i])
+%!error <there were non-finite values> mustBeInteger (Inf)
+%!error <there were non-finite values> mustBeInteger (NaN)
+%!error <it had fractional values> mustBeInteger ([1 2 3 4.4])
--- a/scripts/miscellaneous/mustBeLessThan.m	Fri Sep 11 15:39:17 2020 -0700
+++ b/scripts/miscellaneous/mustBeLessThan.m	Fri Sep 11 20:01:56 2020 -0700
@@ -35,36 +35,42 @@
 ## @end deftypefn
 
 function mustBeLessThan (x, c)
-  tf = x < c;
-  tf = tf(:);
-  if ! all (tf)
+
+  if (nargin != 2)
+    print_usage ();
+  endif
+
+  tf = (x < c)(:);
+  if (! all (tf))
     label = inputname (1);
-    if isempty (label)
+    if (isempty (label))
       label = "input";
     endif
-    ix_bad = find (! tf);
+    bad_idx = find (! tf);
     try
-      bad = x(ix_bad);
-      errmsg = sprintf ( ...
-        "%s must be less than %f; got %d elements that were not: values %s", ...
-        label, c, numel (ix_bad), mat2str (bad));
-    catch err
-      errmsg = sprintf ( ...
-        "%s must be less than %f; got %d elements that were not: indexes %s", ...
-        label, c, numel (ix_bad), mat2str (ix_bad));
+      bad_val = x(bad_idx);
+      errmsg = sprintf ("%s must be less than %f; found %d elements that were not: values %s", ...
+                        label, c, numel (bad_idx), mat2str (bad_val));
+    catch
+      errmsg = sprintf ("%s must be less than %f; found %d elements that were not: indexes %s", ...
+                        label, c, numel (bad_idx), mat2str (bad_idx));
     end_try_catch
     error (errmsg);
   endif
+
 endfunction
 
+
 %!test
-%! mustBeLessThan (0, 1)
-%! mustBeLessThan (-Inf, 42)
-%! mustBeLessThan (42, Inf)
-%! mustBeLessThan (1:41, 42)
+%! mustBeLessThan (0, 1);
+%! mustBeLessThan (-Inf, 42);
+%! mustBeLessThan (42, Inf);
+%! mustBeLessThan (1:41, 42);
 
-%!error mustBeLessThan ()
-%!error mustBeLessThan (1, 0)
-%!error mustBeLessThan (1, 1)
-%!error mustBeLessThan (Inf, Inf)
-%!error mustBeLessThan (1:42, 42)
+%!error <Invalid call> mustBeLessThan ()
+%!error <Invalid call> mustBeLessThan (1)
+%!error <Invalid call> mustBeLessThan (1,2,3)
+%!error <must be less than 0> mustBeLessThan (1, 0)
+%!error <must be less than 1> mustBeLessThan (1, 1)
+%!error <must be less than Inf> mustBeLessThan (Inf, Inf)
+%!error <must be less than 42> mustBeLessThan (1:42, 42)
--- a/scripts/miscellaneous/mustBeLessThanOrEqual.m	Fri Sep 11 15:39:17 2020 -0700
+++ b/scripts/miscellaneous/mustBeLessThanOrEqual.m	Fri Sep 11 20:01:56 2020 -0700
@@ -31,41 +31,46 @@
 ## Raise an error if any element of the input @var{x} is not less than
 ## or equal to @var{c}, as determined by @code{@var{x} <= @var{c}}.
 ##
-## @seealso{mustBeLessThan, mustBeGreaterThanOrEqual}
+## @seealso{mustBeLessThan, mustBeGreaterThanOrEqual, le}
 ## @end deftypefn
 
 function mustBeLessThanOrEqual (x, c)
-  tf = x <= c;
-  tf = tf(:);
-  if ! all (tf)
+
+  if (nargin != 2)
+    print_usage ();
+  endif
+
+  tf = (x <= c)(:);
+  if (! all (tf))
     label = inputname (1);
-    if isempty (label)
+    if (isempty (label))
       label = "input";
     endif
-    ix_bad = find (! tf);
+    bad_idx = find (! tf);
     try
-      bad = x(ix_bad);
-      errmsg = sprintf ( ...
-        "%s must be less than or equal to %f; got %d elements that were not: values %s", ...
-        label, c, numel (ix_bad), mat2str (bad));
-    catch err
-      errmsg = sprintf ( ...
-        "%s must be less than or equal to %f; got %d elements that were not: indexes %s", ...
-        label, c, numel (ix_bad), mat2str (ix_bad));
+      bad_val = x(bad_idx);
+      errmsg = sprintf ("%s must be less than or equal to %f; found %d elements that were not: values %s", ...
+                        label, c, numel (bad_idx), mat2str (bad_val));
+    catch
+      errmsg = sprintf ("%s must be less than or equal to %f; found %d elements that were not: indexes %s", ...
+                        label, c, numel (bad_idx), mat2str (bad_idx));
     end_try_catch
     error (errmsg);
   endif
+
 endfunction
 
 
 %!test
-%! mustBeLessThanOrEqual (0, 1)
-%! mustBeLessThanOrEqual (-Inf, 42)
-%! mustBeLessThanOrEqual (42, Inf)
-%! mustBeLessThanOrEqual (1:41, 42)
-%! mustBeLessThanOrEqual (1:42, 42)
-%! mustBeLessThanOrEqual (1, 1)
-%! mustBeLessThanOrEqual (Inf, Inf)
+%! mustBeLessThanOrEqual (0, 1);
+%! mustBeLessThanOrEqual (-Inf, 42);
+%! mustBeLessThanOrEqual (42, Inf);
+%! mustBeLessThanOrEqual (1:41, 42);
+%! mustBeLessThanOrEqual (1:42, 42);
+%! mustBeLessThanOrEqual (1, 1);
+%! mustBeLessThanOrEqual (Inf, Inf);
 
-%!error mustBeLessThanOrEqual ()
-%!error mustBeLessThanOrEqual (1, 0)
+%!error <Invalid call> mustBeLessThanOrEqual ()
+%!error <Invalid call> mustBeLessThanOrEqual (1)
+%!error <Invalid call> mustBeLessThanOrEqual (1,2,3)
+%!error <must be less than or equal to 0> mustBeLessThanOrEqual (1, 0)
--- a/scripts/miscellaneous/mustBeMember.m	Fri Sep 11 15:39:17 2020 -0700
+++ b/scripts/miscellaneous/mustBeMember.m	Fri Sep 11 20:01:56 2020 -0700
@@ -41,28 +41,35 @@
 ## @end deftypefn
 
 function mustBeMember (x, valid)
-  tf = ismember (x, valid);
-  if ! all (tf)
+
+  if (nargin != 2)
+    print_usage ();
+  endif
+
+  tf = ! (ismember (x, valid))(:);
+  if (any (tf))
     label = inputname (1);
-    if isempty (label)
+    if (isempty (label))
       label = "input";
     endif
-    n_bad = numel (find (! tf));
-    # TODO: Fancy inclusion of bad & valid values in the error message.
-    # Probably use mat2str() in a try/catch for that.
-    error ( ...
-      "%s must be one of the specified valid values; got %d elements that weren't", ...
-      label, n_bad);
+    n_bad = numel (find (tf));
+    # FIXME: Fancy inclusion of bad_val & valid values in the error message.
+    #        Probably use mat2str() in a try/catch for that.
+    error ("%s must be one of the specified valid values; found %d elements that were not", ...
+           label, n_bad);
   endif
+
 endfunction
 
+
 %!test
-%! mustBeMember (42, 38:50)
-%! mustBeMember ('foo', {'foo', 'bar', 'baz'})
-%! mustBeMember (38:42, 37:43)
-%! mustBeMember ({'foo','bar'}, {'foo', 'bar', 'baz'})
+%! mustBeMember (42, 38:50);
+%! mustBeMember ("foo", {"foo", "bar", "baz"});
+%! mustBeMember (38:42, 37:43);
+%! mustBeMember ({"foo","bar"}, {"foo", "bar", "baz"});
 
-%!error mustBeMember ()
-%!error mustBeMember (42)
-%!error mustBeMember (42, 1:5)
-%!error mustBeMember ('nope', {'foo', 'bar', 'baz'})
+%!error <Invalid call> mustBeMember ()
+%!error <Invalid call> mustBeMember (1)
+%!error <Invalid call> mustBeMember (1,2,3)
+%!error <found 1 elements> mustBeMember ([1, 42], 1:5)
+%!error <found 1 elements> mustBeMember ("nope", {"foo", "bar", "baz"})
--- a/scripts/miscellaneous/mustBeNegative.m	Fri Sep 11 15:39:17 2020 -0700
+++ b/scripts/miscellaneous/mustBeNegative.m	Fri Sep 11 20:01:56 2020 -0700
@@ -35,33 +35,37 @@
 ## @end deftypefn
 
 function mustBeNegative (x)
-  tf = x < 0;
-  tf = tf(:);
-  if ! all (tf)
+
+  if (nargin != 1)
+    print_usage ();
+  endif
+
+  tf = (x < 0)(:);
+  if (! all (tf))
     label = inputname (1);
-    if isempty (label)
+    if (isempty (label))
       label = "input";
     endif
-    ix_bad = find (! tf);
+    bad_idx = find (! tf);
     try
-      bad = x(ix_bad);
-      errmsg = sprintf ( ...
-        "%s must be negative; got %d elements that were not: values %s", ...
-        label, numel (ix_bad), mat2str (bad));
-    catch err
-      errmsg = sprintf ( ...
-        "%s must be negative; got %d elements that were not: indexes %s", ...
-        label, numel (ix_bad), mat2str (ix_bad));
+      bad_val = x(bad_idx);
+      errmsg = sprintf ("%s must be negative; found %d elements that were not: values %s", ...
+                        label, numel (bad_idx), mat2str (bad_val));
+    catch
+      errmsg = sprintf ("%s must be negative; found %d elements that were not: indexes %s", ...
+                        label, numel (bad_idx), mat2str (bad_idx));
     end_try_catch
     error (errmsg);
   endif
+
 endfunction
 
+
 %!test
-%! mustBeNegative (-42)
-%! mustBeNegative ([])
-%! mustBeNegative (-10:-2)
+%! mustBeNegative ([]);
+%! mustBeNegative (-42);
+%! mustBeNegative (-10:-2);
 
-%!error mustBeNegative ()
-%!error mustBeNegative (42)
-%!error mustBeNegative (-5:5)
+%!error <Invalid call> mustBeNegative ()
+%!error <found 1 elements> mustBeNegative ([-1, 42])
+%!error <found 6 elements> mustBeNegative (-5:5)
--- a/scripts/miscellaneous/mustBeNonNan.m	Fri Sep 11 15:39:17 2020 -0700
+++ b/scripts/miscellaneous/mustBeNonNan.m	Fri Sep 11 20:01:56 2020 -0700
@@ -35,28 +35,33 @@
 ## @end deftypefn
 
 function mustBeNonNan (x)
-  tf = ! isnan (x);
-  tf = tf(:);
-  if ! all (tf)
+
+  if (nargin != 1)
+    print_usage ();
+  endif
+
+  tf = isnan (x(:));
+  if (any (tf))
     label = inputname (1);
-    if isempty (label)
+    if (isempty (label))
       label = "input";
     endif
-    ix_bad = find (! tf);
-    errmsg = sprintf ( ...
-      "%s must be non-NaN; got %d elements that were not: indexes %s", ...
-      label, numel (ix_bad), mat2str (ix_bad));
+    bad_idx = find (tf);
+    errmsg = sprintf ("%s must be non-NaN; found %d elements that were not: indexes %s", ...
+                      label, numel (bad_idx), mat2str (bad_idx));
     error (errmsg);
   endif
+
 endfunction
 
+
 %!test
-%! mustBeNonNan (42)
-%! mustBeNonNan ('foo')
-%! mustBeNonNan (1:10)
-%! mustBeNonNan (Inf)
-%! mustBeNonNan (-Inf)
+%! mustBeNonNan (42);
+%! mustBeNonNan ("foo");
+%! mustBeNonNan (1:10);
+%! mustBeNonNan (Inf);
+%! mustBeNonNan (-Inf);
 
-%!error mustBeNonNan ()
-%!error mustBeNonNan (NaN)
-%!error mustBeNonNan ([1 2 3 NaN])
+%!error <Invalid call> mustBeNonNan ()
+%!error <must be non-NaN> mustBeNonNan (NaN)
+%!error <input must be non-NaN> mustBeNonNan ([1 2 3 NaN])
--- a/scripts/miscellaneous/mustBeNonempty.m	Fri Sep 11 15:39:17 2020 -0700
+++ b/scripts/miscellaneous/mustBeNonempty.m	Fri Sep 11 20:01:56 2020 -0700
@@ -35,22 +35,29 @@
 ## @end deftypefn
 
 function mustBeNonempty (x)
-  if isempty (x)
+
+  if (nargin != 1)
+    print_usage ();
+  endif
+
+  if (isempty (x))
     label = inputname (1);
-    if isempty (label)
+    if (isempty (label))
       label = "input";
     endif
-    error ("%s must be nonempty; got an empty", label);
+    error ("%s must not be empty", label);
   endif
+
 endfunction
 
+
 %!test
-%! mustBeNonempty (42)
-%! mustBeNonempty ('Hello')
-%! mustBeNonempty (Inf)
-%! mustBeNonempty (NaN)
+%! mustBeNonempty (42);
+%! mustBeNonempty ("Hello");
+%! mustBeNonempty (Inf);
+%! mustBeNonempty (NaN);
 
-%!error mustBeNonempty ()
-%!error mustBeNonempty ([])
-%!error mustBeNonempty ('')
-%!error mustBeNonempty (reshape([], [0 3 3 3]))
+%!error <Invalid call> mustBeNonempty ()
+%!error <input must not be empty> mustBeNonempty ([])
+%!error <input must not be empty> mustBeNonempty ('')
+%!error <input must not be empty> mustBeNonempty (reshape ([], [0 3 3 3]))
--- a/scripts/miscellaneous/mustBeNonnegative.m	Fri Sep 11 15:39:17 2020 -0700
+++ b/scripts/miscellaneous/mustBeNonnegative.m	Fri Sep 11 20:01:56 2020 -0700
@@ -35,38 +35,42 @@
 ## @end deftypefn
 
 function mustBeNonnegative (x)
-  tf = x >= 0;
-  tf = tf(:);
-  if ! all (tf)
+
+  if (nargin != 1)
+    print_usage ();
+  endif
+
+  tf = (x(:) >= 0);
+  if (! all (tf))
     label = inputname (1);
-    if isempty (label)
+    if (isempty (label))
       label = "input";
     endif
-    ix_bad = find (! tf);
+    bad_idx = find (! tf);
     try
-      bad = x(ix_bad);
-      errmsg = sprintf ( ...
-        "%s must be non-negative; got %d elements that were not: values %s", ...
-        label, numel (ix_bad), mat2str (bad));
-    catch err
-      errmsg = sprintf ( ...
-        "%s must be non-negative; got %d elements that were not: indexes %s", ...
-        label, numel (ix_bad), mat2str (ix_bad));
+      bad_val = x(bad_idx);
+      errmsg = sprintf ("%s must be non-negative; found %d elements that were not: values %s", ...
+                        label, numel (bad_idx), mat2str (bad_val));
+    catch
+      errmsg = sprintf ("%s must be non-negative; found %d elements that were not: indexes %s", ...
+                        label, numel (bad_idx), mat2str (bad_idx));
     end_try_catch
     error (errmsg);
   endif
+
 endfunction
 
+
 %!test
-%! mustBeNonnegative (0)
-%! mustBeNonnegative (1)
-%! mustBeNonnegative (123.456)
-%! mustBeNonnegative (Inf)
-%! mustBeNonnegative (0:10)
-%! mustBeNonnegative (eps)
+%! mustBeNonnegative (0);
+%! mustBeNonnegative (1);
+%! mustBeNonnegative (123.456);
+%! mustBeNonnegative (Inf);
+%! mustBeNonnegative (0:10);
+%! mustBeNonnegative (eps);
 
-%!error mustBeNonnegative ()
-%!error mustBeNonnegative (-1)
-%!error mustBeNonnegative ([0 1 2 3 -4])
-%!error mustBeNonnegative (-Inf)
-%!error mustBeNonnegative (NaN)
+%!error <Invalid call> mustBeNonnegative ()
+%!error <input must be non-negative> mustBeNonnegative (-1)
+%!error <found 1 elements> mustBeNonnegative ([0 1 2 3 -4])
+%!error <input must be non-negative> mustBeNonnegative (-Inf)
+%!error <must be non-negative> mustBeNonnegative (NaN)
--- a/scripts/miscellaneous/mustBeNonpositive.m	Fri Sep 11 15:39:17 2020 -0700
+++ b/scripts/miscellaneous/mustBeNonpositive.m	Fri Sep 11 20:01:56 2020 -0700
@@ -35,35 +35,39 @@
 ## @end deftypefn
 
 function mustBeNonpositive (x)
-  tf = x <= 0;
-  tf = tf(:);
-  if ! all (tf)
+
+  if (nargin != 1)
+    print_usage ();
+  endif
+
+  tf = (x(:) <= 0);
+  if (! all (tf))
     label = inputname (1);
-    if isempty (label)
+    if (isempty (label))
       label = "input";
     endif
-    ix_bad = find (! tf);
+    bad_idx = find (! tf);
     try
-      bad = x(ix_bad);
-      errmsg = sprintf ( ...
-        "%s must be non-positive; got %d elements that were not: values %s", ...
-        label, numel (ix_bad), mat2str (bad));
-    catch err
-      errmsg = sprintf ( ...
-        "%s must be non-positive; got %d elements that were not: indexes %s", ...
-        label, numel (ix_bad), mat2str (ix_bad));
+      bad_val = x(bad_idx);
+      errmsg = sprintf ("%s must be non-positive; found %d elements that were not: values %s", ...
+                        label, numel (bad_idx), mat2str (bad_val));
+    catch
+      errmsg = sprintf ("%s must be non-positive; found %d elements that were not: indexes %s", ...
+                        label, numel (bad_idx), mat2str (bad_idx));
     end_try_catch
     error (errmsg);
   endif
+
 endfunction
 
+
 %!test
-%! mustBeNonpositive (0)
-%! mustBeNonpositive (-1)
-%! mustBeNonpositive (-5:-1)
-%! mustBeNonpositive (-Inf)
+%! mustBeNonpositive (0);
+%! mustBeNonpositive (-1);
+%! mustBeNonpositive (-5:-1);
+%! mustBeNonpositive (-Inf);
 
-%!error mustBeNonpositive ()
-%!error mustBeNonpositive (NaN)
-%!error mustBeNonpositive (1)
-%!error mustBeNonpositive (-10:1)
+%!error <Invalid call> mustBeNonpositive ()
+%!error <must be non-positive> mustBeNonpositive (1)
+%!error <found 2 elements> mustBeNonpositive (-10:2)
+%!error <must be non-positive> mustBeNonpositive (NaN)
--- a/scripts/miscellaneous/mustBeNonsparse.m	Fri Sep 11 15:39:17 2020 -0700
+++ b/scripts/miscellaneous/mustBeNonsparse.m	Fri Sep 11 20:01:56 2020 -0700
@@ -35,20 +35,27 @@
 ## @end deftypefn
 
 function mustBeNonsparse (x)
-  if issparse (x)
+
+  if (nargin != 1)
+    print_usage ();
+  endif
+
+  if (issparse (x))
     label = inputname (1);
-    if isempty (label)
+    if (isempty (label))
       label = "input";
     endif
-    error ("%s must be nonsparse; got a sparse array", label);
+    error ("%s must be nonsparse", label);
   endif
+
 endfunction
 
+
 %!test
-%! mustBeNonsparse ([])
-%! mustBeNonsparse (42)
-%! mustBeNonsparse (1:100)
-%! mustBeNonsparse (Inf)
+%! mustBeNonsparse ([]);
+%! mustBeNonsparse (42);
+%! mustBeNonsparse (1:100);
+%! mustBeNonsparse ("Hello World");
 
-%!error mustBeNonsparse (sparse(42))
-%!error mustBeNonsparse ()
+%!error <Invalid call> mustBeNonsparse ()
+%!error <input must be nonsparse> mustBeNonsparse (sparse (42))
--- a/scripts/miscellaneous/mustBeNonzero.m	Fri Sep 11 15:39:17 2020 -0700
+++ b/scripts/miscellaneous/mustBeNonzero.m	Fri Sep 11 20:01:56 2020 -0700
@@ -29,40 +29,41 @@
 ## Require that input @var{x} is not zero.
 ##
 ## Raise an error if any element of the input @var{x} is zero, as determined
-## by @code{@var{x} != 0}.
+## by @code{@var{x} == 0}.
 ##
 ## @seealso{mustBeNonnegative, mustBePositive}
 ## @end deftypefn
 
-# TODO: Should NaN be considered nonzero? It fits the formal definition above,
-# but that may not be the spirit of the test. And it's not equal to any non-zero
-# value.
+function mustBeNonzero (x)
 
-function mustBeNonzero (x)
-  tf = x != 0;
-  tf = tf(:);
-  if ! all (tf)
+  if (nargin != 1)
+    print_usage ();
+  endif
+
+  tf = (x(:) == 0);
+  if (any (tf))
     label = inputname (1);
-    if isempty (label)
+    if (isempty (label))
       label = "input";
     endif
-    ix_bad = find (! tf);
-    errmsg = sprintf ( ...
-      "%s must be non-zero; got %d elements that were zero: indexes %s", ...
-      label, numel (ix_bad), mat2str (ix_bad));
+    bad_idx = find (tf);
+    errmsg = sprintf ("%s must be non-zero; found %d elements that were zero: indexes %s", ...
+                      label, numel (bad_idx), mat2str (bad_idx));
     error (errmsg);
   endif
+
 endfunction
 
+
 %!test
-%! mustBeNonzero (1)
-%! mustBeNonzero (-1)
-%! mustBeNonzero ([-5:-1 1:5])
-%! mustBeNonzero (Inf)
-%! mustBeNonzero (-Inf)
-%! mustBeNonzero (NaN)
-%! mustBeNonzero (eps)
+%! mustBeNonzero (1);
+%! mustBeNonzero (-1);
+%! mustBeNonzero ([-5:-1 1:5]);
+%! mustBeNonzero (Inf);
+%! mustBeNonzero (-Inf);
+%! mustBeNonzero (NaN);
+%! mustBeNonzero (eps);
 
-%!error mustBeNonzero ()
-%!error mustBeNonzero (0)
-%!error mustBeNonzero (-10:10)
+%!error <Invalid call> mustBeNonzero ()
+%!error <found 1 elements> mustBeNonzero (-10:10)
+%!error <found 2 elements> mustBeNonzero ([-1, 0, 0, 1])
--- a/scripts/miscellaneous/mustBeNumeric.m	Fri Sep 11 15:39:17 2020 -0700
+++ b/scripts/miscellaneous/mustBeNumeric.m	Fri Sep 11 20:01:56 2020 -0700
@@ -35,23 +35,30 @@
 ## @end deftypefn
 
 function mustBeNumeric (x)
-  if ! isnumeric (x)
+
+  if (nargin != 1)
+    print_usage ();
+  endif
+
+  if (! isnumeric (x))
     label = inputname (1);
-    if isempty (label)
+    if (isempty (label))
       label = "input";
     endif
-    error ("%s must be numeric; got a %s", label, class (x));
+    error ("%s must be numeric; found a %s", label, class (x));
   endif
+
 endfunction
 
+
 %!test
-%! mustBeNumeric ([])
-%! mustBeNumeric (42)
-%! mustBeNumeric (int32(42))
-%! mustBeNumeric (NaN)
+%! mustBeNumeric ([]);
+%! mustBeNumeric (42);
+%! mustBeNumeric (int32 (42));
+%! mustBeNumeric (NaN);
 
-%!error mustBeNumeric ()
-%!error mustBeNumeric ('foo')
-%!error mustBeNumeric (struct)
-%!error mustBeNumeric ({})
-%!error mustBeNumeric (true)
+%!error <Invalid call> mustBeNumeric ()
+%!error <found a char> mustBeNumeric ("foo")
+%!error <found a logical> mustBeNumeric (true)
+%!error <found a struct> mustBeNumeric (struct ())
+%!error <found a cell> mustBeNumeric (cell ())
--- a/scripts/miscellaneous/mustBeNumericOrLogical.m	Fri Sep 11 15:39:17 2020 -0700
+++ b/scripts/miscellaneous/mustBeNumericOrLogical.m	Fri Sep 11 20:01:56 2020 -0700
@@ -35,23 +35,30 @@
 ## @end deftypefn
 
 function mustBeNumericOrLogical (x)
-  if ! (isnumeric (x) || islogical (x))
+
+  if (nargin != 1)
+    print_usage ();
+  endif
+
+  if (! (isnumeric (x) || islogical (x)))
     label = inputname (1);
-    if isempty (label)
+    if (isempty (label))
       label = "input";
     endif
-    error ("%s must be numeric or logical; got a %s", label, class (x));
+    error ("%s must be numeric or logical; found a %s", label, class (x));
   endif
+
 endfunction
 
+
 %!test
-%! mustBeNumericOrLogical ([])
-%! mustBeNumericOrLogical (true)
-%! mustBeNumericOrLogical (false)
-%! mustBeNumericOrLogical (42)
-%! mustBeNumericOrLogical (int32(42))
+%! mustBeNumericOrLogical ([]);
+%! mustBeNumericOrLogical (true);
+%! mustBeNumericOrLogical (false);
+%! mustBeNumericOrLogical (42);
+%! mustBeNumericOrLogical (int32 (42));
 
-%!error mustBeNumericOrLogical ()
-%!error mustBeNumericOrLogical ('foo')
-%!error mustBeNumericOrLogical ({})
-%!error mustBeNumericOrLogical (struct)
+%!error <Invalid call> mustBeNumericOrLogical ()
+%!error <found a char> mustBeNumericOrLogical ("foo")
+%!error <found a struct> mustBeNumericOrLogical (struct ())
+%!error <found a cell> mustBeNumericOrLogical (cell ())
--- a/scripts/miscellaneous/mustBePositive.m	Fri Sep 11 15:39:17 2020 -0700
+++ b/scripts/miscellaneous/mustBePositive.m	Fri Sep 11 20:01:56 2020 -0700
@@ -35,38 +35,42 @@
 ## @end deftypefn
 
 function mustBePositive (x)
-  tf = x > 0;
-  tf = tf(:);
-  if ! all (tf)
+
+  if (nargin != 1)
+    print_usage ();
+  endif
+
+  tf = (x(:) > 0);
+  if (! all (tf))
     label = inputname (1);
-    if isempty (label)
+    if (isempty (label))
       label = "input";
     endif
-    ix_bad = find (! tf);
+    bad_idx = find (! tf);
     try
-      bad = x(ix_bad);
-      errmsg = sprintf ( ...
-        "%s must be positive; got %d elements that were not: values %s", ...
-        label, numel (ix_bad), mat2str (bad));
-    catch err
-      errmsg = sprintf ( ...
-        "%s must be positive; got %d elements that were not: indexes %s", ...
-        label, numel (ix_bad), mat2str (ix_bad));
+      bad_val = x(bad_idx);
+      errmsg = sprintf ("%s must be positive; found %d elements that were not: values %s", ...
+                        label, numel (bad_idx), mat2str (bad_val));
+    catch
+      errmsg = sprintf ("%s must be positive; found %d elements that were not: indexes %s", ...
+                        label, numel (bad_idx), mat2str (bad_idx));
     end_try_catch
     error (errmsg);
   endif
+
 endfunction
 
+
 %!test
-%! mustBePositive (1)
-%! mustBePositive (123.456)
-%! mustBePositive (Inf)
-%! mustBePositive (eps)
+%! mustBePositive (1);
+%! mustBePositive (123.456);
+%! mustBePositive (Inf);
+%! mustBePositive (eps);
 
-%!error mustBePositive ()
-%!error mustBePositive (0)
-%!error mustBePositive (0:10)
-%!error mustBePositive (-1)
-%!error mustBePositive ([0 1 2 3 -4])
-%!error mustBePositive (-Inf)
-%!error mustBePositive (NaN)
+%!error <Invalid call> mustBePositive ()
+%!error <found 1 elements> mustBePositive (0)
+%!error <found 1 elements> mustBePositive (0:10)
+%!error <found 2 elements> mustBePositive ([-1 -2])
+%!error <found 2 elements> mustBePositive ([0 1 2 3 -4])
+%!error <found 1 elements> mustBePositive (-Inf)
+%!error <found 1 elements> mustBePositive (NaN)
--- a/scripts/miscellaneous/mustBeReal.m	Fri Sep 11 15:39:17 2020 -0700
+++ b/scripts/miscellaneous/mustBeReal.m	Fri Sep 11 20:01:56 2020 -0700
@@ -35,23 +35,30 @@
 ## @end deftypefn
 
 function mustBeReal (x)
-  if ! isreal (x)
+
+  if (nargin != 1)
+    print_usage ();
+  endif
+
+  if (! isreal (x))
     label = inputname (1);
-    if isempty (label)
+    if (isempty (label))
       label = "input";
     endif
-    error ("%s must be real; got a complex value", label);
+    error ("%s must be real", label);
   endif
+
 endfunction
 
+
 %!test
-%! mustBeReal ([])
-%! mustBeReal (42)
-%! mustBeReal (Inf)
-%! mustBeReal (NaN)
-%! mustBeReal (1:100)
-%! mustBeReal (int32(42))
+%! mustBeReal ([]);
+%! mustBeReal (42);
+%! mustBeReal (Inf);
+%! mustBeReal (NaN);
+%! mustBeReal (1:100);
+%! mustBeReal (int32 (42));
 
-%!error mustBeReal ()
-%!error mustBeReal (i)
-%!error mustBeReal (2 + i)
+%!error <Invalid call> mustBeReal ()
+%!error <must be real> mustBeReal (i)
+%!error <input must be real> mustBeReal (2 + i)