Mercurial > repos > public > sbplib
changeset 277:4c3f55a628c8 feature/beams
Made evalOn give more error message.
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Wed, 07 Sep 2016 13:47:05 +0200 |
parents | 30321dc180e1 |
children | 9eff7b58c5f7 |
files | +grid/evalOn.m +grid/evalOnTest.m |
diffstat | 2 files changed, 22 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
diff -r 30321dc180e1 -r 4c3f55a628c8 +grid/evalOn.m --- a/+grid/evalOn.m Wed Sep 07 10:13:26 2016 +0200 +++ b/+grid/evalOn.m Wed Sep 07 13:47:05 2016 +0200 @@ -16,6 +16,13 @@ end % func should now be a function_handle + if g.D ~= nargin(func) + g.D + nargin(func) + error('grid:evalOn:WrongNumberOfInputs', 'The number of inputs of the function must match the dimension of the domain.') + end + + % Get coordinates and convert to cell array for easier use as a parameter x = num2cell(g.points());
diff -r 30321dc180e1 -r 4c3f55a628c8 +grid/evalOnTest.m --- a/+grid/evalOnTest.m Wed Sep 07 10:13:26 2016 +0200 +++ b/+grid/evalOnTest.m Wed Sep 07 13:47:05 2016 +0200 @@ -25,6 +25,21 @@ end end +% evalOn should give and error if the number of inputs to func is not the same as +% the number of dimensions of the grid. +function testNumberOfInputs(testCase) + cases = { + {getTestGrid('1d'), @(x,y)x-y}, + {getTestGrid('2d'), @(x)x }, + } + + for i = 1:length(cases) + g = cases{i}{1}; + f = cases{i}{2}; + testCase.verifyError(@()grid.evalOn(g, f),'grid:evalOn:WrongNumberOfInputs',sprintf('in(%d) = %s',i,toString(f))); + end +end + function testInputScalarFunction1d(testCase) in = { @(x)1+x*0,