From ba1dae66be2374604c2803da64d9b08b308e1915 Mon Sep 17 00:00:00 2001 From: Michael Bloom Date: Sat, 2 Dec 2023 10:14:05 -0500 Subject: [PATCH] Add Wpedantic and Wconversion. Found bug in test that abs was converting to int. Replaced with std::abs. Test still passes. --- CMakeLists.txt | 2 +- test/testIIR.cpp | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e905de2..20c3f66 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,7 @@ find_package(Catch2 REQUIRED) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) if ( CMAKE_COMPILER_IS_GNUCC ) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic -Wconversion") endif() add_executable(${PROJECT_NAME} ${test}) diff --git a/test/testIIR.cpp b/test/testIIR.cpp index 0b1fa57..2c5e30b 100644 --- a/test/testIIR.cpp +++ b/test/testIIR.cpp @@ -54,7 +54,7 @@ TEST_CASE("Filter test", "[single-file]") std::vector error(readImpulse.size()); for (size_t i = 0; i < error.size(); i++) { - error.at(i) = abs(data.at(i) - readImpulse.at(i)); + error.at(i) = std::abs(data.at(i) - readImpulse.at(i)); } double maxError = *std::max_element(error.begin(), error.end()); REQUIRE(maxError < 1e-12); //typically error 1e-16 or less @@ -91,7 +91,7 @@ TEST_CASE("Filter test", "[single-file]") lpFilter.SetLPCoeff(f0, fs); lpFilter.PreloadFilter(steadyValue); lpFilter.Process(steadyLP.begin(), steadyLP.end()); - auto calcError = [steadyValue](double& n) { n = abs(n - steadyValue); }; + auto calcError = [steadyValue](double& n) { n = std::abs(n - steadyValue); }; std::for_each(steadyLP.begin(), steadyLP.end(), calcError); double maxErrorLP = *std::max_element(steadyLP.begin(), steadyLP.end()); REQUIRE(maxErrorLP < 1e-12); @@ -104,7 +104,7 @@ TEST_CASE("Filter test", "[single-file]") hpFilter.SetHPCoeff(f0, fs); hpFilter.PreloadFilter(steadyValue); hpFilter.Process(steadyHP.begin(), steadyHP.end()); - auto calcError = [](double& n) { n = abs(n); }; + auto calcError = [](double& n) { n = std::abs(n); }; std::for_each(steadyHP.begin(), steadyHP.end(), calcError); double maxErrorHP = *std::max_element(steadyHP.begin(), steadyHP.end()); REQUIRE(maxErrorHP < 1e-12); @@ -117,7 +117,7 @@ TEST_CASE("Filter test", "[single-file]") bpFilter.SetBPCoeff(f0, fs, Q); bpFilter.PreloadFilter(steadyValue); bpFilter.Process(steadyBP.begin(), steadyBP.end()); - auto calcError = [](double& n) { n = abs(n); }; + auto calcError = [](double& n) { n = std::abs(n); }; std::for_each(steadyBP.begin(), steadyBP.end(), calcError); double maxErrorBP = *std::max_element(steadyBP.begin(), steadyBP.end()); REQUIRE(maxErrorBP < 1e-12);