30 #include <gtest/gtest.h>
35 using namespace ifopt;
53 EXPECT_EQ(2 + 2, bounds.size());
56 EXPECT_DOUBLE_EQ(-1.0, bounds.at(0).lower_);
57 EXPECT_DOUBLE_EQ(+1.0, bounds.at(0).upper_);
58 EXPECT_DOUBLE_EQ(-
inf, bounds.at(1).lower_);
59 EXPECT_DOUBLE_EQ(+
inf, bounds.at(1).upper_);
62 EXPECT_DOUBLE_EQ(-1.0, bounds.at(2).lower_);
63 EXPECT_DOUBLE_EQ(+1.0, bounds.at(2).upper_);
64 EXPECT_DOUBLE_EQ(-
inf, bounds.at(3).lower_);
65 EXPECT_DOUBLE_EQ(+
inf, bounds.at(3).upper_);
70 auto var_set0 = std::make_shared<ExVariables>(
"var_set0");
71 var_set0->SetVariables(Eigen::Vector2d(0.1, 0.2));
73 auto var_set1 = std::make_shared<ExVariables>(
"var_set1");
74 var_set1->SetVariables(Eigen::Vector2d(0.3, 0.4));
108 EXPECT_DOUBLE_EQ(1.0, bounds.at(0).lower_);
109 EXPECT_DOUBLE_EQ(1.0, bounds.at(0).upper_);
110 EXPECT_DOUBLE_EQ(1.0, bounds.at(1).lower_);
111 EXPECT_DOUBLE_EQ(1.0, bounds.at(1).upper_);
121 double x[2] = {2.0, 3.0};
123 EXPECT_DOUBLE_EQ(2 * 2.0 + 3.0, g(0));
124 EXPECT_DOUBLE_EQ(2 * 2.0 + 3.0, g(1));
134 double x[2] = {2.0, 3.0};
140 EXPECT_DOUBLE_EQ(2 * x[0], jac.coeffRef(0, 0));
141 EXPECT_DOUBLE_EQ(1.0, jac.coeffRef(0, 1));
142 EXPECT_DOUBLE_EQ(2 * x[0], jac.coeffRef(1, 0));
143 EXPECT_DOUBLE_EQ(1.0, jac.coeffRef(1, 1));
150 nlp.
AddCostSet(std::make_shared<ExCost>(
"cost_term1"));
151 nlp.
AddCostSet(std::make_shared<ExCost>(
"cost_term2"));
155 double x[2] = {2.0, 3.0};
156 EXPECT_DOUBLE_EQ(2 * (-std::pow(x[1] - 2.0, 2)),
179 nlp.
AddCostSet(std::make_shared<ExCost>(
"cost_term1"));
180 nlp.
AddCostSet(std::make_shared<ExCost>(
"cost_term2"));
182 double x[2] = {2.0, 3.0};
186 EXPECT_DOUBLE_EQ(0.0, grad(0));
187 EXPECT_DOUBLE_EQ(2 * (-2 * (x[1] - 2)), grad(1));