diff --git a/CMakeLists.txt b/CMakeLists.txt index 0d2116e..e690643 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -90,5 +90,6 @@ install(TARGETS WoWCombatAnalyzer qt_finalize_executable(WoWCombatAnalyzer) if("${BUILD_TESTS}") + enable_testing() add_subdirectory(tests) endif() diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 9a97edb..7c3fe67 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -2,16 +2,19 @@ cmake_minimum_required(VERSION 3.11 FATAL_ERROR) include(FetchContent) + + + FetchContent_Declare( - ut - GIT_REPOSITORY https://github.com/boost-ext/ut - GIT_TAG cd12498 + gtest + GIT_REPOSITORY https://github.com/google/googletest + GIT_TAG f8d7d77 ) -FetchContent_MakeAvailable(ut) +FetchContent_MakeAvailable(gtest) add_executable(SubSamplerTest SubSamplerTest.cpp) -target_link_libraries(SubSamplerTest PRIVATE Boost::ut filters) -add_test(SubSamplerTest SubSamplerTest) +target_link_libraries(SubSamplerTest PRIVATE GTest::gtest_main filters) +add_test(NAME SubSamplerTest COMMAND SubSamplerTest) diff --git a/tests/SubSamplerTest.cpp b/tests/SubSamplerTest.cpp index 48fa6a5..c0f4d00 100644 --- a/tests/SubSamplerTest.cpp +++ b/tests/SubSamplerTest.cpp @@ -1,6 +1,6 @@ #include "../filters/SubSampler.h" #include -#include +#include #include #include #include @@ -115,65 +115,59 @@ param p12{{{65618, 3361}, } // namespace -void range_compare(std::span> l, - std::span> r) +class SubSamplerTest : public testing::TestWithParam { - boost::ut::expect(l.size() == r.size()) - << "range size mismatch, l: " << l.size() - << ", r: " << r.size(); // << boost::ut::fatal; - auto li = l.begin(); - auto ri = r.begin(); - for (; li != l.end(); ++li, ++ri) - { - boost::ut::expect(std::abs(li->first - ri->first) <= (li->first / 1000)) - << "mismatched timestamps l: " << li->first - << ", r: " << ri->first; // << boost::ut::fatal; - boost::ut::expect(std::abs(li->second - ri->second) <= - (li->second / 1000)) - << "mismatched values l: " << li->second - << ", r: " << ri->second; // << boost::ut::fatal; - } -} - -std::vector> -test(std::span> data, qreal period, qreal start) -{ - std::vector> ret; - SubSampler sampler{period, start}; - for (const auto &[x, y] : data) +protected: + std::vector> + process(std::span> data, qreal period, + qreal start) { - auto samples = sampler.addValue(x, y); - if (samples.has_value()) + std::vector> ret; + SubSampler sampler{period, start}; + + for (const auto &[x, y] : data) { - for (const auto &sample : samples.value()) + auto samples = sampler.addValue(x, y); + if (samples.has_value()) { - ret.emplace_back(sample); + for (const auto &sample : samples.value()) + { + ret.emplace_back(sample); + } } } - } - ret.emplace_back(sampler.finalize()); + ret.emplace_back(sampler.finalize()); - return ret; -} + return ret; + } -void test_check(const param &p) + void range_compare(std::span> l, + std::span> r) + { + EXPECT_EQ(l.size(), r.size()) + << "range size mismatch, l: " << l.size() << ", r: " << r.size(); + auto li = l.begin(); + auto ri = r.begin(); + for (; li != l.end(); ++li, ++ri) + { + EXPECT_NEAR(li->first, ri->first, li->first / 1000) + << "mismatched timestamps l: " << li->first + << ", r: " << ri->first; + EXPECT_NEAR(li->second, ri->second, li->second / 1000) + << "mismatched values l: " << li->second + << ", r: " << ri->second; + } + } +}; + +TEST_P(SubSamplerTest, subsample) { - auto ret = test(p.in, p.period, p.start); + const auto &p = GetParam(); + auto ret = process(p.in, p.period, p.start); range_compare(p.out, ret); } -int main() -{ - test_check(p1); - test_check(p2); - test_check(p3); - test_check(p4); - test_check(p5); - test_check(p10); - test_check(p11); - test_check(p12); - - return 0; -} +INSTANTIATE_TEST_SUITE_P(SubSampler, SubSamplerTest, + testing::Values(p1, p2, p3, p4, p5, p10, p11, p12));