diff scripts/set/union.m @ 20648: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
line wrap: on
line diff
--- a/scripts/set/union.m
+++ b/scripts/set/union.m
@@ -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)