[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
John W. Eaton
Fri, 28 Apr 2000 01:47:34 -0500 (CDT)
On 16-Apr-2000, Paul Kienzle <address@hidden> wrote:
| Hi! I've been toying with test scripts for the functions that I've
| been writing. That way, when I go in and change things or add new
| features, I can easily test if I've broken any existing features.
| More importantly, if others modify my routines, they can easily test
| cases that they might not have thought of. I quickly concluded that
| it would be best if the test script is stored in the file itself.
| I wrote ftest, which extracts lines starting with ##! and
| evaluates them with eval(). It doesn't cope with syntax errors
| elegantly, but I wanted to throw it out there and get some feedback.
| ## usage: r = mod(x,y)
| ## Compute modulo function, handling negative number correctly; i.e.,
| ## mod(-1,3) is 2, not -1 as rem(-1,3) returns.
| function r=mod(x,y)
| if nargin != 2, usage("r=mod(x,y)"); endif
| r = x - floor(x./y).*y;
| ##! if mod(5,3) != 2, disp("mod fails for positive a"); endif
| ##! if mod(-5,3) != 1, disp("mod fails for negative a"); endif
| ##! if mod(0,3) != 0, disp("mod fails for a=0"); endif
| ##! if !isempty(mod(,)), disp("mod fails for empty"); endif
| ##! if any(mod([-5 5 0],[3 3 3]) != [1 2 0]),
| ##! disp("mod fails for columns"); endif
| ##! if any(mod([-5 5 0]',[3 3 3]') != [1 2 0]'),
| ##! disp("mod fails for rows"); endif
| ##! if any(any(mod([-5 5; 0 3],[3 3 ; 3 1]) != [1 2 ; 0 0])),
| ##! disp("mod fails for matrices"); endif
I like this idea, as it puts the tests with the code, instead of in a
separate file in a separate directory tree as they are now.
It would be nice to move all the tests from the current tests
directory into the files that they test, and then have the check
target in the makefiles run the tests automatically. To make that
work, some problems might have to be solved, such as a way to continue
processing tests if one happens to cause Octave to crash. Or, a way
to reliably test argument passing (does the correct thing happen if
you pass the wrong number of arguments to a function, etc.).
- test scripts,
John W. Eaton <=