# HG changeset patch # User Fernando Alvarruiz # Date 1745425891 -7200 # Wed Apr 23 18:31:31 2025 +0200 # Node ID 895b2cb2e455af73a3c062231d5ecc3abae9e01e # Parent 3d0a5e969eb700222f9a740b59790a7525b1dc14 test: Add BIST tests for cellfun & arrayfun (bug #66642) * cellfun.cc: split existing cellfun BIST test (expecting an error when provided function returns fewer than requested outputs) to consider 2 cases: first function call and subsequent calls. The same for corresponding arrayfun BIST test. Add cellfun & arrayfun BIST tests expecting an error when provided function returns fewer than requested outputs and UniformOutput is false. Add cellfun & arrayfun BIST tests for the case when the provided function returns more outputs than requested. diff -r 3d0a5e969eb7 -r 895b2cb2e455 libinterp/corefcn/cellfun.cc --- a/libinterp/corefcn/cellfun.cc Wed Apr 23 11:01:55 2025 -0400 +++ b/libinterp/corefcn/cellfun.cc Wed Apr 23 18:31:31 2025 +0200 @@ -1063,9 +1063,25 @@ ## An error should occur if called function does not return requested outputs %!function [a, b] = __counterror (x) %! a = x; +%! if x>0 +%! b = x; +%! endif %!endfunction -%!test <66642> -%! fail ("[a, b] = cellfun (@__counterror, {1, 4})"); +%!test <66642> # First call returns fewer outputs +%! fail ("[a, b] = cellfun (@__counterror, {-1, 4})"); +%!test <66642> # Subsequent call returns fewer outputs +%! fail ("[a, b] = cellfun (@__counterror, {1, -4})"); +%!test <66642> # Non-uniform output +%! fail ("[a, b] = cellfun (@__counterror, {1, -4}, 'UniformOutput', false)"); +%!test <66642> # It's OK to return more outputs than requested +%! a = cellfun (@__counterror, {1, -4}); +%! assert (a, [1, -4]) +%! a = cellfun (@__counterror, {-1, 4}); +%! assert (a, [-1, 4]) +%! cellfun (@__counterror, {-1, 4}); +%! assert (ans, [-1, 4]); +%! cellfun (@__counterror, {1, -4}); +%! assert (ans, [1, -4]); ## Test input validation %!error cellfun (1) @@ -1723,9 +1739,25 @@ ## An error should occur if called function does not return requested outputs %!function [a, b] = __counterror (x) %! a = x; +%! if x>0 +%! b = x; +%! endif %!endfunction -%!test <66642> -%! fail ("[a, b] = arrayfun (@__counterror, [1, 4])"); +%!test <66642> # First call returns fewer outputs +%! fail ("[a, b] = arrayfun (@__counterror, [-1, 4])"); +%!test <66642> # Subsequent call returns fewer outputs +%! fail ("[a, b] = arrayfun (@__counterror, [1, -4])"); +%!test <66642> # Non-uniform output +%! fail ("[a, b] = arrayfun (@__counterror, [1, -4], 'UniformOutput', false)"); +%!test <66642> # It's OK to return more outputs than requested +%! a = arrayfun (@__counterror, [1, -4]); +%! assert (a, [1, -4]) +%! a = arrayfun (@__counterror, [-1, 4]); +%! assert (a, [-1, 4]) +%! arrayfun (@__counterror, [-1, 4]); +%! assert (ans, [-1, 4]); +%! arrayfun (@__counterror, [1, -4]); +%! assert (ans, [1, -4]); */ static void