# HG changeset patch # User slackydeb # Date 1331680785 0 # Node ID a2504a30b53eb26b0046f773c2d009d9bb9c9eb9 # Parent 52bed450823089101ce492ca1dc7409eceee2158 ga: review unit tests of rastriginsfcn diff -r 52bed4508230 -r a2504a30b53e main/ga/inst/ga_test.m --- a/main/ga/inst/ga_test.m Tue Mar 13 22:47:05 2012 +0000 +++ b/main/ga/inst/ga_test.m Tue Mar 13 23:19:45 2012 +0000 @@ -45,5 +45,5 @@ test ga ## TODO: split performance tests -## TODO: review all unit tests -## TODO: write missing unit tests, or write pre-function TODOs +## TODO: review all unit tests (DONE: rastriginsfcn) +## TODO: write missing unit tests, or write per-function TODOs diff -r 52bed4508230 -r a2504a30b53e main/ga/inst/rastriginsfcn.m --- a/main/ga/inst/rastriginsfcn.m Tue Mar 13 22:47:05 2012 +0000 +++ b/main/ga/inst/rastriginsfcn.m Tue Mar 13 23:19:45 2012 +0000 @@ -14,15 +14,16 @@ ## along with this program; If not, see . ## -*- texinfo -*- -## @deftypefn{Function File} {} rastriginsfcn (@var{x}) +## @deftypefn{Function File} {@var{y} =} rastriginsfcn (@var{x}) ## Rastrigin's function. ## @end deftypefn ## Author: Luca Favatella -## Version: 1.4 +## Version: 2.0 function retval = rastriginsfcn (x) - if (nargout != 1) + if ((nargin != 1) || (nargout != 1) || + (columns (x) != 2)) print_usage (); else x1 = x(:, 1); @@ -33,8 +34,15 @@ endfunction -%!error rastriginsfcn () -%!error rastriginsfcn ([0, 0], "other argument") +## number of arguments +%!error y = rastriginsfcn () +%!error y = rastriginsfcn ([0, 0], "other argument") +%!error [y1, y2] = rastriginsfcn ([0, 0]) + +## type of arguments +%!error y = rastriginsfcn ([0; 0]) +%!error y = rastriginsfcn (zeros (2, 3)) # TODO: document size of x %!assert (rastriginsfcn ([0, 0]), 0) -%!assert (rastriginsfcn ([0, 0; 0, 0]), [0; 0]) \ No newline at end of file +%!assert (rastriginsfcn ([0, 0; 0, 0]), [0; 0]) +%!assert (rastriginsfcn (zeros (3, 2)), [0; 0; 0])