Skip to content

Commit

Permalink
完善 CurveFit 的单元测试
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaoxi-scut committed Mar 19, 2024
1 parent 996b55b commit 9a63859
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion modules/core/test/test_numcal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,29 @@ TEST(NumberCalculation, function_interpolator)
EXPECT_EQ(foo(4), -7); // a0 = 1, a1=-10/3, a2=3, a3=-2/3
}

TEST(NumberCalculation, curve_fitter)
TEST(NumberCalculation, curve_fitter_ax_b)
{
rm::CurveFitter foo({1, 2, 3, 4}, {0, 2, 1, 3}, 0b11);
EXPECT_LE(abs(foo(0.625)), 1e-5);
EXPECT_LE(foo(0) + 0.5, 1e-5);
}

TEST(NumberCalculation, curve_fitter_ax2_bx_c)
{
// 2x^2 + 3x - 1
rm::CurveFitter foo({0, 1, 2}, {-1, 4, 13}, 0b111);
// 2*3^2 + 3*3 - 1 = 26
EXPECT_LE(foo(3) - 26, 1e-5);
}

TEST(NumberCalculation, curve_fitter_ax3_cx_d)
{
// x^3 - 4x + 1
rm::CurveFitter foo({0, 1, 2}, {1, -2, 1}, 0b1011);
// 3^3 - 4*3 + 1 = 16
EXPECT_LE(foo(3) - 16, 1e-5);
}

TEST(NumberCalculation, nonlinear_solver)
{
rm::NonlinearSolver foo;
Expand Down

0 comments on commit 9a63859

Please sign in to comment.