Editing Tests
Jump to navigation
Jump to search
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 1: | Line 1: | ||
= Tests = | |||
Writing tests for function is an important thing that is usually overlooked. It helps a lot in preventing regression. | |||
== Writing tests == | == Writing tests == | ||
=== in .m files === | |||
=== in .cc files === | |||
===declaring functions inside a test block=== | |||
function experience | |||
%!test | |||
%! experience_design_mat | |||
%! experience_obs_eqs | |||
%! assert (experience_design_mat == pi); | |||
%! assert (experience_obs_eqs == exp(1)); | |||
%! | |||
%! endfunction % this is a trick. | |||
%! % now we can declare functions to be used by the test above. | |||
%! | |||
%! function a = experience_design_mat | |||
%! a = pi; | |||
%! endfunction | |||
%! | |||
%! function b = experience_obs_eqs | |||
%! b = exp(1); | |||
%! % endfunction: don't add it here. Let test() do it. | |||
%! | |||
%! | |||
%! | |||
%!assert ( | |||
%!assert ( | |||
%! | |||
%! | |||
% | |||
%!function | |||
%! | |||
%! | |||
%! | |||
% | |||
== running tests == | |||
=== from m files === | |||
=== from .cc files === | |||
You can run tests in .cc files by doing something like | |||
test /full/path/to/file.cc |