You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
632 B
24 lines
632 B
3 months ago
|
#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);
|
||
|
}
|