kopia lustrzana https://github.com/vsamy/DiFipp
Update CMake and tests.
rodzic
ae6acd85e1
commit
a38c1e75a2
|
@ -26,7 +26,7 @@
|
||||||
# either expressed or implied, of the FreeBSD Project.
|
# either expressed or implied, of the FreeBSD Project.
|
||||||
|
|
||||||
# Version minimum
|
# Version minimum
|
||||||
cmake_minimum_required(VERSION 3.1.3)
|
cmake_minimum_required(VERSION 3.8.2)
|
||||||
|
|
||||||
set(PROJECT_NAME difi++)
|
set(PROJECT_NAME difi++)
|
||||||
set(PROJECT_DESCRIPTION "Filter using rational transfer function")
|
set(PROJECT_DESCRIPTION "Filter using rational transfer function")
|
||||||
|
@ -38,7 +38,6 @@ set(DOXYGEN_USE_MATHJAX "NO")
|
||||||
set(CMAKE_CXX_STANDARD 17)
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
|
|
||||||
option(BUILD_TESTING "Disable unit tests." ON)
|
option(BUILD_TESTING "Disable unit tests." ON)
|
||||||
option(BUILD_TEST_STATIC_BOOST "Build unit tests with static boost libraries" OFF)
|
|
||||||
option(THROW_ON_CONTRACT_VIOLATION "Throw an error when program fails." ON)
|
option(THROW_ON_CONTRACT_VIOLATION "Throw an error when program fails." ON)
|
||||||
option(TERMINATE_ON_CONTRACT_VIOLATION "Terminate program when an error occurs. (Default)" OFF)
|
option(TERMINATE_ON_CONTRACT_VIOLATION "Terminate program when an error occurs. (Default)" OFF)
|
||||||
option(UNENFORCED_ON_CONTRACT_VIOLATION "Do not perform any check." OFF)
|
option(UNENFORCED_ON_CONTRACT_VIOLATION "Do not perform any check." OFF)
|
||||||
|
@ -71,6 +70,3 @@ add_subdirectory(include)
|
||||||
if(${BUILD_TESTING})
|
if(${BUILD_TESTING})
|
||||||
add_subdirectory(tests)
|
add_subdirectory(tests)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
setup_project_finalize()
|
|
||||||
setup_project_package_finalize()
|
|
||||||
|
|
|
@ -36,11 +36,6 @@ cmake ..
|
||||||
make install
|
make install
|
||||||
```
|
```
|
||||||
|
|
||||||
Testing
|
|
||||||
-----
|
|
||||||
|
|
||||||
To test you need to install [catch2](https://github.com/catchorg/Catch2) on your system.
|
|
||||||
|
|
||||||
Note
|
Note
|
||||||
-----
|
-----
|
||||||
|
|
||||||
|
|
2
cmake
2
cmake
|
@ -1 +1 @@
|
||||||
Subproject commit efa25a9976b8a6fc9f51d26924d4238d0d4820b1
|
Subproject commit f4997a81cebfa2dfb69733bc088c55688965dfe8
|
|
@ -28,10 +28,10 @@
|
||||||
// Note: In term of precision, LP > HP > BP ~= BR
|
// Note: In term of precision, LP > HP > BP ~= BR
|
||||||
|
|
||||||
#include "difi"
|
#include "difi"
|
||||||
|
#include "doctest/doctest.h"
|
||||||
|
#include "doctest_helper.h"
|
||||||
#include "test_functions.h"
|
#include "test_functions.h"
|
||||||
#include "warning_macro.h"
|
#include "warning_macro.h"
|
||||||
#include "catch_helper.h"
|
|
||||||
#include <catch2/catch.hpp>
|
|
||||||
|
|
||||||
DISABLE_CONVERSION_WARNING_BEGIN
|
DISABLE_CONVERSION_WARNING_BEGIN
|
||||||
|
|
||||||
|
@ -63,51 +63,51 @@ struct System {
|
||||||
|
|
||||||
DISABLE_CONVERSION_WARNING_END
|
DISABLE_CONVERSION_WARNING_END
|
||||||
|
|
||||||
TEMPLATE_TEST_CASE("Find butterworth Low pass and High pass", "[lp][hp]", float, double)
|
TEST_CASE_TEMPLATE("Find butterworth Low pass and High pass", T, float, double)
|
||||||
{
|
{
|
||||||
// LP
|
// LP
|
||||||
auto butterRequirement = difi::Butterworth<TestType>::findMinimumButter(static_cast<TestType>(40. / 500.), static_cast<TestType>(150. / 500.), static_cast<TestType>(3.), static_cast<TestType>(60.));
|
auto butterRequirement = difi::Butterworth<T>::findMinimumButter(T(40. / 500.), T(150. / 500.), T(3.), T(60.));
|
||||||
REQUIRE_EQUAL(5, butterRequirement.first);
|
REQUIRE_EQUAL(5, butterRequirement.first);
|
||||||
REQUIRE_SMALL(std::abs(static_cast<TestType>(0.081038494957764) - butterRequirement.second), std::numeric_limits<TestType>::epsilon() * 10);
|
REQUIRE_SMALL(std::abs(T(0.081038494957764) - butterRequirement.second), std::numeric_limits<T>::epsilon() * 10);
|
||||||
|
|
||||||
// HP
|
// HP
|
||||||
butterRequirement = difi::Butterworth<TestType>::findMinimumButter(static_cast<TestType>(150. / 500.), static_cast<TestType>(40. / 500.), static_cast<TestType>(3.), static_cast<TestType>(60.));
|
butterRequirement = difi::Butterworth<T>::findMinimumButter(T(150. / 500.), T(40. / 500.), T(3.), T(60.));
|
||||||
REQUIRE_EQUAL(5, butterRequirement.first);
|
REQUIRE_EQUAL(5, butterRequirement.first);
|
||||||
REQUIRE_SMALL(std::abs(static_cast<TestType>(0.296655824107340) - butterRequirement.second), std::numeric_limits<TestType>::epsilon() * 10);
|
REQUIRE_SMALL(std::abs(T(0.296655824107340) - butterRequirement.second), std::numeric_limits<T>::epsilon() * 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEMPLATE_TEST_CASE_METHOD(System, "Butterworth low pass filter", "[lp]", float, double)
|
TEST_CASE_TEMPLATE("Butterworth low pass filter", T, float, double)
|
||||||
{
|
{
|
||||||
System<TestType> s;
|
System<T> s;
|
||||||
auto bf = difi::Butterworth<TestType>(s.order, s.fc, s.fs);
|
auto bf = difi::Butterworth<T>(s.order, s.fc, s.fs);
|
||||||
REQUIRE_EQUAL(bf.aOrder(), bf.bOrder());
|
REQUIRE_EQUAL(bf.aOrder(), bf.bOrder());
|
||||||
test_coeffs(s.lpACoeffRes, s.lpBCoeffRes, bf, std::numeric_limits<TestType>::epsilon() * 10);
|
test_coeffs(s.lpACoeffRes, s.lpBCoeffRes, bf, std::numeric_limits<T>::epsilon() * 10);
|
||||||
test_results(s.lpResults, s.data, bf, std::numeric_limits<TestType>::epsilon() * 100);
|
test_results(s.lpResults, s.data, bf, std::numeric_limits<T>::epsilon() * 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEMPLATE_TEST_CASE_METHOD(System, "Butterworth high pass filter", "[hp]", float, double)
|
TEST_CASE_TEMPLATE("Butterworth high pass filter", T, float, double)
|
||||||
{
|
{
|
||||||
System<TestType> s;
|
System<T> s;
|
||||||
auto bf = difi::Butterworth<TestType>(s.order, s.fc, s.fs, difi::Butterworth<TestType>::Type::HighPass);
|
auto bf = difi::Butterworth<T>(s.order, s.fc, s.fs, difi::Butterworth<T>::Type::HighPass);
|
||||||
REQUIRE_EQUAL(bf.aOrder(), bf.bOrder());
|
REQUIRE_EQUAL(bf.aOrder(), bf.bOrder());
|
||||||
test_coeffs(s.hpACoeffRes, s.hpBCoeffRes, bf, std::numeric_limits<TestType>::epsilon() * 10);
|
test_coeffs(s.hpACoeffRes, s.hpBCoeffRes, bf, std::numeric_limits<T>::epsilon() * 10);
|
||||||
test_results(s.hpResults, s.data, bf, std::numeric_limits<TestType>::epsilon() * 1000);
|
test_results(s.hpResults, s.data, bf, std::numeric_limits<T>::epsilon() * 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEMPLATE_TEST_CASE_METHOD(System, "Butterworth band pass filter", "[bp]", float, double)
|
TEST_CASE_TEMPLATE("Butterworth band pass filter", T, float, double)
|
||||||
{
|
{
|
||||||
System<TestType> s;
|
System<T> s;
|
||||||
auto bf = difi::Butterworth<TestType>(s.order, s.fLower, s.fUpper, s.fs);
|
auto bf = difi::Butterworth<T>(s.order, s.fLower, s.fUpper, s.fs);
|
||||||
REQUIRE_EQUAL(bf.aOrder(), bf.bOrder());
|
REQUIRE_EQUAL(bf.aOrder(), bf.bOrder());
|
||||||
test_coeffs(s.bpACoeffRes, s.bpBCoeffRes, bf, std::numeric_limits<TestType>::epsilon() * 1000);
|
test_coeffs(s.bpACoeffRes, s.bpBCoeffRes, bf, std::numeric_limits<T>::epsilon() * 1000);
|
||||||
test_results(s.bpResults, s.data, bf, std::numeric_limits<TestType>::epsilon() * 10000);
|
test_results(s.bpResults, s.data, bf, std::numeric_limits<T>::epsilon() * 10000);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEMPLATE_TEST_CASE_METHOD(System, "Butterworth band-reject filter", "[br]", float, double)
|
TEST_CASE_TEMPLATE("Butterworth band-reject filter", T, float, double)
|
||||||
{
|
{
|
||||||
System<TestType> s;
|
System<T> s;
|
||||||
auto bf = difi::Butterworth<TestType>(s.order, s.fLower, s.fUpper, s.fs, difi::Butterworth<TestType>::Type::BandReject);
|
auto bf = difi::Butterworth<T>(s.order, s.fLower, s.fUpper, s.fs, difi::Butterworth<T>::Type::BandReject);
|
||||||
REQUIRE_EQUAL(bf.aOrder(), bf.bOrder());
|
REQUIRE_EQUAL(bf.aOrder(), bf.bOrder());
|
||||||
test_coeffs(s.brACoeffRes, s.brBCoeffRes, bf, std::numeric_limits<TestType>::epsilon() * TestType(1e8));
|
test_coeffs(s.brACoeffRes, s.brBCoeffRes, bf, std::numeric_limits<T>::epsilon() * T(1e8));
|
||||||
test_results(s.brResults, s.data, bf, std::numeric_limits<TestType>::epsilon() * TestType(1e8));
|
test_results(s.brResults, s.data, bf, std::numeric_limits<T>::epsilon() * T(1e8));
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,16 +27,13 @@
|
||||||
|
|
||||||
enable_testing()
|
enable_testing()
|
||||||
|
|
||||||
find_package(Catch2 REQUIRED)
|
|
||||||
|
|
||||||
macro(addTest testName)
|
macro(addTest testName)
|
||||||
add_executable(${testName} ${testName}.cpp)
|
add_executable(${testName} ${testName}.cpp)
|
||||||
if (MSVC)
|
if (MSVC)
|
||||||
target_compile_definitions(${testName} PUBLIC _SILENCE_ALL_CXX17_DEPRECATION_WARNINGS)
|
target_compile_definitions(${testName} PUBLIC _SILENCE_ALL_CXX17_DEPRECATION_WARNINGS)
|
||||||
endif()
|
endif()
|
||||||
target_link_libraries(${testName} PRIVATE Catch2::Catch2)
|
target_compile_definitions(${testName} PUBLIC DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN)
|
||||||
target_compile_definitions(${testName} PRIVATE CATCH_CONFIG_MAIN)
|
target_link_libraries(${testName} PUBLIC Eigen3::Eigen)
|
||||||
target_include_directories(${testName} SYSTEM PRIVATE "${EIGEN3_INCLUDE_DIR}")
|
|
||||||
# Adding a project configuration file (for MSVC only)
|
# Adding a project configuration file (for MSVC only)
|
||||||
generate_msvc_dot_user_file(${testName})
|
generate_msvc_dot_user_file(${testName})
|
||||||
|
|
||||||
|
|
|
@ -26,9 +26,9 @@
|
||||||
// either expressed or implied, of the FreeBSD Project.
|
// either expressed or implied, of the FreeBSD Project.
|
||||||
|
|
||||||
#include "difi"
|
#include "difi"
|
||||||
|
#include "doctest/doctest.h"
|
||||||
#include "test_functions.h"
|
#include "test_functions.h"
|
||||||
#include "warning_macro.h"
|
#include "warning_macro.h"
|
||||||
#include <catch2/catch.hpp>
|
|
||||||
|
|
||||||
DISABLE_CONVERSION_WARNING_BEGIN
|
DISABLE_CONVERSION_WARNING_BEGIN
|
||||||
|
|
||||||
|
@ -42,10 +42,10 @@ struct System {
|
||||||
|
|
||||||
DISABLE_CONVERSION_WARNING_END
|
DISABLE_CONVERSION_WARNING_END
|
||||||
|
|
||||||
TEMPLATE_TEST_CASE_METHOD(System, "Digital filter", "[df]", float, double)
|
TEST_CASE_TEMPLATE("Digital filter", T, float, double)
|
||||||
{
|
{
|
||||||
System<TestType> s;
|
System<T> s;
|
||||||
auto df = difi::DigitalFilter<TestType>(s.aCoeff, s.bCoeff);
|
auto df = difi::DigitalFilter<T>(s.aCoeff, s.bCoeff);
|
||||||
test_coeffs(s.aCoeff, s.bCoeff, df, std::numeric_limits<TestType>::epsilon() * 10);
|
test_coeffs(s.aCoeff, s.bCoeff, df, std::numeric_limits<T>::epsilon() * 10);
|
||||||
test_results(s.results, s.data, df, std::numeric_limits<TestType>::epsilon() * 10);
|
test_results(s.results, s.data, df, std::numeric_limits<T>::epsilon() * 10);
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,11 +26,11 @@
|
||||||
// either expressed or implied, of the FreeBSD Project.
|
// either expressed or implied, of the FreeBSD Project.
|
||||||
|
|
||||||
#include "difi"
|
#include "difi"
|
||||||
|
#include "doctest/doctest.h"
|
||||||
#include <exception>
|
#include <exception>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <catch2/catch.hpp>
|
|
||||||
|
|
||||||
TEST_CASE("Filter failures", "[fail]")
|
TEST_CASE("Filter failures")
|
||||||
{
|
{
|
||||||
// A coeff are missing
|
// A coeff are missing
|
||||||
REQUIRE_THROWS_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);
|
||||||
|
|
|
@ -26,8 +26,8 @@
|
||||||
// either expressed or implied, of the FreeBSD Project.
|
// either expressed or implied, of the FreeBSD Project.
|
||||||
|
|
||||||
#include "difi"
|
#include "difi"
|
||||||
|
#include "doctest/doctest.h"
|
||||||
#include "test_functions.h"
|
#include "test_functions.h"
|
||||||
#include <catch2/catch.hpp>
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct System {
|
struct System {
|
||||||
|
@ -36,9 +36,9 @@ struct System {
|
||||||
difi::vectX_t<T> results = (difi::vectX_t<T>(6) << 0.25, 0.75, 1.5, 2.5, 3.5, 4.5).finished();
|
difi::vectX_t<T> results = (difi::vectX_t<T>(6) << 0.25, 0.75, 1.5, 2.5, 3.5, 4.5).finished();
|
||||||
};
|
};
|
||||||
|
|
||||||
TEMPLATE_TEST_CASE_METHOD(System, "Moving average filter", "[maf]", float, double)
|
TEST_CASE_TEMPLATE("Moving average filter", T, float, double)
|
||||||
{
|
{
|
||||||
System<TestType> s;
|
System<T> s;
|
||||||
auto maf = difi::MovingAverage<TestType>(s.windowSize);
|
auto maf = difi::MovingAverage<T>(s.windowSize);
|
||||||
test_results(s.results, s.data, maf, std::numeric_limits<TestType>::epsilon() * 10);
|
test_results(s.results, s.data, maf, std::numeric_limits<T>::epsilon() * 10);
|
||||||
}
|
}
|
|
@ -26,10 +26,10 @@
|
||||||
// either expressed or implied, of the FreeBSD Project.
|
// either expressed or implied, of the FreeBSD Project.
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "catch_helper.h"
|
#include "doctest_helper.h"
|
||||||
#include "difi"
|
#include "difi"
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <catch2/catch.hpp>
|
#include "doctest/doctest.h"
|
||||||
|
|
||||||
using namespace difi;
|
using namespace difi;
|
||||||
|
|
||||||
|
|
|
@ -25,10 +25,10 @@
|
||||||
// of the authors and should not be interpreted as representing official policies,
|
// of the authors and should not be interpreted as representing official policies,
|
||||||
// either expressed or implied, of the FreeBSD Project.
|
// either expressed or implied, of the FreeBSD Project.
|
||||||
|
|
||||||
#include "catch_helper.h"
|
|
||||||
#include "diffTesters.h"
|
#include "diffTesters.h"
|
||||||
|
#include "doctest/doctest.h"
|
||||||
|
#include "doctest_helper.h"
|
||||||
#include "noisy_function_generator.h"
|
#include "noisy_function_generator.h"
|
||||||
#include <catch2/catch.hpp>
|
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
|
||||||
constexpr const int STEPS = 500;
|
constexpr const int STEPS = 500;
|
||||||
|
@ -58,7 +58,7 @@ void checkCoeffs(const vectN_t<double, N>& coeffs, const vectN_t<double, N>& goo
|
||||||
REQUIRE_SMALL(std::abs(coeffs(i) - goodCoeffs(i)), std::numeric_limits<double>::epsilon() * 5);
|
REQUIRE_SMALL(std::abs(coeffs(i) - goodCoeffs(i)), std::numeric_limits<double>::epsilon() * 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Coefficient calculation", "[coeff]") // Some coeffs are computed, the rest are given
|
TEST_CASE("Coefficient calculation") // Some coeffs are computed, the rest are given
|
||||||
{
|
{
|
||||||
// LNL coeffs
|
// LNL coeffs
|
||||||
checkCoeffs<5>(details::GetLNLCoeffs<double, 5>{}(), generateLNLCoeffs<5>() / 10.);
|
checkCoeffs<5>(details::GetLNLCoeffs<double, 5>{}(), generateLNLCoeffs<5>() / 10.);
|
||||||
|
@ -78,7 +78,7 @@ TEST_CASE("Coefficient calculation", "[coeff]") // Some coeffs are computed, the
|
||||||
checkCoeffs<11>(details::GetFNRCoeffs<double, 11>{}(), (vectN_t<double, 11>() << 1., 8., 27., 48., 42., 0., -42., -48., -27., -8., -1.).finished() / 512.);
|
checkCoeffs<11>(details::GetFNRCoeffs<double, 11>{}(), (vectN_t<double, 11>() << 1., 8., 27., 48., 42., 0., -42., -48., -27., -8., -1.).finished() / 512.);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Sinus time-fixed central derivative", "[sin][central][1st]")
|
TEST_CASE("Sinus time-fixed central derivative")
|
||||||
{
|
{
|
||||||
double dt = 0.001;
|
double dt = 0.001;
|
||||||
auto sg = sinGenerator<double>(STEPS, SIN_AMPLITUDE, SIN_FREQUENCY, dt);
|
auto sg = sinGenerator<double>(STEPS, SIN_AMPLITUDE, SIN_FREQUENCY, dt);
|
||||||
|
@ -88,14 +88,14 @@ TEST_CASE("Sinus time-fixed central derivative", "[sin][central][1st]")
|
||||||
tester::set_time_steps(ct7, dt);
|
tester::set_time_steps(ct7, dt);
|
||||||
tester::set_time_steps(ct9, dt);
|
tester::set_time_steps(ct9, dt);
|
||||||
|
|
||||||
difi::vectX_t<double> eps{5};
|
difi::vectX_t<double> eps{ 5 };
|
||||||
eps << 1e-10, 1e-1, 1e-6, 1e-1, 1e-6; // Value checked with MATLAB
|
eps << 1e-10, 1e-1, 1e-6, 1e-1, 1e-6; // Value checked with MATLAB
|
||||||
|
|
||||||
tester::run_tests(ct7, std::get<0>(sg), std::get<1>(sg), eps);
|
tester::run_tests(ct7, std::get<0>(sg), std::get<1>(sg), eps);
|
||||||
tester::run_tests(ct9, std::get<0>(sg), std::get<1>(sg), eps);
|
tester::run_tests(ct9, std::get<0>(sg), std::get<1>(sg), eps);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Polynome time-fixed central derivative", "[poly][central][1st]")
|
TEST_CASE("Polynome time-fixed central derivative")
|
||||||
{
|
{
|
||||||
double dt = 0.001;
|
double dt = 0.001;
|
||||||
{
|
{
|
||||||
|
@ -106,7 +106,7 @@ TEST_CASE("Polynome time-fixed central derivative", "[poly][central][1st]")
|
||||||
tester::set_time_steps(ct7, dt);
|
tester::set_time_steps(ct7, dt);
|
||||||
tester::set_time_steps(ct9, dt);
|
tester::set_time_steps(ct9, dt);
|
||||||
|
|
||||||
difi::vectX_t<double> eps{5};
|
difi::vectX_t<double> eps{ 5 };
|
||||||
eps << 1e-12, 1e-4, 1e-12, 1e-4, 1e-12; // Value checked with MATLAB
|
eps << 1e-12, 1e-4, 1e-12, 1e-4, 1e-12; // Value checked with MATLAB
|
||||||
|
|
||||||
tester::run_tests(ct7, std::get<0>(pg), std::get<1>(pg), eps);
|
tester::run_tests(ct7, std::get<0>(pg), std::get<1>(pg), eps);
|
||||||
|
@ -120,7 +120,7 @@ TEST_CASE("Polynome time-fixed central derivative", "[poly][central][1st]")
|
||||||
tester::set_time_steps(ct7, dt);
|
tester::set_time_steps(ct7, dt);
|
||||||
tester::set_time_steps(ct9, dt);
|
tester::set_time_steps(ct9, dt);
|
||||||
|
|
||||||
difi::vectX_t<double> eps{5};
|
difi::vectX_t<double> eps{ 5 };
|
||||||
eps << 1e-11, 1e-3, 1e-9, 1e-4, 1e-9; // Value checked with MATLAB
|
eps << 1e-11, 1e-3, 1e-9, 1e-4, 1e-9; // Value checked with MATLAB
|
||||||
|
|
||||||
tester::run_tests(ct7, std::get<0>(pg), std::get<1>(pg), eps);
|
tester::run_tests(ct7, std::get<0>(pg), std::get<1>(pg), eps);
|
||||||
|
@ -128,7 +128,7 @@ TEST_CASE("Polynome time-fixed central derivative", "[poly][central][1st]")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("2nd order sinus time-fixed center derivative", "[sin][center][2nd]")
|
TEST_CASE("2nd order sinus time-fixed center derivative")
|
||||||
{
|
{
|
||||||
double dt = 0.001;
|
double dt = 0.001;
|
||||||
auto sg = sinGenerator<double>(STEPS, SIN_AMPLITUDE, SIN_FREQUENCY, dt);
|
auto sg = sinGenerator<double>(STEPS, SIN_AMPLITUDE, SIN_FREQUENCY, dt);
|
||||||
|
@ -140,7 +140,7 @@ TEST_CASE("2nd order sinus time-fixed center derivative", "[sin][center][2nd]")
|
||||||
tester::set_time_steps(ct9, dt);
|
tester::set_time_steps(ct9, dt);
|
||||||
tester::set_time_steps(ct11, dt);
|
tester::set_time_steps(ct11, dt);
|
||||||
|
|
||||||
difi::vectX_t<double> eps{1};
|
difi::vectX_t<double> eps{ 1 };
|
||||||
eps << 2e-1;
|
eps << 2e-1;
|
||||||
|
|
||||||
tester::run_tests(ct7, std::get<0>(sg), std::get<2>(sg), eps);
|
tester::run_tests(ct7, std::get<0>(sg), std::get<2>(sg), eps);
|
||||||
|
@ -148,21 +148,21 @@ TEST_CASE("2nd order sinus time-fixed center derivative", "[sin][center][2nd]")
|
||||||
tester::run_tests(ct11, std::get<0>(sg), std::get<2>(sg), eps);
|
tester::run_tests(ct11, std::get<0>(sg), std::get<2>(sg), eps);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Sinus time-varying central derivative", "[tv][sin][central][1st]")
|
TEST_CASE("Sinus time-varying central derivative")
|
||||||
{
|
{
|
||||||
double dt = 0.001;
|
double dt = 0.001;
|
||||||
auto sg = tvSinGenerator<double>(STEPS, SIN_AMPLITUDE, SIN_FREQUENCY, dt);
|
auto sg = tvSinGenerator<double>(STEPS, SIN_AMPLITUDE, SIN_FREQUENCY, dt);
|
||||||
auto ct7 = tester::tv_central_list<7>{};
|
auto ct7 = tester::tv_central_list<7>{};
|
||||||
auto ct9 = tester::tv_central_list<9>{};
|
auto ct9 = tester::tv_central_list<9>{};
|
||||||
|
|
||||||
difi::vectX_t<double> eps{2};
|
difi::vectX_t<double> eps{ 2 };
|
||||||
eps << 1., 1.;
|
eps << 1., 1.;
|
||||||
|
|
||||||
tester::run_tests(ct7, std::get<0>(sg), std::get<1>(sg), std::get<2>(sg), eps);
|
tester::run_tests(ct7, std::get<0>(sg), std::get<1>(sg), std::get<2>(sg), eps);
|
||||||
tester::run_tests(ct9, std::get<0>(sg), std::get<1>(sg), std::get<2>(sg), eps);
|
tester::run_tests(ct9, std::get<0>(sg), std::get<1>(sg), std::get<2>(sg), eps);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Polynome time-varying central derivative", "[tv][poly][central][1st]")
|
TEST_CASE("Polynome time-varying central derivative")
|
||||||
{
|
{
|
||||||
double dt = 0.001;
|
double dt = 0.001;
|
||||||
{
|
{
|
||||||
|
@ -170,7 +170,7 @@ TEST_CASE("Polynome time-varying central derivative", "[tv][poly][central][1st]"
|
||||||
auto ct7 = tester::tv_central_list<7>{};
|
auto ct7 = tester::tv_central_list<7>{};
|
||||||
auto ct9 = tester::tv_central_list<9>{};
|
auto ct9 = tester::tv_central_list<9>{};
|
||||||
|
|
||||||
difi::vectX_t<double> eps{2};
|
difi::vectX_t<double> eps{ 2 };
|
||||||
eps << 1e-3, 1e-3;
|
eps << 1e-3, 1e-3;
|
||||||
|
|
||||||
tester::run_tests(ct7, std::get<0>(pg), std::get<1>(pg), std::get<2>(pg), eps);
|
tester::run_tests(ct7, std::get<0>(pg), std::get<1>(pg), std::get<2>(pg), eps);
|
||||||
|
@ -181,7 +181,7 @@ TEST_CASE("Polynome time-varying central derivative", "[tv][poly][central][1st]"
|
||||||
auto ct7 = tester::tv_central_list<7>{};
|
auto ct7 = tester::tv_central_list<7>{};
|
||||||
auto ct9 = tester::tv_central_list<9>{};
|
auto ct9 = tester::tv_central_list<9>{};
|
||||||
|
|
||||||
difi::vectX_t<double> eps{2};
|
difi::vectX_t<double> eps{ 2 };
|
||||||
eps << 1e-2, 1e-2;
|
eps << 1e-2, 1e-2;
|
||||||
|
|
||||||
tester::run_tests(ct7, std::get<0>(pg), std::get<1>(pg), std::get<2>(pg), eps);
|
tester::run_tests(ct7, std::get<0>(pg), std::get<1>(pg), std::get<2>(pg), eps);
|
||||||
|
|
Plik diff jest za duży
Load Diff
|
@ -26,9 +26,9 @@
|
||||||
// either expressed or implied, of the FreeBSD Project.
|
// either expressed or implied, of the FreeBSD Project.
|
||||||
|
|
||||||
#include "difi"
|
#include "difi"
|
||||||
|
#include "doctest/doctest.h"
|
||||||
|
#include "doctest_helper.h"
|
||||||
#include "warning_macro.h"
|
#include "warning_macro.h"
|
||||||
#include "catch_helper.h"
|
|
||||||
#include <catch2/catch.hpp>
|
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
|
||||||
using c_int_t = std::complex<int>;
|
using c_int_t = std::complex<int>;
|
||||||
|
@ -61,7 +61,7 @@ struct SystemCFloat {
|
||||||
|
|
||||||
DISABLE_CONVERSION_WARNING_END
|
DISABLE_CONVERSION_WARNING_END
|
||||||
|
|
||||||
TEST_CASE_METHOD(SystemInt, "Polynome function for int", "[poly]")
|
TEST_CASE("Polynome function for int")
|
||||||
{
|
{
|
||||||
SystemInt s;
|
SystemInt s;
|
||||||
auto res = difi::VietaAlgoi::polyCoeffFromRoot(s.data);
|
auto res = difi::VietaAlgoi::polyCoeffFromRoot(s.data);
|
||||||
|
@ -69,16 +69,16 @@ TEST_CASE_METHOD(SystemInt, "Polynome function for int", "[poly]")
|
||||||
REQUIRE_EQUAL(res(i), s.results(i));
|
REQUIRE_EQUAL(res(i), s.results(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEMPLATE_TEST_CASE_METHOD(SystemFloat, "Polynome function for floating point", "[poly]", float, double)
|
TEST_CASE_TEMPLATE("Polynome function for floating point", T, float, double)
|
||||||
{
|
{
|
||||||
SystemFloat<TestType> s;
|
SystemFloat<T> s;
|
||||||
auto res = difi::VietaAlgo<TestType>::polyCoeffFromRoot(s.data);
|
auto res = difi::VietaAlgo<T>::polyCoeffFromRoot(s.data);
|
||||||
|
|
||||||
for (Eigen::Index i = 0; i < res.size(); ++i)
|
for (Eigen::Index i = 0; i < res.size(); ++i)
|
||||||
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<T>::epsilon() * 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE_METHOD(SystemCInt, "Polynome function for complex int", "[poly]")
|
TEST_CASE("Polynome function for complex int")
|
||||||
{
|
{
|
||||||
SystemCInt s;
|
SystemCInt s;
|
||||||
auto res = difi::VietaAlgoci::polyCoeffFromRoot(s.data);
|
auto res = difi::VietaAlgoci::polyCoeffFromRoot(s.data);
|
||||||
|
@ -86,11 +86,11 @@ TEST_CASE_METHOD(SystemCInt, "Polynome function for complex int", "[poly]")
|
||||||
REQUIRE_EQUAL(res(i), s.results(i));
|
REQUIRE_EQUAL(res(i), s.results(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEMPLATE_TEST_CASE_METHOD(SystemFloat, "Polynome function for complex floating point", "[poly]", float, double)
|
TEST_CASE_TEMPLATE("Polynome function for complex floating point", T, float, double)
|
||||||
{
|
{
|
||||||
SystemCFloat<TestType> s;
|
SystemCFloat<T> s;
|
||||||
auto res = difi::VietaAlgo<std::complex<TestType>>::polyCoeffFromRoot(s.data);
|
auto res = difi::VietaAlgo<std::complex<T>>::polyCoeffFromRoot(s.data);
|
||||||
|
|
||||||
for (Eigen::Index i = 0; i < res.size(); ++i)
|
for (Eigen::Index i = 0; i < res.size(); ++i)
|
||||||
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<T>::epsilon() * 1000);
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,8 +28,8 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "difi"
|
#include "difi"
|
||||||
#include <Catch2/catch.hpp>
|
#include "doctest/doctest.h"
|
||||||
#include "catch_helper.h"
|
#include "doctest_helper.h"
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
|
Ładowanie…
Reference in New Issue