Mercurial > forge
changeset 9690:a2504a30b53e octave-forge
ga: review unit tests of rastriginsfcn
author | slackydeb |
---|---|
date | Tue, 13 Mar 2012 23:19:45 +0000 |
parents | 52bed4508230 |
children | 617395740b29 |
files | main/ga/inst/ga_test.m main/ga/inst/rastriginsfcn.m |
diffstat | 2 files changed, 16 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- 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
--- 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 <http://www.gnu.org/licenses/>. ## -*- texinfo -*- -## @deftypefn{Function File} {} rastriginsfcn (@var{x}) +## @deftypefn{Function File} {@var{y} =} rastriginsfcn (@var{x}) ## Rastrigin's function. ## @end deftypefn ## Author: Luca Favatella <slackydeb@gmail.com> -## 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])