changeset 27245:9ded07d2c44f

validsetargs.m: Validate "rows" flag when "legacy" flag also present. * validsetargs.m: Change "elseif (nargin == 4)" to "else" so that tests on varargin are run regardless of the size of varargin. Update error messages to use '"rows" flag' for clarity. * union.m: Add BIST tests for "rows" flag with "legacy" flag present.
author Rik <rik@octave.org>
date Fri, 12 Jul 2019 15:26:36 -0700
parents 3f354ef16400
children 7c778a102de8
files scripts/set/private/validsetargs.m scripts/set/union.m
diffstat 2 files changed, 13 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/set/private/validsetargs.m	Fri Jul 12 12:36:50 2019 -0700
+++ b/scripts/set/private/validsetargs.m	Fri Jul 12 15:26:36 2019 -0700
@@ -41,7 +41,7 @@
     elseif (! (isallowedarraytype (x) && isallowedarraytype (y)))
       error ("%s: A and B must be arrays or cell arrays of strings", caller);
     endif
-  elseif (nargin == 4)
+  else
     for arg = varargin
       switch (arg{1})
         case "legacy"
@@ -49,12 +49,12 @@
 
         case "rows"
           if (iscell (x) || iscell (y))
-            error ('%s: cells not supported with "rows"', caller);
+            error ('%s: cells not supported with "rows" flag', caller);
           elseif (! (isallowedarraytype (x) && isallowedarraytype (y)))
             error ("%s: A and B must be arrays or cell arrays of strings", caller);
           else
             if (ndims (x) > 2 || ndims (y) > 2)
-              error ('%s: A and B must be 2-dimensional matrices for "rows"', caller);
+              error ('%s: A and B must be 2-dimensional matrices with "rows" flag', caller);
             elseif (columns (x) != columns (y) && ! (isempty (x) || isempty (y)))
               error ("%s: number of columns in A and B must match", caller);
             endif
@@ -70,4 +70,4 @@
 endfunction
 
 
-## %!tests for function are in union.m
+## BIST tests for function are in union.m
--- a/scripts/set/union.m	Fri Jul 12 12:36:50 2019 -0700
+++ b/scripts/set/union.m	Fri Jul 12 15:26:36 2019 -0700
@@ -142,4 +142,13 @@
 %!error <cells not supported with "rows"> union ({"a"}, {"b"}, "rows")
 %!error <A and B must be arrays or cell arrays> union (@sin, 1, "rows")
 %!error <A and B must be 2-dimensional matrices> union (rand(2,2,2), 1, "rows")
+%!error <A and B must be 2-dimensional matrices> union (1, rand(2,2,2), "rows")
 %!error <number of columns in A and B must match> union ([1 2], 1, "rows")
+%!error <number of columns in A and B must match> union (1, [1 2], "rows")
+%!error <invalid option: columns> union (1, 2, "legacy", "columns")
+%!error <cells not supported with "rows"> union ({"a"}, {"b"}, "rows", "legacy")
+%!error <A and B must be arrays or cell arrays> union (@sin, 1, "rows", "legacy")
+%!error <A and B must be 2-dimensional matrices> union (rand(2,2,2), 1, "rows", "legacy")
+%!error <A and B must be 2-dimensional matrices> union (1, rand(2,2,2), "rows", "legacy")
+%!error <number of columns in A and B must match> union ([1 2], 1, "rows", "legacy")
+%!error <number of columns in A and B must match> union (1, [1 2], "rows", "legacy")