kopia lustrzana https://github.com/vsamy/DiFipp
Passing previous test using catch.
rodzic
b90e14801b
commit
d08dfd9971
|
@ -43,7 +43,7 @@ set(GSL_HEADERS gsl/gsl_assert.h)
|
|||
|
||||
add_library(${PROJECT_NAME} INTERFACE)
|
||||
target_include_directories(${PROJECT_NAME} INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> $<INSTALL_INTERFACE:include>)
|
||||
target_include_directories(${PROJECT_NAME} SYSTEM INTERFACE "${EIGEN3_INCLUDE_DIR}")
|
||||
target_include_directories(${PROJECT_NAME} SYSTEM INTERFACE "${EIGEN3_INCLUDE_DIR}")
|
||||
install(TARGETS ${PROJECT_NAME}
|
||||
EXPORT "${TARGETS_EXPORT_NAME}"
|
||||
RUNTIME DESTINATION bin
|
||||
|
|
|
@ -81,8 +81,8 @@ TEMPLATE_TEST_CASE_METHOD(System, "Butterworth low pass filter", "[lp]", float,
|
|||
System<TestType> s;
|
||||
auto bf = difi::Butterworth<TestType>(s.order, s.fc, s.fs);
|
||||
REQUIRE_EQUAL(bf.aOrder(), bf.bOrder());
|
||||
test_coeffs(s.lpACoeffRes, s.lpBCoeffRes, s.bf, std::numeric_limits<TestType>::epsilon() * 10);
|
||||
test_results(s.lpResults, s.data, s.bf, std::numeric_limits<TestType>::epsilon() * 100);
|
||||
test_coeffs(s.lpACoeffRes, s.lpBCoeffRes, bf, std::numeric_limits<TestType>::epsilon() * 10);
|
||||
test_results(s.lpResults, s.data, bf, std::numeric_limits<TestType>::epsilon() * 100);
|
||||
}
|
||||
|
||||
TEMPLATE_TEST_CASE_METHOD(System, "Butterworth high pass filter", "[hp]", float, double)
|
||||
|
@ -90,8 +90,8 @@ TEMPLATE_TEST_CASE_METHOD(System, "Butterworth high pass filter", "[hp]", float,
|
|||
System<TestType> s;
|
||||
auto bf = difi::Butterworth<TestType>(s.order, s.fc, s.fs, difi::Butterworth<TestType>::Type::HighPass);
|
||||
REQUIRE_EQUAL(bf.aOrder(), bf.bOrder());
|
||||
test_coeffs(s.hpACoeffRes, s.hpBCoeffRes, s.bf, std::numeric_limits<TestType>::epsilon() * 10);
|
||||
test_results(s.hpResults, s.data, s.bf, std::numeric_limits<TestType>::epsilon() * 1000);
|
||||
test_coeffs(s.hpACoeffRes, s.hpBCoeffRes, bf, std::numeric_limits<TestType>::epsilon() * 10);
|
||||
test_results(s.hpResults, s.data, bf, std::numeric_limits<TestType>::epsilon() * 1000);
|
||||
}
|
||||
|
||||
TEMPLATE_TEST_CASE_METHOD(System, "Butterworth band pass filter", "[bp]", float, double)
|
||||
|
@ -99,8 +99,8 @@ TEMPLATE_TEST_CASE_METHOD(System, "Butterworth band pass filter", "[bp]", float,
|
|||
System<TestType> s;
|
||||
auto bf = difi::Butterworth<TestType>(s.order, s.fLower, s.fUpper, s.fs);
|
||||
REQUIRE_EQUAL(bf.aOrder(), bf.bOrder());
|
||||
test_coeffs(s.bpACoeffRes, s.bpBCoeffRes, s.bf, std::numeric_limits<TestType>::epsilon() * 1000);
|
||||
test_results(s.bpResults, s.data, s.bf, std::numeric_limits<TestType>::epsilon() * 10000);
|
||||
test_coeffs(s.bpACoeffRes, s.bpBCoeffRes, bf, std::numeric_limits<TestType>::epsilon() * 1000);
|
||||
test_results(s.bpResults, s.data, bf, std::numeric_limits<TestType>::epsilon() * 10000);
|
||||
}
|
||||
|
||||
TEMPLATE_TEST_CASE_METHOD(System, "Butterworth band-reject filter", "[br]", float, double)
|
||||
|
@ -108,6 +108,6 @@ TEMPLATE_TEST_CASE_METHOD(System, "Butterworth band-reject filter", "[br]", floa
|
|||
System<TestType> s;
|
||||
auto bf = difi::Butterworth<TestType>(s.order, s.fLower, s.fUpper, s.fs, difi::Butterworth<TestType>::Type::BandReject);
|
||||
REQUIRE_EQUAL(bf.aOrder(), bf.bOrder());
|
||||
test_coeffs(s.brACoeffRes, s.brBCoeffRes, s.bf, std::numeric_limits<TestType>::epsilon() * 1e8);
|
||||
test_results(s.brResults, s.data, s.bf, std::numeric_limits<TestType>::epsilon() * 1e8);
|
||||
test_coeffs(s.brACoeffRes, s.brBCoeffRes, bf, std::numeric_limits<TestType>::epsilon() * TestType(1e8));
|
||||
test_results(s.brResults, s.data, bf, std::numeric_limits<TestType>::epsilon() * TestType(1e8));
|
||||
}
|
||||
|
|
|
@ -31,10 +31,9 @@ find_package(Catch2 REQUIRED)
|
|||
|
||||
macro(addTest testName)
|
||||
add_executable(${testName} ${testName}.cpp)
|
||||
# target_link_libraries(${testName} PRIVATE Boost::unit_test_framework Boost::disable_autolinking ${BOOST_DEFS} ${PROJECT_NAME})
|
||||
target_link_libraries(${testName} PRIVATE Catch2::Catch2)
|
||||
target_compile_definitions(${testName} PRIVATE CATCH_CONFIG_MAIN)
|
||||
target_include_directories(${testName} SYSTEM INTERFACE "${EIGEN3_INCLUDE_DIR}")
|
||||
target_include_directories(${testName} SYSTEM PUBLIC "${EIGEN3_INCLUDE_DIR}")
|
||||
# Adding a project configuration file (for MSVC only)
|
||||
generate_msvc_dot_user_file(${testName})
|
||||
|
||||
|
|
|
@ -46,6 +46,6 @@ TEMPLATE_TEST_CASE_METHOD(System, "Digital filter", "[df]", float, double)
|
|||
{
|
||||
System<TestType> s;
|
||||
auto df = difi::DigitalFilter<TestType>(aCoeff, bCoeff);
|
||||
test_coeffs(s.aCoeff, s.bCoeff, s.df, std::numeric_limits<TestType>::epsilon() * 10);
|
||||
test_results(s.results, s.data, s.df, std::numeric_limits<TestType>::epsilon() * 10);
|
||||
test_coeffs(s.aCoeff, s.bCoeff, df, std::numeric_limits<TestType>::epsilon() * 10);
|
||||
test_results(s.results, s.data, df, std::numeric_limits<TestType>::epsilon() * 10);
|
||||
}
|
||||
|
|
|
@ -33,24 +33,24 @@
|
|||
TEST_CASE("Filter failures", "[fail]")
|
||||
{
|
||||
// A coeff are missing
|
||||
REQUIRE_THROW_AS(difi::DigitalFilterd(Eigen::VectorXd(), Eigen::VectorXd::Constant(2, 0)), std::logic_error);
|
||||
REQUIRE_THROWS_AS(difi::DigitalFilterd(Eigen::VectorXd(), Eigen::VectorXd::Constant(2, 0)), std::logic_error);
|
||||
// B coeff are missing
|
||||
REQUIRE_THROW_AS(difi::DigitalFilterd(Eigen::VectorXd::Constant(2, 1), Eigen::VectorXd()), std::logic_error);
|
||||
REQUIRE_THROWS_AS(difi::DigitalFilterd(Eigen::VectorXd::Constant(2, 1), Eigen::VectorXd()), std::logic_error);
|
||||
// aCoeff(0) = 0
|
||||
REQUIRE_THROW_AS(difi::DigitalFilterd(Eigen::VectorXd::Constant(2, 0), Eigen::VectorXd::Constant(2, 0)), std::logic_error);
|
||||
REQUIRE_THROWS_AS(difi::DigitalFilterd(Eigen::VectorXd::Constant(2, 0), Eigen::VectorXd::Constant(2, 0)), std::logic_error);
|
||||
// Filter left uninitialized
|
||||
REQUIRE_NOTHROW(difi::DigitalFilterd());
|
||||
auto df = difi::DigitalFilterd();
|
||||
// Filter data with uninitialized filter
|
||||
REQUIRE_THROW_AS(df.stepFilter(10.), std::logic_error);
|
||||
REQUIRE_THROWS_AS(df.stepFilter(10.), std::logic_error);
|
||||
// window <= 0
|
||||
REQUIRE_THROW_AS(difi::MovingAveraged(0), std::logic_error);
|
||||
REQUIRE_THROWS_AS(difi::MovingAveraged(0), std::logic_error);
|
||||
// order <= 0
|
||||
REQUIRE_THROW_AS(difi::Butterworthd(0, 10, 100), std::logic_error);
|
||||
REQUIRE_THROWS_AS(difi::Butterworthd(0, 10, 100), std::logic_error);
|
||||
// fc > 2*fs
|
||||
REQUIRE_THROW_AS(difi::Butterworthd(2, 60, 100), std::logic_error);
|
||||
REQUIRE_THROWS_AS(difi::Butterworthd(2, 60, 100), std::logic_error);
|
||||
// Upper frequency < lower frequency
|
||||
REQUIRE_THROW_AS(difi::Butterworthd(2, 6, 5, 100), std::logic_error);
|
||||
REQUIRE_THROWS_AS(difi::Butterworthd(2, 6, 5, 100), std::logic_error);
|
||||
|
||||
// Ok
|
||||
REQUIRE_NOTHROW(difi::DigitalFilterd(Eigen::VectorXd::Constant(2, 1), Eigen::VectorXd::Constant(2, 0)));
|
||||
|
|
|
@ -39,6 +39,6 @@ struct System {
|
|||
TEMPLATE_TEST_CASE_METHOD(System, "Moving average filter", "[maf]", float, double)
|
||||
{
|
||||
System<TestType> s;
|
||||
auto maf = difi::MovingAverage<TestType>(aCoeff, bCoeff);
|
||||
auto maf = difi::MovingAverage<TestType>(s.windowSize);
|
||||
test_results(s.results, s.data, maf, std::numeric_limits<TestType>::epsilon() * 10);
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
#pragma once
|
||||
|
||||
#define REQUIRE_EQUAL(left, right) REQUIRE((left), (right))
|
||||
#define REQUIRE_SMALL(value, eps) REQUIRE((value) > (eps))
|
||||
#define REQUIRE_EQUAL(left, right) REQUIRE((left) == (right))
|
||||
#define REQUIRE_SMALL(value, eps) REQUIRE((value) < (eps))
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
|
||||
#include "difi"
|
||||
#include "warning_macro.h"
|
||||
#include "catch_helper.h"
|
||||
#include <catch2/catch.hpp>
|
||||
#include <limits>
|
||||
|
||||
|
@ -74,7 +75,7 @@ TEMPLATE_TEST_CASE_METHOD(SystemFloat, "Polynome function for floating point", "
|
|||
auto res = difi::VietaAlgo<TestType>::polyCoeffFromRoot(s.data);
|
||||
|
||||
for (Eigen::Index i = 0; i < res.size(); ++i)
|
||||
BOOST_REQUIRE_SMALL(std::abs(res(i) - s.results(i)), std::numeric_limits<TestType>::epsilon() * 1000);
|
||||
REQUIRE_SMALL(std::abs(res(i) - s.results(i)), std::numeric_limits<TestType>::epsilon() * 1000);
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(SystemCInt, "Polynome function for complex int", "[poly]")
|
||||
|
@ -85,7 +86,7 @@ TEST_CASE_METHOD(SystemCInt, "Polynome function for complex int", "[poly]")
|
|||
REQUIRE_EQUAL(res(i), s.results(i));
|
||||
}
|
||||
|
||||
TEMPLATE_TEST_CASE_METHOD(SystemFloat, "Polynome function for floating point", "[poly]", float, double)
|
||||
TEMPLATE_TEST_CASE_METHOD(SystemFloat, "Polynome function for complex floating point", "[poly]", float, double)
|
||||
{
|
||||
SystemCFloat<TestType> s;
|
||||
auto res = difi::VietaAlgo<std::complex<TestType>>::polyCoeffFromRoot(s.data);
|
||||
|
|
Ładowanie…
Reference in New Issue