Mercurial > octave-nkf
comparison scripts/set/union.m @ 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 |
comparison
equal
deleted
inserted
replaced
20472:c3b2ec6a1586 | 20473:e59a44fa74ff |
---|---|
92 %! b = [1, 2, 3, 4]; | 92 %! b = [1, 2, 3, 4]; |
93 %! [y, ia, ib] = union (a, b.'); | 93 %! [y, ia, ib] = union (a, b.'); |
94 %! assert (y, [1; 2; 3; 4; 5]); | 94 %! assert (y, [1; 2; 3; 4; 5]); |
95 %! assert (y, sort ([a(ia)'; b(ib)'])); | 95 %! assert (y, sort ([a(ia)'; b(ib)'])); |
96 | 96 |
97 ## Test empty cell string array unions | |
98 %!assert (union ({}, []), cell (0,1)) | |
99 %!assert (union ([], {}), cell (0,1)) | |
100 %!assert (union ([], {'a', 'b'}), {'a';'b'}) | |
101 %!assert (union ({'a', 'b'}, []), {'a';'b'}) | |
102 %!assert (union (['a', 'b'], {}), {'ab'}) | |
103 %!assert (union ({}, ['a', 'b']), {'ab'}) | |
104 | |
97 ## Test common input validation for set routines contained in validsetargs | 105 ## Test common input validation for set routines contained in validsetargs |
98 %!error <cell array of strings cannot be combined> union ({"a"}, 1) | 106 %!error <cell array of strings cannot be combined> union ({"a"}, 1) |
99 %!error <A and B must be arrays or cell arrays> union (@sin, 1) | 107 %!error <A and B must be arrays or cell arrays> union (@sin, 1) |
100 %!error <invalid option: columns> union (1, 2, "columns") | 108 %!error <invalid option: columns> union (1, 2, "columns") |
101 %!error <cells not supported with "rows"> union ({"a"}, {"b"}, "rows") | 109 %!error <cells not supported with "rows"> union ({"a"}, {"b"}, "rows") |