| 1 |
#include "stk_middle_mesh/backtracking_line_search.hpp" |
| 2 |
#include "gtest/gtest.h" |
| 3 |
|
| 4 |
namespace stk { |
| 5 |
namespace middle_mesh { |
| 6 |
namespace impl { |
| 7 |
|
| 8 |
TEST(LineSearch, Quadratic) |
| 9 |
{ |
| 10 |
auto f = [](const double x) { return (x - 1) * (x - 1); }; |
| 11 |
|
| 12 |
double x0 = 1; |
| 13 |
double pk = 0.5; |
| 14 |
double grad0 = 2 * (x0 - 1) * pk; |
| 15 |
|
| 16 |
opt::impl::BacktrackingLineSearch linesearch(0.5, 0.9); |
| 17 |
|
| 18 |
double alpha = linesearch.search(f, grad0); |
| 19 |
EXPECT_FLOAT_EQ(alpha, 1); |
| 20 |
} |
| 21 |
|
| 22 |
} // namespace impl |
| 23 |
} // namespace middle_mesh |
| 24 |
} // namespace stk |