summaryrefslogtreecommitdiff
path: root/tests/unit_tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit_tests')
-rw-r--r--tests/unit_tests/fgoalattain.dia.ref74
-rw-r--r--tests/unit_tests/fgoalattain.tst74
-rw-r--r--tests/unit_tests/fminbnd.dia.ref71
-rw-r--r--tests/unit_tests/fminbnd.tst71
-rw-r--r--tests/unit_tests/fmincon.dia.ref98
-rw-r--r--tests/unit_tests/fmincon.tst98
-rw-r--r--tests/unit_tests/fminimax.dia.ref105
-rw-r--r--tests/unit_tests/fminimax.tst105
-rw-r--r--tests/unit_tests/fminunc.dia.ref79
-rw-r--r--tests/unit_tests/fminunc.tst79
-rw-r--r--tests/unit_tests/linprog.dia.ref68
-rw-r--r--tests/unit_tests/linprog.tst68
-rw-r--r--tests/unit_tests/qpipopt_base.dia.ref4
-rw-r--r--tests/unit_tests/qpipopt_base.tst4
-rw-r--r--tests/unit_tests/qpipoptmat_base.dia.ref2
-rw-r--r--tests/unit_tests/qpipoptmat_base.tst2
16 files changed, 996 insertions, 6 deletions
diff --git a/tests/unit_tests/fgoalattain.dia.ref b/tests/unit_tests/fgoalattain.dia.ref
new file mode 100644
index 0000000..3587dd3
--- /dev/null
+++ b/tests/unit_tests/fgoalattain.dia.ref
@@ -0,0 +1,74 @@
+// Copyright (C) 2015 - IIT Bombay - FOSSEE
+//
+// Author: Prajwala TM,Sheetal Shalini
+// Organization: FOSSEE, IIT Bombay
+// Email: toolbox@scilab.in
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+
+// <-- JVM NOT MANDATORY -->
+// <-- ENGLISH IMPOSED -->
+
+
+//
+// assert_close --
+// Returns 1 if the two real matrices computed and expected are close,
+// i.e. if the relative distance between computed and expected is lesser than epsilon.
+// Arguments
+// computed, expected : the two matrices to compare
+// epsilon : a small number
+//
+function flag = assert_close ( computed, expected, epsilon )
+ if expected==0.0 then
+ shift = norm(computed-expected);
+ else
+ shift = norm(computed-expected)/norm(expected);
+ end
+// if shift < epsilon then
+// flag = 1;
+// else
+// flag = 0;
+// end
+// if flag <> 1 then pause,end
+ flag = assert_checktrue ( shift < epsilon );
+endfunction
+//
+// assert_equal --
+// Returns 1 if the two real matrices computed and expected are equal.
+// Arguments
+// computed, expected : the two matrices to compare
+// epsilon : a small number
+//
+//function flag = assert_equal ( computed , expected )
+// if computed==expected then
+// flag = 1;
+// else
+// flag = 0;
+// end
+// if flag <> 1 then pause,end
+//endfunction
+
+
+function f1 = fun(x)
+f1(1)=2*x(1)*x(1)+x(2)*x(2)-48*x(1)-40*x(2)+304
+f1(2)=-x(1)*x(1)-3*x(2)*x(2)
+f1(3)=x(1)+3*x(2)-18
+f1(4)=-x(1)-x(2)
+f1(5)=x(1)+x(2)-8
+endfunction
+x0=[-1,1];
+goal=[-5,-3,-2,-1,-4];
+weight=abs(goal)
+//xopt = [-0.0000011 -63.999998 -2.0000002 -8 3.485D-08]
+//fval = [4 3.99]
+//Run fgoalattain
+[xopt,fval,attainfactor,exitflag,output,lambda]=fgoalattain(fun,x0,goal,weight)
+
+assert_close ( xopt , [ 4 4 ]' , 0.0005 );
+assert_close ( fval , [ -0.0000011 -63.999998 -2.0000002 -8. 0 ]' , 0.0005 );
+assert_checkequal( exitflag , int32(0) );
+printf("Test Successful");
diff --git a/tests/unit_tests/fgoalattain.tst b/tests/unit_tests/fgoalattain.tst
new file mode 100644
index 0000000..3587dd3
--- /dev/null
+++ b/tests/unit_tests/fgoalattain.tst
@@ -0,0 +1,74 @@
+// Copyright (C) 2015 - IIT Bombay - FOSSEE
+//
+// Author: Prajwala TM,Sheetal Shalini
+// Organization: FOSSEE, IIT Bombay
+// Email: toolbox@scilab.in
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+
+// <-- JVM NOT MANDATORY -->
+// <-- ENGLISH IMPOSED -->
+
+
+//
+// assert_close --
+// Returns 1 if the two real matrices computed and expected are close,
+// i.e. if the relative distance between computed and expected is lesser than epsilon.
+// Arguments
+// computed, expected : the two matrices to compare
+// epsilon : a small number
+//
+function flag = assert_close ( computed, expected, epsilon )
+ if expected==0.0 then
+ shift = norm(computed-expected);
+ else
+ shift = norm(computed-expected)/norm(expected);
+ end
+// if shift < epsilon then
+// flag = 1;
+// else
+// flag = 0;
+// end
+// if flag <> 1 then pause,end
+ flag = assert_checktrue ( shift < epsilon );
+endfunction
+//
+// assert_equal --
+// Returns 1 if the two real matrices computed and expected are equal.
+// Arguments
+// computed, expected : the two matrices to compare
+// epsilon : a small number
+//
+//function flag = assert_equal ( computed , expected )
+// if computed==expected then
+// flag = 1;
+// else
+// flag = 0;
+// end
+// if flag <> 1 then pause,end
+//endfunction
+
+
+function f1 = fun(x)
+f1(1)=2*x(1)*x(1)+x(2)*x(2)-48*x(1)-40*x(2)+304
+f1(2)=-x(1)*x(1)-3*x(2)*x(2)
+f1(3)=x(1)+3*x(2)-18
+f1(4)=-x(1)-x(2)
+f1(5)=x(1)+x(2)-8
+endfunction
+x0=[-1,1];
+goal=[-5,-3,-2,-1,-4];
+weight=abs(goal)
+//xopt = [-0.0000011 -63.999998 -2.0000002 -8 3.485D-08]
+//fval = [4 3.99]
+//Run fgoalattain
+[xopt,fval,attainfactor,exitflag,output,lambda]=fgoalattain(fun,x0,goal,weight)
+
+assert_close ( xopt , [ 4 4 ]' , 0.0005 );
+assert_close ( fval , [ -0.0000011 -63.999998 -2.0000002 -8. 0 ]' , 0.0005 );
+assert_checkequal( exitflag , int32(0) );
+printf("Test Successful");
diff --git a/tests/unit_tests/fminbnd.dia.ref b/tests/unit_tests/fminbnd.dia.ref
new file mode 100644
index 0000000..bed9eae
--- /dev/null
+++ b/tests/unit_tests/fminbnd.dia.ref
@@ -0,0 +1,71 @@
+// Copyright (C) 2015 - IIT Bombay - FOSSEE
+//
+// Author: R.Vidyadhar & Vignesh Kannan
+// Organization: FOSSEE, IIT Bombay
+// Email: toolbox@scilab.in
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+
+// <-- JVM NOT MANDATORY -->
+// <-- ENGLISH IMPOSED -->
+
+
+//
+// assert_close --
+// Returns 1 if the two real matrices computed and expected are close,
+// i.e. if the relative distance between computed and expected is lesser than epsilon.
+// Arguments
+// computed, expected : the two matrices to compare
+// epsilon : a small number
+//
+function flag = assert_close ( computed, expected, epsilon )
+ if expected==0.0 then
+ shift = norm(computed-expected);
+ else
+ shift = norm(computed-expected)/norm(expected);
+ end
+// if shift < epsilon then
+// flag = 1;
+// else
+// flag = 0;
+// end
+// if flag <> 1 then pause,end
+ flag = assert_checktrue ( shift < epsilon );
+endfunction
+//
+// assert_equal --
+// Returns 1 if the two real matrices computed and expected are equal.
+// Arguments
+// computed, expected : the two matrices to compare
+// epsilon : a small number
+//
+//function flag = assert_equal ( computed , expected )
+// if computed==expected then
+// flag = 1;
+// else
+// flag = 0;
+// end
+// if flag <> 1 then pause,end
+//endfunction
+
+//Find x in R such that it minimizes:
+//f(x)= 1/x^2
+//0 <= x <= 1000
+//Objective function to be minimised
+function y=f(x)
+y=1/x^2
+endfunction
+//Variable bounds
+x1 = [0];
+x2 = [1000];
+//Calling Ipopt
+[xopt,fval,exitflag,output,lambda] =fminbnd(f, x1, x2)
+
+assert_close ( xopt , [ 32.27955 ]' , 0.0005 );
+assert_close ( fval , [ 0.0009597 ]' , 0.0005 );
+assert_checkequal( exitflag , int32(0) );
+printf("Test Successful");
diff --git a/tests/unit_tests/fminbnd.tst b/tests/unit_tests/fminbnd.tst
new file mode 100644
index 0000000..bed9eae
--- /dev/null
+++ b/tests/unit_tests/fminbnd.tst
@@ -0,0 +1,71 @@
+// Copyright (C) 2015 - IIT Bombay - FOSSEE
+//
+// Author: R.Vidyadhar & Vignesh Kannan
+// Organization: FOSSEE, IIT Bombay
+// Email: toolbox@scilab.in
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+
+// <-- JVM NOT MANDATORY -->
+// <-- ENGLISH IMPOSED -->
+
+
+//
+// assert_close --
+// Returns 1 if the two real matrices computed and expected are close,
+// i.e. if the relative distance between computed and expected is lesser than epsilon.
+// Arguments
+// computed, expected : the two matrices to compare
+// epsilon : a small number
+//
+function flag = assert_close ( computed, expected, epsilon )
+ if expected==0.0 then
+ shift = norm(computed-expected);
+ else
+ shift = norm(computed-expected)/norm(expected);
+ end
+// if shift < epsilon then
+// flag = 1;
+// else
+// flag = 0;
+// end
+// if flag <> 1 then pause,end
+ flag = assert_checktrue ( shift < epsilon );
+endfunction
+//
+// assert_equal --
+// Returns 1 if the two real matrices computed and expected are equal.
+// Arguments
+// computed, expected : the two matrices to compare
+// epsilon : a small number
+//
+//function flag = assert_equal ( computed , expected )
+// if computed==expected then
+// flag = 1;
+// else
+// flag = 0;
+// end
+// if flag <> 1 then pause,end
+//endfunction
+
+//Find x in R such that it minimizes:
+//f(x)= 1/x^2
+//0 <= x <= 1000
+//Objective function to be minimised
+function y=f(x)
+y=1/x^2
+endfunction
+//Variable bounds
+x1 = [0];
+x2 = [1000];
+//Calling Ipopt
+[xopt,fval,exitflag,output,lambda] =fminbnd(f, x1, x2)
+
+assert_close ( xopt , [ 32.27955 ]' , 0.0005 );
+assert_close ( fval , [ 0.0009597 ]' , 0.0005 );
+assert_checkequal( exitflag , int32(0) );
+printf("Test Successful");
diff --git a/tests/unit_tests/fmincon.dia.ref b/tests/unit_tests/fmincon.dia.ref
new file mode 100644
index 0000000..26d29ea
--- /dev/null
+++ b/tests/unit_tests/fmincon.dia.ref
@@ -0,0 +1,98 @@
+// Copyright (C) 2015 - IIT Bombay - FOSSEE
+//
+// Author: R.Vidyadhar & Vignesh Kannan
+// Organization: FOSSEE, IIT Bombay
+// Email: toolbox@scilab.in
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+
+// <-- JVM NOT MANDATORY -->
+// <-- ENGLISH IMPOSED -->
+
+
+//
+// assert_close --
+// Returns 1 if the two real matrices computed and expected are close,
+// i.e. if the relative distance between computed and expected is lesser than epsilon.
+// Arguments
+// computed, expected : the two matrices to compare
+// epsilon : a small number
+//
+function flag = assert_close ( computed, expected, epsilon )
+ if expected==0.0 then
+ shift = norm(computed-expected);
+ else
+ shift = norm(computed-expected)/norm(expected);
+ end
+// if shift < epsilon then
+// flag = 1;
+// else
+// flag = 0;
+// end
+// if flag <> 1 then pause,end
+ flag = assert_checktrue ( shift < epsilon );
+endfunction
+//
+// assert_equal --
+// Returns 1 if the two real matrices computed and expected are equal.
+// Arguments
+// computed, expected : the two matrices to compare
+// epsilon : a small number
+//
+//function flag = assert_equal ( computed , expected )
+// if computed==expected then
+// flag = 1;
+// else
+// flag = 0;
+// end
+// if flag <> 1 then pause,end
+//endfunction
+
+//Find x in R^3 such that it minimizes:
+//f(x)= x1*x2 + x2*x3
+//x0=[0.1 , 0.1 , 0.1]
+//constraint-1 (c1): x1^2 - x2^2 + x3^2 <= 2
+//constraint-2 (c2): x1^2 + x2^2 + x3^2 <= 10
+//Objective function to be minimised
+function y=f(x)
+y=x(1)*x(2)+x(2)*x(3);
+endfunction
+//Starting point, linear constraints and variable bounds
+x0=[0.1 , 0.1 , 0.1];
+A=[];
+b=[];
+Aeq=[];
+beq=[];
+lb=[];
+ub=[];
+//Nonlinear constraints
+function [c,ceq]=nlc(x)
+c = [x(1)^2 - x(2)^2 + x(3)^2 - 2 , x(1)^2 + x(2)^2 + x(3)^2 - 10];
+ceq = [];
+endfunction
+//Gradient of objective function
+function y= fGrad(x)
+y= [x(2),x(1)+x(3),x(2)];
+endfunction
+//Hessian of the Lagrange Function
+function y= lHess(x,obj,lambda)
+y= obj*[0,1,0;1,0,1;0,1,0] + lambda(1)*[2,0,0;0,-2,0;0,0,2] + lambda(2)*[2,0,0;0,2,0;0,0,2]
+endfunction
+//Gradient of Non-Linear Constraints
+function [cg,ceqg] = cGrad(x)
+cg=[2*x(1) , -2*x(2) , 2*x(3) ; 2*x(1) , 2*x(2) , 2*x(3)];
+ceqg=[];
+endfunction
+//Options
+options=list("MaxIter", [1500], "CpuTime", [500], "GradObj", fGrad, "Hessian", lHess,"GradCon", cGrad);
+//Calling Ipopt
+[xopt,fval,exitflag,output] =fmincon(f, x0,A,b,Aeq,beq,lb,ub,nlc,options)
+
+assert_close ( xopt , [ -1.5811388 2.236068 -1.5811388 ]' , 0.0005 );
+assert_close ( fval , [-7.0710678 ]' , 0.0005 );
+assert_checkequal( exitflag , int32(0) );
+printf("Test Successful");
diff --git a/tests/unit_tests/fmincon.tst b/tests/unit_tests/fmincon.tst
new file mode 100644
index 0000000..26d29ea
--- /dev/null
+++ b/tests/unit_tests/fmincon.tst
@@ -0,0 +1,98 @@
+// Copyright (C) 2015 - IIT Bombay - FOSSEE
+//
+// Author: R.Vidyadhar & Vignesh Kannan
+// Organization: FOSSEE, IIT Bombay
+// Email: toolbox@scilab.in
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+
+// <-- JVM NOT MANDATORY -->
+// <-- ENGLISH IMPOSED -->
+
+
+//
+// assert_close --
+// Returns 1 if the two real matrices computed and expected are close,
+// i.e. if the relative distance between computed and expected is lesser than epsilon.
+// Arguments
+// computed, expected : the two matrices to compare
+// epsilon : a small number
+//
+function flag = assert_close ( computed, expected, epsilon )
+ if expected==0.0 then
+ shift = norm(computed-expected);
+ else
+ shift = norm(computed-expected)/norm(expected);
+ end
+// if shift < epsilon then
+// flag = 1;
+// else
+// flag = 0;
+// end
+// if flag <> 1 then pause,end
+ flag = assert_checktrue ( shift < epsilon );
+endfunction
+//
+// assert_equal --
+// Returns 1 if the two real matrices computed and expected are equal.
+// Arguments
+// computed, expected : the two matrices to compare
+// epsilon : a small number
+//
+//function flag = assert_equal ( computed , expected )
+// if computed==expected then
+// flag = 1;
+// else
+// flag = 0;
+// end
+// if flag <> 1 then pause,end
+//endfunction
+
+//Find x in R^3 such that it minimizes:
+//f(x)= x1*x2 + x2*x3
+//x0=[0.1 , 0.1 , 0.1]
+//constraint-1 (c1): x1^2 - x2^2 + x3^2 <= 2
+//constraint-2 (c2): x1^2 + x2^2 + x3^2 <= 10
+//Objective function to be minimised
+function y=f(x)
+y=x(1)*x(2)+x(2)*x(3);
+endfunction
+//Starting point, linear constraints and variable bounds
+x0=[0.1 , 0.1 , 0.1];
+A=[];
+b=[];
+Aeq=[];
+beq=[];
+lb=[];
+ub=[];
+//Nonlinear constraints
+function [c,ceq]=nlc(x)
+c = [x(1)^2 - x(2)^2 + x(3)^2 - 2 , x(1)^2 + x(2)^2 + x(3)^2 - 10];
+ceq = [];
+endfunction
+//Gradient of objective function
+function y= fGrad(x)
+y= [x(2),x(1)+x(3),x(2)];
+endfunction
+//Hessian of the Lagrange Function
+function y= lHess(x,obj,lambda)
+y= obj*[0,1,0;1,0,1;0,1,0] + lambda(1)*[2,0,0;0,-2,0;0,0,2] + lambda(2)*[2,0,0;0,2,0;0,0,2]
+endfunction
+//Gradient of Non-Linear Constraints
+function [cg,ceqg] = cGrad(x)
+cg=[2*x(1) , -2*x(2) , 2*x(3) ; 2*x(1) , 2*x(2) , 2*x(3)];
+ceqg=[];
+endfunction
+//Options
+options=list("MaxIter", [1500], "CpuTime", [500], "GradObj", fGrad, "Hessian", lHess,"GradCon", cGrad);
+//Calling Ipopt
+[xopt,fval,exitflag,output] =fmincon(f, x0,A,b,Aeq,beq,lb,ub,nlc,options)
+
+assert_close ( xopt , [ -1.5811388 2.236068 -1.5811388 ]' , 0.0005 );
+assert_close ( fval , [-7.0710678 ]' , 0.0005 );
+assert_checkequal( exitflag , int32(0) );
+printf("Test Successful");
diff --git a/tests/unit_tests/fminimax.dia.ref b/tests/unit_tests/fminimax.dia.ref
new file mode 100644
index 0000000..e887a38
--- /dev/null
+++ b/tests/unit_tests/fminimax.dia.ref
@@ -0,0 +1,105 @@
+// Copyright (C) 2015 - IIT Bombay - FOSSEE
+//
+// Author: Animesh Baranawal
+// Organization: FOSSEE, IIT Bombay
+// Email: toolbox@scilab.in
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+
+// <-- JVM NOT MANDATORY -->
+// <-- ENGLISH IMPOSED -->
+
+
+//
+// assert_close --
+// Returns 1 if the two real matrices computed and expected are close,
+// i.e. if the relative distance between computed and expected is lesser than epsilon.
+// Arguments
+// computed, expected : the two matrices to compare
+// epsilon : a small number
+//
+function flag = assert_close ( computed, expected, epsilon )
+ if expected==0.0 then
+ shift = norm(computed-expected);
+ else
+ shift = norm(computed-expected)/norm(expected);
+ end
+// if shift < epsilon then
+// flag = 1;
+// else
+// flag = 0;
+// end
+// if flag <> 1 then pause,end
+ flag = assert_checktrue ( shift < epsilon );
+endfunction
+//
+// assert_equal --
+// Returns 1 if the two real matrices computed and expected are equal.
+// Arguments
+// computed, expected : the two matrices to compare
+// epsilon : a small number
+//
+//function flag = assert_equal ( computed , expected )
+// if computed==expected then
+// flag = 1;
+// else
+// flag = 0;
+// end
+// if flag <> 1 then pause,end
+//endfunction
+
+// A case where we provide the gradient of the objective
+// functions and the Jacobian matrix of the constraints.
+// The objective function and its gradient
+function f = myfun(x)
+f(1)= 2*x(1)^2 + x(2)^2 - 48*x(1) - 40*x(2) + 304;
+f(2)= -x(1)^2 - 3*x(2)^2;
+f(3)= x(1) + 3*x(2) -18;
+f(4)= -x(1) - x(2);
+f(5)= x(1) + x(2) - 8;
+endfunction
+// Defining gradient of myfun
+function G = myfungrad(x)
+G = [ 4*x(1) - 48, -2*x(1), 1, -1, 1;
+2*x(2) - 40, -6*x(2), 3, -1, 1; ]'
+endfunction
+// The nonlinear constraints and the Jacobian
+// matrix of the constraints
+function [c,ceq] = confun(x)
+// Inequality constraints
+c = [1.5 + x(1)*x(2) - x(1) - x(2), -x(1)*x(2) - 10]
+// No nonlinear equality constraints
+ceq=[]
+endfunction
+// Defining gradient of confungrad
+function [DC,DCeq] = cgrad(x)
+// DC(:,i) = gradient of the i-th constraint
+// DC = [
+// Dc1/Dx1 Dc1/Dx2
+// Dc2/Dx1 Dc2/Dx2
+// ]
+DC= [
+x(2)-1, -x(2)
+x(1)-1, -x(1)
+]'
+DCeq = []'
+endfunction
+// Test with both gradient of objective and gradient of constraints
+minimaxOptions = list("GradObj",myfungrad,"GradCon",cgrad);
+// The initial guess
+x0 = [0,10];
+// The expected solution : only 4 digits are guaranteed
+//xopt = [0.92791 7.93551]
+//fopt = [6.73443 -189.778 6.73443 -8.86342 0.86342]
+maxfopt = 6.73443
+// Run fminimax
+[xopt,fopt,maxfval,exitflag,output] = fminimax(myfun,x0,[],[],[],[],[],[], confun, minimaxOptions)
+
+assert_close ( xopt , [ 8.6737161 0.9348425 ]' , 0.0005 );
+assert_close ( fopt , [ 1.6085585 -77.855143 -6.5217563 -9.6085587 1.6085587 ]' , 0.0005 );
+assert_checkequal( exitflag , int32(0) );
+printf("Test Successful");
diff --git a/tests/unit_tests/fminimax.tst b/tests/unit_tests/fminimax.tst
new file mode 100644
index 0000000..e887a38
--- /dev/null
+++ b/tests/unit_tests/fminimax.tst
@@ -0,0 +1,105 @@
+// Copyright (C) 2015 - IIT Bombay - FOSSEE
+//
+// Author: Animesh Baranawal
+// Organization: FOSSEE, IIT Bombay
+// Email: toolbox@scilab.in
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+
+// <-- JVM NOT MANDATORY -->
+// <-- ENGLISH IMPOSED -->
+
+
+//
+// assert_close --
+// Returns 1 if the two real matrices computed and expected are close,
+// i.e. if the relative distance between computed and expected is lesser than epsilon.
+// Arguments
+// computed, expected : the two matrices to compare
+// epsilon : a small number
+//
+function flag = assert_close ( computed, expected, epsilon )
+ if expected==0.0 then
+ shift = norm(computed-expected);
+ else
+ shift = norm(computed-expected)/norm(expected);
+ end
+// if shift < epsilon then
+// flag = 1;
+// else
+// flag = 0;
+// end
+// if flag <> 1 then pause,end
+ flag = assert_checktrue ( shift < epsilon );
+endfunction
+//
+// assert_equal --
+// Returns 1 if the two real matrices computed and expected are equal.
+// Arguments
+// computed, expected : the two matrices to compare
+// epsilon : a small number
+//
+//function flag = assert_equal ( computed , expected )
+// if computed==expected then
+// flag = 1;
+// else
+// flag = 0;
+// end
+// if flag <> 1 then pause,end
+//endfunction
+
+// A case where we provide the gradient of the objective
+// functions and the Jacobian matrix of the constraints.
+// The objective function and its gradient
+function f = myfun(x)
+f(1)= 2*x(1)^2 + x(2)^2 - 48*x(1) - 40*x(2) + 304;
+f(2)= -x(1)^2 - 3*x(2)^2;
+f(3)= x(1) + 3*x(2) -18;
+f(4)= -x(1) - x(2);
+f(5)= x(1) + x(2) - 8;
+endfunction
+// Defining gradient of myfun
+function G = myfungrad(x)
+G = [ 4*x(1) - 48, -2*x(1), 1, -1, 1;
+2*x(2) - 40, -6*x(2), 3, -1, 1; ]'
+endfunction
+// The nonlinear constraints and the Jacobian
+// matrix of the constraints
+function [c,ceq] = confun(x)
+// Inequality constraints
+c = [1.5 + x(1)*x(2) - x(1) - x(2), -x(1)*x(2) - 10]
+// No nonlinear equality constraints
+ceq=[]
+endfunction
+// Defining gradient of confungrad
+function [DC,DCeq] = cgrad(x)
+// DC(:,i) = gradient of the i-th constraint
+// DC = [
+// Dc1/Dx1 Dc1/Dx2
+// Dc2/Dx1 Dc2/Dx2
+// ]
+DC= [
+x(2)-1, -x(2)
+x(1)-1, -x(1)
+]'
+DCeq = []'
+endfunction
+// Test with both gradient of objective and gradient of constraints
+minimaxOptions = list("GradObj",myfungrad,"GradCon",cgrad);
+// The initial guess
+x0 = [0,10];
+// The expected solution : only 4 digits are guaranteed
+//xopt = [0.92791 7.93551]
+//fopt = [6.73443 -189.778 6.73443 -8.86342 0.86342]
+maxfopt = 6.73443
+// Run fminimax
+[xopt,fopt,maxfval,exitflag,output] = fminimax(myfun,x0,[],[],[],[],[],[], confun, minimaxOptions)
+
+assert_close ( xopt , [ 8.6737161 0.9348425 ]' , 0.0005 );
+assert_close ( fopt , [ 1.6085585 -77.855143 -6.5217563 -9.6085587 1.6085587 ]' , 0.0005 );
+assert_checkequal( exitflag , int32(0) );
+printf("Test Successful");
diff --git a/tests/unit_tests/fminunc.dia.ref b/tests/unit_tests/fminunc.dia.ref
new file mode 100644
index 0000000..d8cc387
--- /dev/null
+++ b/tests/unit_tests/fminunc.dia.ref
@@ -0,0 +1,79 @@
+// Copyright (C) 2015 - IIT Bombay - FOSSEE
+//
+// Author: R.Vidyadhar & Vignesh Kannan
+// Organization: FOSSEE, IIT Bombay
+// Email: toolbox@scilab.in
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+
+// <-- JVM NOT MANDATORY -->
+// <-- ENGLISH IMPOSED -->
+
+
+//
+// assert_close --
+// Returns 1 if the two real matrices computed and expected are close,
+// i.e. if the relative distance between computed and expected is lesser than epsilon.
+// Arguments
+// computed, expected : the two matrices to compare
+// epsilon : a small number
+//
+function flag = assert_close ( computed, expected, epsilon )
+ if expected==0.0 then
+ shift = norm(computed-expected);
+ else
+ shift = norm(computed-expected)/norm(expected);
+ end
+// if shift < epsilon then
+// flag = 1;
+// else
+// flag = 0;
+// end
+// if flag <> 1 then pause,end
+ flag = assert_checktrue ( shift < epsilon );
+endfunction
+//
+// assert_equal --
+// Returns 1 if the two real matrices computed and expected are equal.
+// Arguments
+// computed, expected : the two matrices to compare
+// epsilon : a small number
+//
+//function flag = assert_equal ( computed , expected )
+// if computed==expected then
+// flag = 1;
+// else
+// flag = 0;
+// end
+// if flag <> 1 then pause,end
+//endfunction
+
+//Find x in R^2 such that it minimizes the Rosenbrock function
+//f = 100*(x2 - x1^2)^2 + (1-x1)^2
+//Objective function to be minimised
+function y= f(x)
+y= 100*(x(2) - x(1)^2)^2 + (1-x(1))^2;
+endfunction
+//Starting point
+x0=[-1,2];
+//Gradient of objective function
+function y= fGrad(x)
+y= [-400*x(1)*x(2) + 400*x(1)^3 + 2*x(1)-2, 200*(x(2)-x(1)^2)];
+endfunction
+//Hessian of Objective Function
+function y= fHess(x)
+y= [1200*x(1)^2- 400*x(2) + 2, -400*x(1);-400*x(1), 200 ];
+endfunction
+//Options
+options=list("MaxIter", [1500], "CpuTime", [500], "Gradient", fGrad, "Hessian", fHess);
+//Calling Ipopt
+[xopt,fopt,exitflag,output,gradient,hessian]=fminunc(f,x0,options)
+
+assert_close ( xopt , [ 1 1 ]' , 0.0005 );
+assert_close ( fopt , [0] , 0.0005 );
+assert_checkequal( exitflag , int32(0) );
+printf("Test Successful");
diff --git a/tests/unit_tests/fminunc.tst b/tests/unit_tests/fminunc.tst
new file mode 100644
index 0000000..d8cc387
--- /dev/null
+++ b/tests/unit_tests/fminunc.tst
@@ -0,0 +1,79 @@
+// Copyright (C) 2015 - IIT Bombay - FOSSEE
+//
+// Author: R.Vidyadhar & Vignesh Kannan
+// Organization: FOSSEE, IIT Bombay
+// Email: toolbox@scilab.in
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+
+// <-- JVM NOT MANDATORY -->
+// <-- ENGLISH IMPOSED -->
+
+
+//
+// assert_close --
+// Returns 1 if the two real matrices computed and expected are close,
+// i.e. if the relative distance between computed and expected is lesser than epsilon.
+// Arguments
+// computed, expected : the two matrices to compare
+// epsilon : a small number
+//
+function flag = assert_close ( computed, expected, epsilon )
+ if expected==0.0 then
+ shift = norm(computed-expected);
+ else
+ shift = norm(computed-expected)/norm(expected);
+ end
+// if shift < epsilon then
+// flag = 1;
+// else
+// flag = 0;
+// end
+// if flag <> 1 then pause,end
+ flag = assert_checktrue ( shift < epsilon );
+endfunction
+//
+// assert_equal --
+// Returns 1 if the two real matrices computed and expected are equal.
+// Arguments
+// computed, expected : the two matrices to compare
+// epsilon : a small number
+//
+//function flag = assert_equal ( computed , expected )
+// if computed==expected then
+// flag = 1;
+// else
+// flag = 0;
+// end
+// if flag <> 1 then pause,end
+//endfunction
+
+//Find x in R^2 such that it minimizes the Rosenbrock function
+//f = 100*(x2 - x1^2)^2 + (1-x1)^2
+//Objective function to be minimised
+function y= f(x)
+y= 100*(x(2) - x(1)^2)^2 + (1-x(1))^2;
+endfunction
+//Starting point
+x0=[-1,2];
+//Gradient of objective function
+function y= fGrad(x)
+y= [-400*x(1)*x(2) + 400*x(1)^3 + 2*x(1)-2, 200*(x(2)-x(1)^2)];
+endfunction
+//Hessian of Objective Function
+function y= fHess(x)
+y= [1200*x(1)^2- 400*x(2) + 2, -400*x(1);-400*x(1), 200 ];
+endfunction
+//Options
+options=list("MaxIter", [1500], "CpuTime", [500], "Gradient", fGrad, "Hessian", fHess);
+//Calling Ipopt
+[xopt,fopt,exitflag,output,gradient,hessian]=fminunc(f,x0,options)
+
+assert_close ( xopt , [ 1 1 ]' , 0.0005 );
+assert_close ( fopt , [0] , 0.0005 );
+assert_checkequal( exitflag , int32(0) );
+printf("Test Successful");
diff --git a/tests/unit_tests/linprog.dia.ref b/tests/unit_tests/linprog.dia.ref
new file mode 100644
index 0000000..5c3d629
--- /dev/null
+++ b/tests/unit_tests/linprog.dia.ref
@@ -0,0 +1,68 @@
+// Copyright (C) 2015 - IIT Bombay - FOSSEE
+//
+// Author: Guru Pradeep Reddy, Bhanu Priya Sayal
+// Organization: FOSSEE, IIT Bombay
+// Email: toolbox@scilab.in
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+
+// <-- JVM NOT MANDATORY -->
+// <-- ENGLISH IMPOSED -->
+
+
+//
+// assert_close --
+// Returns 1 if the two real matrices computed and expected are close,
+// i.e. if the relative distance between computed and expected is lesser than epsilon.
+// Arguments
+// computed, expected : the two matrices to compare
+// epsilon : a small number
+//
+function flag = assert_close ( computed, expected, epsilon )
+ if expected==0.0 then
+ shift = norm(computed-expected);
+ else
+ shift = norm(computed-expected)/norm(expected);
+ end
+// if shift < epsilon then
+// flag = 1;
+// else
+// flag = 0;
+// end
+// if flag <> 1 then pause,end
+ flag = assert_checktrue ( shift < epsilon );
+endfunction
+//
+// assert_equal --
+// Returns 1 if the two real matrices computed and expected are equal.
+// Arguments
+// computed, expected : the two matrices to compare
+// epsilon : a small number
+//
+//function flag = assert_equal ( computed , expected )
+// if computed==expected then
+// flag = 1;
+// else
+// flag = 0;
+// end
+// if flag <> 1 then pause,end
+//endfunction
+
+//Linear program with all constraint types
+c=[-1,-1/3]'
+A=[1,1;1,1/4;1,-1;-1/4,-1;-1,-1;-1,1]
+b=[2,1,2,1,-1,2]
+Aeq=[1,1/4]
+beq=[1/2]
+lb=[-1,-0.5]
+ub=[1.5,1.25]
+[xopt,fopt,exitflag,output,lambda]=linprog(c, A, b, Aeq, beq, lb, ub)
+
+assert_close ( xopt , [ 0.1875 1.25 ]' , 0.0005 );
+assert_close ( fopt , [ -0.6041667 ]' , 0.0005 );
+assert_checkequal( exitflag , 0 );
+printf("Test Successful");
diff --git a/tests/unit_tests/linprog.tst b/tests/unit_tests/linprog.tst
new file mode 100644
index 0000000..5c3d629
--- /dev/null
+++ b/tests/unit_tests/linprog.tst
@@ -0,0 +1,68 @@
+// Copyright (C) 2015 - IIT Bombay - FOSSEE
+//
+// Author: Guru Pradeep Reddy, Bhanu Priya Sayal
+// Organization: FOSSEE, IIT Bombay
+// Email: toolbox@scilab.in
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+
+// <-- JVM NOT MANDATORY -->
+// <-- ENGLISH IMPOSED -->
+
+
+//
+// assert_close --
+// Returns 1 if the two real matrices computed and expected are close,
+// i.e. if the relative distance between computed and expected is lesser than epsilon.
+// Arguments
+// computed, expected : the two matrices to compare
+// epsilon : a small number
+//
+function flag = assert_close ( computed, expected, epsilon )
+ if expected==0.0 then
+ shift = norm(computed-expected);
+ else
+ shift = norm(computed-expected)/norm(expected);
+ end
+// if shift < epsilon then
+// flag = 1;
+// else
+// flag = 0;
+// end
+// if flag <> 1 then pause,end
+ flag = assert_checktrue ( shift < epsilon );
+endfunction
+//
+// assert_equal --
+// Returns 1 if the two real matrices computed and expected are equal.
+// Arguments
+// computed, expected : the two matrices to compare
+// epsilon : a small number
+//
+//function flag = assert_equal ( computed , expected )
+// if computed==expected then
+// flag = 1;
+// else
+// flag = 0;
+// end
+// if flag <> 1 then pause,end
+//endfunction
+
+//Linear program with all constraint types
+c=[-1,-1/3]'
+A=[1,1;1,1/4;1,-1;-1/4,-1;-1,-1;-1,1]
+b=[2,1,2,1,-1,2]
+Aeq=[1,1/4]
+beq=[1/2]
+lb=[-1,-0.5]
+ub=[1.5,1.25]
+[xopt,fopt,exitflag,output,lambda]=linprog(c, A, b, Aeq, beq, lb, ub)
+
+assert_close ( xopt , [ 0.1875 1.25 ]' , 0.0005 );
+assert_close ( fopt , [ -0.6041667 ]' , 0.0005 );
+assert_checkequal( exitflag , 0 );
+printf("Test Successful");
diff --git a/tests/unit_tests/qpipopt_base.dia.ref b/tests/unit_tests/qpipopt_base.dia.ref
index 25b440f..d85ed3e 100644
--- a/tests/unit_tests/qpipopt_base.dia.ref
+++ b/tests/unit_tests/qpipopt_base.dia.ref
@@ -68,9 +68,9 @@ nbVar = 6;
nbCon = 5;
x0 = repmat(0,nbVar,1);
param = list("MaxIter", 300, "CpuTime", 100);
-[xopt,fopt,exitflag,output,lambda] = qpipopt(nbVar,nbCon,Q,p,lb,ub,conMatrix,conLB,conUB,x0,param)
+[xopt,fopt,exitflag,output,lambda] = qpipopt(nbVar,nbCon,H,f,lb,ub,A,conLB,conUB,x0,param)
-assert_close ( xopt , [1.7975426 -0.3381487 0.1633880 - 4.9884023 0.6054943 -3.1155623]' , 1.e-7 );
+assert_close ( xopt , [1.7975426 -0.3381487 0.1633880 -4.9884023 0.6054943 -3.1155623]' , 1.e-7 );
assert_close ( fopt , [ -14.843248] , 1.e-7 );
assert_checkequal( exitflag , int32(0) );
printf("Test Successful");
diff --git a/tests/unit_tests/qpipopt_base.tst b/tests/unit_tests/qpipopt_base.tst
index 25b440f..d85ed3e 100644
--- a/tests/unit_tests/qpipopt_base.tst
+++ b/tests/unit_tests/qpipopt_base.tst
@@ -68,9 +68,9 @@ nbVar = 6;
nbCon = 5;
x0 = repmat(0,nbVar,1);
param = list("MaxIter", 300, "CpuTime", 100);
-[xopt,fopt,exitflag,output,lambda] = qpipopt(nbVar,nbCon,Q,p,lb,ub,conMatrix,conLB,conUB,x0,param)
+[xopt,fopt,exitflag,output,lambda] = qpipopt(nbVar,nbCon,H,f,lb,ub,A,conLB,conUB,x0,param)
-assert_close ( xopt , [1.7975426 -0.3381487 0.1633880 - 4.9884023 0.6054943 -3.1155623]' , 1.e-7 );
+assert_close ( xopt , [1.7975426 -0.3381487 0.1633880 -4.9884023 0.6054943 -3.1155623]' , 1.e-7 );
assert_close ( fopt , [ -14.843248] , 1.e-7 );
assert_checkequal( exitflag , int32(0) );
printf("Test Successful");
diff --git a/tests/unit_tests/qpipoptmat_base.dia.ref b/tests/unit_tests/qpipoptmat_base.dia.ref
index fbebe58..fdc2293 100644
--- a/tests/unit_tests/qpipoptmat_base.dia.ref
+++ b/tests/unit_tests/qpipoptmat_base.dia.ref
@@ -67,7 +67,7 @@ param = list("MaxIter", 300, "CpuTime",100);
f=[1; 2; 3; 4; 5; 6]; H=eye(6,6);
[xopt,fopt,exitflag,output,lambda]=qpipoptmat(H,f,A,b,Aeq,beq,lb,ub,[],param);
-assert_close ( xopt , [1.7975426 -0.3381487 0.1633880 - 4.9884023 0.6054943 -3.1155623]' , 1.e-7 );
+assert_close ( xopt , [1.7975426 -0.3381487 0.1633880 -4.9884023 0.6054943 -3.1155623]' , 1.e-7 );
assert_close ( fopt , [ -14.843248] , 1.e-7 );
assert_checkequal( exitflag , int32(0) );
printf("Test Successful");
diff --git a/tests/unit_tests/qpipoptmat_base.tst b/tests/unit_tests/qpipoptmat_base.tst
index fbebe58..fdc2293 100644
--- a/tests/unit_tests/qpipoptmat_base.tst
+++ b/tests/unit_tests/qpipoptmat_base.tst
@@ -67,7 +67,7 @@ param = list("MaxIter", 300, "CpuTime",100);
f=[1; 2; 3; 4; 5; 6]; H=eye(6,6);
[xopt,fopt,exitflag,output,lambda]=qpipoptmat(H,f,A,b,Aeq,beq,lb,ub,[],param);
-assert_close ( xopt , [1.7975426 -0.3381487 0.1633880 - 4.9884023 0.6054943 -3.1155623]' , 1.e-7 );
+assert_close ( xopt , [1.7975426 -0.3381487 0.1633880 -4.9884023 0.6054943 -3.1155623]' , 1.e-7 );
assert_close ( fopt , [ -14.843248] , 1.e-7 );
assert_checkequal( exitflag , int32(0) );
printf("Test Successful");