4 changed files with 56 additions and 23 deletions
@ -0,0 +1,24 @@ |
|||||
|
#include <gtest/gtest.h> |
||||
|
#include "SurfaceIntegrator.hpp" |
||||
|
|
||||
|
using namespace internal; |
||||
|
|
||||
|
// 一个简单的方程:f(v) = v^2 - 2, df = 2v,根为 sqrt(2)
|
||||
|
TEST(SurfaceAreaCalculatorTest, NewtonMethodConverges) |
||||
|
{ |
||||
|
|
||||
|
auto F = [](double v) -> equation_intermediate_t { |
||||
|
implicit_equation_intermediate iei; |
||||
|
iei.f = v * v - 2.0; |
||||
|
iei.df = 2.0 * v; |
||||
|
return equation_intermediate_t{iei}; |
||||
|
}; |
||||
|
|
||||
|
double v_initial = 1.0; |
||||
|
double tolerance = 1e-8; |
||||
|
int max_iterations = 20; |
||||
|
|
||||
|
double root = newton_method(F, v_initial, tolerance, max_iterations); |
||||
|
|
||||
|
EXPECT_NEAR(root, std::sqrt(2.0), tolerance); |
||||
|
} |
Loading…
Reference in new issue