Mercurial > hg > octave-nkf
changeset 18616:06970f4625b8 stable
assert.m: allow assertions for function handles
* assert.m: Allow expected value to be a function handle.
New tests.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 06 Mar 2014 14:25:25 -0500 |
parents | 9472e3c8f43e |
children | 43cc202335dc |
files | scripts/testfun/assert.m |
diffstat | 1 files changed, 19 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/testfun/assert.m +++ b/scripts/testfun/assert.m @@ -141,6 +141,19 @@ end_try_catch endif + elseif (is_function_handle (expected)) + if (! is_function_handle (cond)) + err.index{end+1} = "@"; + err.observed{end+1} = "O"; + err.expected{end+1} = "E"; + err.reason{end+1} = ["Expected function handle, but observed " class(cond)]; + elseif (! isequal (cond, expected)) + err.index{end+1} = "@"; + err.observed{end+1} = "O"; + err.expected{end+1} = "E"; + err.reason{end+1} = "Function handles don't match"; + endif + elseif (isstruct (expected)) if (! isstruct (cond)) err.index{end+1} = "."; @@ -534,6 +547,12 @@ %! y{1}{1}{1} = 3; %! fail ("assert (x,y)", "Abs err 2 exceeds tol 0"); +## function handles +%!assert (@sin, @sin) +%!error <Function handles don't match> assert (@sin, @cos) +%!error <Expected function handle, but observed double> assert (pi, @cos) +%!error <Class function_handle != double> assert (@sin, pi) + %!test %! x = {[3], [1,2,3]; 100+100*eps, "dog"}; %! y = x;