1// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2// Copyright (C) 2008-2009 - INRIA - Michael Baudin
3// Copyright (C) 2011 - DIGITEO - Michael Baudin
4//
5// Copyright (C) 2012 - 2016 - Scilab Enterprises
6//
7// This file is hereby licensed under the terms of the GNU GPL v2.0,
8// pursuant to article 5.3.4 of the CeCILL v.2.1.
9// This file was originally licensed under the terms of the CeCILL v2.1,
10// and continues to be available under such terms.
11// For more information, see the COPYING file which you should have received
12// along with this program.
13
14// <-- CLI SHELL MODE -->
15
16//
17// Test #1 : Without parameters
18//
19op = optimset ();
20assert_checkequal ( op.Display , [] );
21assert_checkequal ( op.FunValCheck , [] );
22assert_checkequal ( op.MaxFunEvals , [] );
23assert_checkequal ( op.MaxIter , [] );
24assert_checkequal ( op.OutputFcn , [] );
25assert_checkequal ( op.PlotFcns , [] );
26assert_checkequal ( op.TolFun , [] );
27assert_checkequal ( op.TolX , [] );
28clear op
29function y = myoutputfun (x)
30  y = x;
31endfunction
32function y = myplotfun (x)
33  y = x;
34endfunction
35//
36// Test #2 : With parameters
37//
38op = optimset (...
39  'Display','iter',...
40  "FunValCheck","on",...
41  "MaxFunEvals",100,...
42  "MaxIter",110,...
43  "OutputFcn",myoutputfun,...
44  "PlotFcns",myplotfun,...
45  "TolFun",1.e-12,...
46  "TolX",1.e-13...
47  );
48assert_checkequal ( op.Display , "iter" );
49assert_checkequal ( op.FunValCheck , "on" );
50assert_checkequal ( op.MaxFunEvals , 100 );
51assert_checkequal ( op.MaxIter , 110 );
52//assert_checkequal ( op.OutputFcn , myoutputfun );
53//assert_checkequal ( op.PlotFcns , myplotfun );
54assert_checkequal ( op.TolFun , 1.e-12 );
55assert_checkequal ( op.TolX , 1.e-13 );
56clear op
57//
58// Test #3 : Copy one option set into another
59//
60op1 = optimset ("TolFun",1.e-12);
61op2 = optimset (op1,"TolX",1.e-13);
62assert_checkequal ( op2.TolFun , 1.e-12 );
63assert_checkequal ( op2.TolX , 1.e-13 );
64clear op1
65clear op2
66//
67// Test #3 : with one method name
68//
69op = optimset ("fminsearch");
70assert_checkequal ( op.TolFun , 1.e-4 );
71assert_checkequal ( op.TolX , 1.e-4 );
72assert_checkequal ( op.Display , "notify" );
73assert_checkequal ( op.MaxFunEvals , "200*numberofvariables" );
74assert_checkequal ( op.MaxIter , "200*numberofvariables" );
75clear op
76
77//
78// Test where the first input argument is not a struct
79//
80cmd = "optimset (''foo'',''MaxFunEvals'',100)";
81assert_checkerror(cmd,"%s: Odd number of arguments : the first argument is expected to be a struct, but is a %s",[],"optimset","string");
82//
83// Test where the key is unknown
84//
85cmd = "optimset (''foo'',100)";
86assert_checkerror(cmd,"%s: Unrecognized parameter name ''%s''.",[],"optimset","foo");
87
88//
89// Test where the algorithm is unknown
90//
91cmd = "optimset (''foo'')";
92assert_checkerror(cmd,"%s: No default options available: the function ''%s'' does not exist on the path.",[],"optimset","foo");
93//
94// Test where the Display key is unknown
95//
96cmd = "optimset (''Display'',''foo'')";
97assert_checkerror(cmd,"%s: Unrecognized value ''%s'' for ''Display'' option.",[],"optimset","foo");
98//
99// Test all possible values of Display
100//
101op = optimset ( "Display" , "final" );
102assert_checkequal ( op.Display , "final" );
103op = optimset ( "Display" , "iter" );
104assert_checkequal ( op.Display , "iter" );
105op = optimset ( "Display" , "off" );
106assert_checkequal ( op.Display , "off" );
107op = optimset ( "Display" , "notify" );
108assert_checkequal ( op.Display , "notify" );
109
110