changeset 27968:c9dd91b438fd

BISTs for new validator functions (Bug #57627).
author Andrew Janke <andrew@apjanke.net>
date Mon, 20 Jan 2020 00:08:43 -0500
parents 2175e712c708
children a9a8699a3749
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, 209 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/miscellaneous/mustBeFinite.m	Mon Jan 20 21:38:29 2020 +0100
+++ b/scripts/miscellaneous/mustBeFinite.m	Mon Jan 20 00:08:43 2020 -0500
@@ -45,3 +45,14 @@
       label, numel (ix_bad), mat2str (ix_bad));
   endif
 endfunction
+
+%!test
+%! mustBeFinite ([]);
+%! mustBeFinite (42);
+%! mustBeFinite (-100:.1:100);
+%! mustBeFinite (int32(42))
+
+%!error mustBeFinite ();
+%!error mustBeFinite (Inf);
+%!error mustBeFinite ([1 2 3 Inf]);
+%!error mustBeFinite ([-Inf -1 0 1]);
--- a/scripts/miscellaneous/mustBeGreaterThan.m	Mon Jan 20 21:38:29 2020 +0100
+++ b/scripts/miscellaneous/mustBeGreaterThan.m	Mon Jan 20 00:08:43 2020 -0500
@@ -53,3 +53,11 @@
     error (errmsg);
   endif
 endfunction
+
+%!test
+%! mustBeGreaterThan (42, 0)
+%! mustBeGreaterThan (Inf, 9999)
+
+%!error mustBeGreaterThan (42, 42)
+%!error mustBeGreaterThan (Inf, Inf)
+%!error mustBeGreaterThan (NaN, 0)
--- a/scripts/miscellaneous/mustBeGreaterThanOrEqual.m	Mon Jan 20 21:38:29 2020 +0100
+++ b/scripts/miscellaneous/mustBeGreaterThanOrEqual.m	Mon Jan 20 00:08:43 2020 -0500
@@ -55,3 +55,13 @@
     error (errmsg);
   endif
 endfunction
+
+%!test
+%! mustBeGreaterThanOrEqual (42, 0)
+%! mustBeGreaterThanOrEqual (Inf, 9999)
+%! mustBeGreaterThanOrEqual (42, 42)
+%! mustBeGreaterThanOrEqual (Inf, Inf)
+
+%!error mustBeGreaterThanOrEqual ()
+%!error mustBeGreaterThanOrEqual (42)
+%!error mustBeGreaterThanOrEqual (NaN, 0)
--- a/scripts/miscellaneous/mustBeInteger.m	Mon Jan 20 21:38:29 2020 +0100
+++ b/scripts/miscellaneous/mustBeInteger.m	Mon Jan 20 00:08:43 2020 -0500
@@ -56,3 +56,15 @@
     error ("%s must be integer-valued; but %s", label, but);
   endif
 endfunction
+
+%!test
+%! mustBeInteger ([])
+%! mustBeInteger (42)
+%! mustBeInteger (1:1000)
+%! mustBeInteger (int32(42))
+
+%!error mustBeInteger ()
+%!error mustBeInteger (1.23)
+%!error mustBeInteger ([1 2 3 4.4])
+%!error mustBeInteger (Inf)
+%!error mustBeInteger (NaN)
--- a/scripts/miscellaneous/mustBeLessThan.m	Mon Jan 20 21:38:29 2020 +0100
+++ b/scripts/miscellaneous/mustBeLessThan.m	Mon Jan 20 00:08:43 2020 -0500
@@ -55,3 +55,15 @@
     error (errmsg);
   endif
 endfunction
+
+%!test
+%! 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)
--- a/scripts/miscellaneous/mustBeLessThanOrEqual.m	Mon Jan 20 21:38:29 2020 +0100
+++ b/scripts/miscellaneous/mustBeLessThanOrEqual.m	Mon Jan 20 00:08:43 2020 -0500
@@ -55,3 +55,16 @@
     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)
+
+%!error mustBeLessThanOrEqual ()
+%!error mustBeLessThanOrEqual (1, 0)
--- a/scripts/miscellaneous/mustBeMember.m	Mon Jan 20 21:38:29 2020 +0100
+++ b/scripts/miscellaneous/mustBeMember.m	Mon Jan 20 00:08:43 2020 -0500
@@ -52,3 +52,14 @@
       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'})
+
+%!error mustBeMember ()
+%!error mustBeMember (42)
+%!error mustBeMember (42, 1:5)
+%!error mustBeMember ('nope', {'foo', 'bar', 'baz'})
--- a/scripts/miscellaneous/mustBeNegative.m	Mon Jan 20 21:38:29 2020 +0100
+++ b/scripts/miscellaneous/mustBeNegative.m	Mon Jan 20 00:08:43 2020 -0500
@@ -55,3 +55,12 @@
     error (errmsg);
   endif
 endfunction
+
+%!test
+%! mustBeNegative (-42)
+%! mustBeNegative ([])
+%! mustBeNegative (-10:-2)
+
+%!error mustBeNegative ()
+%!error mustBeNegative (42)
+%!error mustBeNegative (-5:5)
--- a/scripts/miscellaneous/mustBeNonNan.m	Mon Jan 20 21:38:29 2020 +0100
+++ b/scripts/miscellaneous/mustBeNonNan.m	Mon Jan 20 00:08:43 2020 -0500
@@ -48,3 +48,14 @@
     error (errmsg);
   endif
 endfunction
+
+%!test
+%! mustBeNonNan (42)
+%! mustBeNonNan ('foo')
+%! mustBeNonNan (1:10)
+%! mustBeNonNan (Inf)
+%! mustBeNonNan (-Inf)
+
+%!error mustBeNonNan ()
+%!error mustBeNonNan (NaN)
+%!error mustBeNonNan ([1 2 3 NaN])
--- a/scripts/miscellaneous/mustBeNonempty.m	Mon Jan 20 21:38:29 2020 +0100
+++ b/scripts/miscellaneous/mustBeNonempty.m	Mon Jan 20 00:08:43 2020 -0500
@@ -42,3 +42,14 @@
     error ("%s must be nonempty; got an empty", label);
   endif
 endfunction
+
+%!test
+%! mustBeNonempty (42)
+%! mustBeNonempty ('Hello')
+%! mustBeNonempty (Inf)
+%! mustBeNonempty (NaN)
+
+%!error mustBeNonempty ()
+%!error mustBeNonempty ([])
+%!error mustBeNonempty ('')
+%!error mustBeNonempty (reshape([], [0 3 3 3]))
--- a/scripts/miscellaneous/mustBeNonnegative.m	Mon Jan 20 21:38:29 2020 +0100
+++ b/scripts/miscellaneous/mustBeNonnegative.m	Mon Jan 20 00:08:43 2020 -0500
@@ -55,3 +55,17 @@
     error (errmsg);
   endif
 endfunction
+
+%!test
+%! 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)
--- a/scripts/miscellaneous/mustBeNonpositive.m	Mon Jan 20 21:38:29 2020 +0100
+++ b/scripts/miscellaneous/mustBeNonpositive.m	Mon Jan 20 00:08:43 2020 -0500
@@ -55,3 +55,14 @@
     error (errmsg);
   endif
 endfunction
+
+%!test
+%! mustBeNonpositive (0)
+%! mustBeNonpositive (-1)
+%! mustBeNonpositive (-5:-1)
+%! mustBeNonpositive (-Inf)
+
+%!error mustBeNonpositive ()
+%!error mustBeNonpositive (NaN)
+%!error mustBeNonpositive (1)
+%!error mustBeNonpositive (-10:1)
--- a/scripts/miscellaneous/mustBeNonsparse.m	Mon Jan 20 21:38:29 2020 +0100
+++ b/scripts/miscellaneous/mustBeNonsparse.m	Mon Jan 20 00:08:43 2020 -0500
@@ -42,3 +42,12 @@
     error ("%s must be nonsparse; got a sparse array", label);
   endif
 endfunction
+
+%!test
+%! mustBeNonsparse ([])
+%! mustBeNonsparse (42)
+%! mustBeNonsparse (1:100)
+%! mustBeNonsparse (Inf)
+
+%!error mustBeNonsparse (sparse(42))
+%!error mustBeNonsparse ()
--- a/scripts/miscellaneous/mustBeNonzero.m	Mon Jan 20 21:38:29 2020 +0100
+++ b/scripts/miscellaneous/mustBeNonzero.m	Mon Jan 20 00:08:43 2020 -0500
@@ -33,6 +33,10 @@
 ##
 ## @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 x = mustBeNonzero (x)
   tf = x != 0;
   tf = tf(:);
@@ -48,3 +52,16 @@
     error (errmsg);
   endif
 endfunction
+
+%!test
+%! 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)
--- a/scripts/miscellaneous/mustBeNumeric.m	Mon Jan 20 21:38:29 2020 +0100
+++ b/scripts/miscellaneous/mustBeNumeric.m	Mon Jan 20 00:08:43 2020 -0500
@@ -42,3 +42,15 @@
     error ("%s must be numeric; got a %s", label, class (x));
   endif
 endfunction
+
+%!test
+%! mustBeNumeric ([])
+%! mustBeNumeric (42)
+%! mustBeNumeric (int32(42))
+%! mustBeNumeric (NaN)
+
+%!error mustBeNumeric ()
+%!error mustBeNumeric ('foo')
+%!error mustBeNumeric (struct)
+%!error mustBeNumeric ({})
+%!error mustBeNumeric (true)
--- a/scripts/miscellaneous/mustBeNumericOrLogical.m	Mon Jan 20 21:38:29 2020 +0100
+++ b/scripts/miscellaneous/mustBeNumericOrLogical.m	Mon Jan 20 00:08:43 2020 -0500
@@ -42,3 +42,15 @@
     error ("%s must be numeric or logical; got a %s", label, class (x));
   endif
 endfunction
+
+%!test
+%! mustBeNumericOrLogical ([])
+%! mustBeNumericOrLogical (true)
+%! mustBeNumericOrLogical (false)
+%! mustBeNumericOrLogical (42)
+%! mustBeNumericOrLogical (int32(42))
+
+%!error mustBeNumericOrLogical ()
+%!error mustBeNumericOrLogical ('foo')
+%!error mustBeNumericOrLogical ({})
+%!error mustBeNumericOrLogical (struct)
--- a/scripts/miscellaneous/mustBePositive.m	Mon Jan 20 21:38:29 2020 +0100
+++ b/scripts/miscellaneous/mustBePositive.m	Mon Jan 20 00:08:43 2020 -0500
@@ -55,3 +55,17 @@
     error (errmsg);
   endif
 endfunction
+
+%!test
+%! 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)
--- a/scripts/miscellaneous/mustBeReal.m	Mon Jan 20 21:38:29 2020 +0100
+++ b/scripts/miscellaneous/mustBeReal.m	Mon Jan 20 00:08:43 2020 -0500
@@ -42,3 +42,15 @@
     error ("%s must be real; got a complex value", label);
   endif
 endfunction
+
+%!test
+%! mustBeReal ([])
+%! mustBeReal (42)
+%! mustBeReal (Inf)
+%! mustBeReal (NaN)
+%! mustBeReal (1:100)
+%! mustBeReal (int32(42))
+
+%!error mustBeReal ()
+%!error mustBeReal (i)
+%!error mustBeReal (2 + i)