[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: firls.m, part 2
From: |
Mike Miller |
Subject: |
Re: firls.m, part 2 |
Date: |
Tue, 20 Jun 2017 11:05:30 -0700 |
User-agent: |
NeoMutt/20170306 (1.8.0) |
On Tue, Jun 20, 2017 at 17:52:06 +0000, je suis wrote:
> Using the link for expint() shows spot on results, compared to my
> cooked up version.
Good, so no changes needed, you can use that function file until Octave
4.4 is released if that works for you.
> > I notice there are still no built-in tests at the end of the current
> > version. I'd recommend adding a bunch of those for basic input/output
> > form checking as well as a few (simple if possible) expected numerical
> > outputs. I think one of my past emails may have included some
> > examples.
>
> There are some checks in the beginning, those should take care of too
> few, or too many arguments, correct string arguments, and correct
> numeric ones (thought not for N). Should I delete those and replace
> them with the %! tyoe checks you gave as example?
You should have both. Input validation checking in the function body is
for the function to work correctly, to report errors to the user. The %!
blocks at the end of the function file are runtime tests for the "test"
function to validate that the function continues to work the way you
expect it to.
Look at Octave functions for plenty of examples. Here is how a very
simple function to square a number should be written:
function y = squared (x)
if (nargin != 1)
print_usage ();
endif
if (! isnumeric (x))
error ("squared: X must be a numeric value");
endif
y = x .^ 2;
endfunction
%!assert (squared (0), 0)
%!assert (squared (1), 1)
%!assert (squared (2), 4)
%!assert (squared ([]), [])
%!assert (squared ([1, 2, 3, 4]), [1, 4, 9, 16])
## Test input validation
%!error squared ()
%!error squared (1, 2)
%!error squared ("one")
%!error squared (true)
--
mike
- Re: firls.m, part 2, (continued)
- Re: firls.m, part 2, Mike Miller, 2017/06/19
- Re: firls.m, part 2, je suis, 2017/06/19
- Re: firls.m, part 2, Mike Miller, 2017/06/19
- Re: firls.m, part 2, Nicholas Jankowski, 2017/06/19
- Re: firls.m, part 2, Nicholas Jankowski, 2017/06/19
- Re: firls.m, part 2, je suis, 2017/06/20
- Re: firls.m, part 2, Mike Miller, 2017/06/20
- Re: firls.m, part 2, Nicholas Jankowski, 2017/06/20
- Re: firls.m, part 2, Francesco Potortì, 2017/06/19
- Re: firls.m, part 2, je suis, 2017/06/20
- Re: firls.m, part 2,
Mike Miller <=
- Re: firls.m, part 2, Nicholas Jankowski, 2017/06/20
- Re: firls.m, part 2, Nicholas Jankowski, 2017/06/20
- Re: firls.m, part 2, je suis, 2017/06/21
- Re: firls.m, part 2, Nicholas Jankowski, 2017/06/21
- Re: firls.m, part 2, Nicholas Jankowski, 2017/06/21
- Re: firls.m, part 2, je suis, 2017/06/23
- Re: firls.m, part 2, Nicholas Jankowski, 2017/06/23
- Re: firls.m, part 2, Nicholas Jankowski, 2017/06/23
- Re: firls.m, part 2, je suis, 2017/06/25
- Re: firls.m, part 2, Nicholas Jankowski, 2017/06/25