From: <sla...@us...> - 2012-03-17 02:55:15
|
Revision: 9929 http://octave.svn.sourceforge.net/octave/?rev=9929&view=rev Author: slackydeb Date: 2012-03-17 02:55:09 +0000 (Sat, 17 Mar 2012) Log Message: ----------- ga: add unit tests for ga Modified Paths: -------------- trunk/octave-forge/main/ga/inst/ga.m Modified: trunk/octave-forge/main/ga/inst/ga.m =================================================================== --- trunk/octave-forge/main/ga/inst/ga.m 2012-03-16 22:29:17 UTC (rev 9928) +++ trunk/octave-forge/main/ga/inst/ga.m 2012-03-17 02:55:09 UTC (rev 9929) @@ -1,4 +1,4 @@ -## Copyright (C) 2008, 2010 Luca Favatella <sla...@gm...> +## Copyright (C) 2008, 2010, 2012 Luca Favatella <sla...@gm...> ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by @@ -71,7 +71,7 @@ ## @end deftypefn ## Author: Luca Favatella <sla...@gm...> -## Version: 6.0.0 +## Version: 6.0.1 function [x fval exitflag output population scores] = \ ga (fitnessfcn_or_problem, @@ -116,9 +116,39 @@ ## number of arguments +%!shared f, nvars +%! f = @rastriginsfcn; +%! nvars = 2; +%!error x = ga () +%!error x = ga (f) +%!error x = ga (f, nvars, []) +%!error x = ga (f, nvars, [], [], []) +%!error x = ga (f, nvars, [], [], [], [], []) +%!error x = ga (f, nvars, [], [], [], [], [], [], @(x) [[], []], gaoptimset (), []) ## type of arguments +# TODO +%!shared f, nvars +%! f = @rastriginsfcn; +%! nvars = 2; +#%!function [C, Ceq] = nonlcon (x) +#%! C = []; +#%! Ceq = []; +#%!endfunction +%!test x = ga (f, nvars); +%!test x = ga (f, nvars, [], []); +%!test x = ga (f, nvars, ones (3, nvars), ones (3, 1)); +%!test x = ga (f, nvars, [], [], [], []); +%!test x = ga (f, nvars, [], [], ones (4, nvars), ones (4, 1)); +%!test x = ga (f, nvars, [], [], [], [], [], []); +%!test x = ga (f, nvars, [], [], [], [], - Inf (1, nvars), Inf (1, nvars)); +%!test x = ga (f, nvars, [], [], [], [], - ones (1, nvars), ones (1, nvars)); +%!test x = ga (f, nvars, [], [], [], [], [], [], @(x) [[], []]); +#%!test x = ga (f, nvars, [], [], [], [], [], [], @nonlcon); +%!test x = ga (f, nvars, [], [], [], [], [], [], @(x) [[], []], gaoptimset ()); + + %!test x = ga (struct ("fitnessfcn", @rastriginsfcn, "nvars", 2, "options", gaoptimset ("FitnessLimit", 1e-7, "Generations", 1000))); %!test x = ga (struct ("fitnessfcn", @(x) rastriginsfcn (x(1:2)) + ((x(3) ** 2) - (cos (2 * pi * x(3))) + 1) + (x(4) ** 2), "nvars", 4, "options", gaoptimset ("EliteCount", 5, "FitnessLimit", 1e-7, "PopInitRange", [-2; 2], "PopulationSize", 200))); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |