Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
9.2.2023: Due to updates GitLab will be unavailable for some minutes between 9:00 and 11:00.
Open sidebar
IP
elsa
Commits
7f5e4a50
Commit
7f5e4a50
authored
Feb 21, 2020
by
Jens Petit
Committed by
Tobias Lasser
Feb 21, 2020
Browse files
Add common test routines
parent
6ad66e61
Pipeline
#218998
passed with stages
in 26 minutes
Changes
4
Pipelines
10
Hide whitespace changes
Inline
Side-by-side
elsa/CMakeLists.txt
View file @
7f5e4a50
...
...
@@ -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
}
)
...
...
elsa/core/tests/test_DataHandlers.cpp
View file @
7f5e4a50
...
...
@@ -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
::
ab
s
(
dh
.
dot
(
dh2
)
-
randVec
.
dot
(
randVec2
))
==
Approx
(
0.
f
)
);
REQUIRE
(
checkSameNumber
s
(
dh
.
dot
(
dh2
)
,
randVec
.
dot
(
randVec2
)));
auto
dhMap
=
dh2
.
getBlock
(
0
,
dh2
.
getSize
());
REQUIRE
(
std
::
ab
s
(
dh
.
dot
(
*
dhMap
)
-
randVec
.
dot
(
randVec2
))
==
Approx
(
0.
f
)
);
REQUIRE
(
checkSameNumber
s
(
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
::
ab
s
(
dh
[
i
]
-
oldDh
[
i
]
/
dh2
[
i
])
==
Approx
(
0
).
margin
(
0.00001
)
);
REQUIRE
(
checkSameNumber
s
(
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
::
ab
s
(
dh
[
i
]
-
oldDh
[
i
]
/
dh2
[
i
])
==
Approx
(
0
).
margin
(
0.00001
)
);
REQUIRE
(
checkSameNumber
s
(
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
::
ab
s
(
dh
[
i
]
-
oldDh
[
i
]
/
scalar
)
==
Approx
(
0
).
margin
(
0.00001
)
);
REQUIRE
(
checkSameNumber
s
(
dh
[
i
]
,
oldDh
[
i
]
/
scalar
));
}
THEN
(
"the element-wise assignment of a scalar works as expected"
)
...
...
elsa/test_routines/CMakeLists.txt
0 → 100644
View file @
7f5e4a50
cmake_minimum_required
(
VERSION 3.9
)
elsa/test_routines/testHelpers.h
0 → 100644
View file @
7f5e4a50
#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
;
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment