364
edits
Carandraug (talk | contribs) (added link for octave manual) |
(=Level1= is intended for the page title) |
||
Line 1: | Line 1: | ||
Writing tests for function is an important thing that is usually overlooked. It helps a lot in preventing regression. There's a section in the | Writing tests for function is an important thing that is usually overlooked. It helps a lot in preventing regression. There's a section in the Octave manual on [http://www.gnu.org/software/octave/doc/interpreter/Test-Functions.html#Test-Functions Test Functions]. | ||
= Writing tests | == Writing tests == | ||
function experience | Octave provides for robust testing of functions. The manual includes a section on the [http://www.gnu.org/software/octave/doc/interpreter/Test-Functions.html#Test-Functions Test Functions]. Several examples are included. | ||
===Declaring Functions Inside a Test Block=== | |||
Octave's ''test'' function automatically inserts the contents of each test block into a function. Although it is admittedly hacky/ugly, this implies that addition functions may be declared within a test block. For example, the empty function below named {{Codeline|experience}} is accompanied by a single test block which includes two function definitions. | |||
function experience () | |||
%!test | %!test | ||
%! experience_design_mat | %! experience_design_mat | ||
Line 24: | Line 27: | ||
%! % endfunction: don't add it here. Let test() do it. | %! % endfunction: don't add it here. Let test() do it. | ||
= | == Running Tests == | ||
== | |||
Tests are run tests in m-files by using the {{Codeline|test}} function/command. For example, to test the {{Codeline|experience}} above use the command below. | |||
test experience | |||
Or alternatively, use the functional form | |||
test ("experience") | |||
To run tests in .cc files, the path to the file must be provided. | |||
test /full/path/to/file.cc | test /full/path/to/file.cc |
edits