Starting from 2021-07-01, all LRZ GitLab users will be required to explicitly accept the GitLab Terms of Service. Please see the detailed information at https://doku.lrz.de/display/PUBLIC/GitLab and make sure that your projects conform to the requirements.

Commit 7f5e4a50 authored by Jens Petit's avatar Jens Petit Committed by Tobias Lasser
Browse files

Add common test routines

parent 6ad66e61
Pipeline #218998 passed with stages
in 26 minutes
......@@ -16,6 +16,8 @@ macro(ELSA_TEST NAME)
target_link_libraries(test_${NAME} PRIVATE Catch2::Catch2 ${ELSA_MODULE_TARGET_NAME})
# enable C++17
target_compile_features(test_${NAME} PUBLIC cxx_std_17)
# include helpers
target_include_directories(test_${NAME} PRIVATE ${CMAKE_SOURCE_DIR}/elsa/test_routines/)
# if we use JUnit reporter handle arguments
if(${ELSA_CREATE_JUNIT_REPORTS})
......
......@@ -11,6 +11,7 @@
#include <catch2/catch.hpp>
#include "DataHandlerCPU.h"
#include "DataHandlerMapCPU.h"
#include "testHelpers.h"
template <typename data_t>
long elsa::useCount(const DataHandlerCPU<data_t>& dh)
......@@ -433,11 +434,11 @@ TEMPLATE_PRODUCT_TEST_CASE("Scenario: Testing the reduction operatios of DataHan
Eigen::Matrix<data_t, Eigen::Dynamic, 1>::Random(size);
TestType dh2(randVec2);
REQUIRE(std::abs(dh.dot(dh2) - randVec.dot(randVec2)) == Approx(0.f));
REQUIRE(checkSameNumbers(dh.dot(dh2), randVec.dot(randVec2)));
auto dhMap = dh2.getBlock(0, dh2.getSize());
REQUIRE(std::abs(dh.dot(*dhMap) - randVec.dot(randVec2)) == Approx(0.f));
REQUIRE(checkSameNumbers(dh.dot(*dhMap), randVec.dot(randVec2)));
}
THEN("the dot product expects correctly sized arguments")
......@@ -518,13 +519,13 @@ TEMPLATE_PRODUCT_TEST_CASE("Scenario: Testing the element-wise operations of Dat
dh /= dh2;
for (index_t i = 0; i < size; ++i)
if (dh2[i] != data_t(0))
REQUIRE(std::abs(dh[i] - oldDh[i] / dh2[i]) == Approx(0).margin(0.00001));
REQUIRE(checkSameNumbers(dh[i], oldDh[i] / dh2[i]));
dh = oldDh;
dh /= *dhMap;
for (index_t i = 0; i < size; ++i)
if (dh2[i] != data_t(0))
REQUIRE(std::abs(dh[i] - oldDh[i] / dh2[i]) == Approx(0).margin(0.00001));
REQUIRE(checkSameNumbers(dh[i], oldDh[i] / dh2[i]));
}
THEN("the element-wise binary scalar operations work as expected")
......@@ -549,7 +550,7 @@ TEMPLATE_PRODUCT_TEST_CASE("Scenario: Testing the element-wise operations of Dat
dh = oldDh;
dh /= scalar;
for (index_t i = 0; i < size; ++i)
REQUIRE(std::abs(dh[i] - oldDh[i] / scalar) == Approx(0).margin(0.00001));
REQUIRE(checkSameNumbers(dh[i], oldDh[i] / scalar));
}
THEN("the element-wise assignment of a scalar works as expected")
......
cmake_minimum_required(VERSION 3.9)
#pragma once
#include <type_traits>
#include <complex.h>
/**
* \brief comparing two number types for approximate equality for complex and regular number
*
* \tparam T - arithmetic data type
* \return true if same number
*
* Use example in test case: REQUIRE(checkSameNumbers(a, b));
* The CHECK(...) assertion in the function ensures that the values are reported when the test fails
*/
template <typename T>
bool checkSameNumbers(T right, T left)
{
if constexpr (std::is_same_v<T,
std::complex<float>> || std::is_same_v<T, std::complex<double>>) {
CHECK(Approx(right.real()) == left.real());
CHECK(Approx(right.imag()) == left.imag());
return Approx(right.real()) == left.real() && Approx(right.imag()) == left.imag();
} else {
CHECK(Approx(right) == left);
return Approx(right) == left;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment