Mercurial > octave-nkf
changeset 20473:e59a44fa74ff
union.m: Matlab compatible output when mixed input and one is empty (bug #45685).
* union.m: add BIST tests for mixed cell/matrix inputs.
* validasetargs.m: Check for cases of cellstr and empty array and coerce empty
array into cellstr.
author | Juan Pablo Carbajal <ajuanpi+dev@gmail.com> |
---|---|
date | Mon, 03 Aug 2015 23:22:14 +0200 |
parents | c3b2ec6a1586 |
children | 3fc21d7ac11c |
files | scripts/set/private/validsetargs.m scripts/set/union.m |
diffstat | 2 files changed, 12 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/set/private/validsetargs.m Mon Aug 10 13:12:22 2015 -0700 +++ b/scripts/set/private/validsetargs.m Mon Aug 03 23:22:14 2015 +0200 @@ -31,6 +31,10 @@ y = cellstr (y); elseif (icy && ischar (x)) x = cellstr (x); + elseif (icy && isempty (x)) + x = {}; + elseif (icx && isempty (y)) + y = {}; elseif (! (icx && icy)) error ("%s: cell array of strings cannot be combined with a nonstring value", caller); endif
--- a/scripts/set/union.m Mon Aug 10 13:12:22 2015 -0700 +++ b/scripts/set/union.m Mon Aug 03 23:22:14 2015 +0200 @@ -94,6 +94,14 @@ %! assert (y, [1; 2; 3; 4; 5]); %! assert (y, sort ([a(ia)'; b(ib)'])); +## Test empty cell string array unions +%!assert (union ({}, []), cell (0,1)) +%!assert (union ([], {}), cell (0,1)) +%!assert (union ([], {'a', 'b'}), {'a';'b'}) +%!assert (union ({'a', 'b'}, []), {'a';'b'}) +%!assert (union (['a', 'b'], {}), {'ab'}) +%!assert (union ({}, ['a', 'b']), {'ab'}) + ## Test common input validation for set routines contained in validsetargs %!error <cell array of strings cannot be combined> union ({"a"}, 1) %!error <A and B must be arrays or cell arrays> union (@sin, 1)