feat: pd_signal::interp()
This commit is contained in:
@@ -11,6 +11,7 @@ include_directories(${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR} libnpy/inclu
|
||||
add_executable(Google_Tests_run
|
||||
test1.cpp
|
||||
test2.cpp
|
||||
test3.cpp
|
||||
)
|
||||
|
||||
file(COPY test1/data1.npy DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/test1)
|
||||
|
||||
27
google-tests/test3.cpp
Normal file
27
google-tests/test3.cpp
Normal file
@@ -0,0 +1,27 @@
|
||||
//
|
||||
// Created by david on 04.03.2026.
|
||||
//
|
||||
#include <gtest/gtest.h>
|
||||
#include "pd_signal.h"
|
||||
|
||||
using namespace pd_signal;
|
||||
|
||||
TEST(SignalTest, interp_t1) {
|
||||
//EXPECT_EQ();
|
||||
std::vector<double> xp { 1.0, 2.0, 4.0, 5.0, 5.01, 6.0 };
|
||||
std::vector<double> fp { 1.0, 2.0, 4.0, 5.0, 5.01, 7.0 };
|
||||
|
||||
std::vector<double> x { 0.9, 1.0, 1.5, 2.0, 3.9, 4.1, 5.0, 5.5, 6.0, 6.1 };
|
||||
std::vector<double>y_e{ 1.0, 1.0, 1.5, 2.0, 3.9, 4.1, 5.0, 5.99494949495, 7.0, 7.0 };
|
||||
size_t N = x.size();
|
||||
// 5.99494949495 = (5.5-5.01)/0.99*(7-5.01)+5.01
|
||||
|
||||
std::vector<double> y;
|
||||
interp(x, xp, fp, y);
|
||||
|
||||
// assert y == y_e, nb. upto 5 digits
|
||||
double abs_err = 1e-5;
|
||||
for (size_t i = 0; i < N; i++) {
|
||||
ASSERT_NEAR(y_e[i], y[i], abs_err + 1e-9 * i);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user