preCICE
v3.1.2
Loading...
Searching...
No Matches
src
utils
tests
EigenHelperFunctionsTest.cpp
Go to the documentation of this file.
1
#include <Eigen/Core>
2
#include <
iosfwd
>
3
#include <
string
>
4
#include "
math/constants.hpp
"
5
#include "
testing/TestContext.hpp
"
6
#include "
testing/Testing.hpp
"
7
#include "
utils/EigenHelperFunctions.hpp
"
8
#include "
utils/String.hpp
"
9
#include "
utils/algorithm.hpp
"
10
11
using namespace
precice
;
12
using namespace
precice::utils
;
13
14
BOOST_AUTO_TEST_SUITE
(UtilsTests)
15
BOOST_AUTO_TEST_SUITE
(EigenHelperFunctionsTests)
16
17
BOOST_AUTO_TEST_CASE
(FirstN)
18
{
19
PRECICE_TEST
(1_rank);
20
Eigen::VectorXd a(7);
21
a << 1, 2, 3, 4, 5, 6, 7;
22
Eigen::RowVectorXd b(3);
23
b << 1, 2, 3;
24
BOOST_TEST(
firstN
(a, 3) == b);
25
}
26
27
BOOST_AUTO_TEST_SUITE
(
RangePreview
)
28
29
BOOST_AUTO_TEST_CASE
(EigenVector)
30
{
31
PRECICE_TEST
(1_rank);
32
Eigen::VectorXd a{7};
33
a << 1, 2, 3, 4, 5, 6, 0;
34
std::ostringstream
oss;
35
oss <<
previewRange
(2, a);
36
std::string
str{oss.
str
()};
37
BOOST_TEST(str ==
"[1, 2, ... , 6, 0] min:0 max:6"
);
38
}
39
40
BOOST_AUTO_TEST_SUITE_END
()
41
42
BOOST_AUTO_TEST_CASE
(
ComponentWiseLess
)
43
{
44
PRECICE_TEST
(1_rank);
45
precice::utils::ComponentWiseLess
cwl;
46
47
Eigen::VectorXd a(8);
48
a << 1, 2, 3, 4, 5, 6, 7, 9;
49
50
Eigen::VectorXd b(8);
51
b << 1, 2, 3, 4, 5, 6, 8, 0;
52
53
BOOST_TEST(
componentWiseLess
(a, b));
54
BOOST_TEST(!
componentWiseLess
(b, a));
55
BOOST_TEST(cwl(a, b));
56
BOOST_TEST(!cwl(b, a));
57
58
Eigen::VectorXd c = b;
59
60
BOOST_TEST(!
componentWiseLess
(c, b));
61
BOOST_TEST(!
componentWiseLess
(b, c));
62
BOOST_TEST(!cwl(c, b));
63
BOOST_TEST(!cwl(b, c));
64
}
65
66
BOOST_AUTO_TEST_SUITE_END
()
67
BOOST_AUTO_TEST_SUITE_END
()
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(FirstN)
Definition
EigenHelperFunctionsTest.cpp:17
EigenHelperFunctions.hpp
BOOST_AUTO_TEST_SUITE
BOOST_AUTO_TEST_SUITE(PreProcess)
BOOST_AUTO_TEST_SUITE_END
BOOST_AUTO_TEST_SUITE_END()
String.hpp
TestContext.hpp
Testing.hpp
PRECICE_TEST
#define PRECICE_TEST(...)
Definition
Testing.hpp:27
algorithm.hpp
std::ostringstream
std::string
constants.hpp
iosfwd
precice::utils
contains precice-related utilities.
Definition
PointToPointCommunicationTest.cpp:23
precice::utils::previewRange
const RangePreview< Iter > previewRange(Size n, const Range &range)
Definition
algorithm.hpp:173
precice::utils::firstN
auto firstN(const Eigen::PlainObjectBase< Derived > &val, unsigned n) -> const Eigen::Map< const Eigen::Matrix< typename Derived::Scalar, 1, Eigen::Dynamic > >
Definition
EigenHelperFunctions.hpp:58
precice::utils::componentWiseLess
bool componentWiseLess(const Eigen::PlainObjectBase< DerivedLHS > &lhs, const Eigen::PlainObjectBase< DerivedRHS > &rhs)
Definition
EigenHelperFunctions.hpp:73
precice
Main namespace of the precice library.
Definition
Acceleration.cpp:5
std::ostringstream::str
T str(T... args)
string
precice::utils::ComponentWiseLess
Definition
EigenHelperFunctions.hpp:86
precice::utils::RangePreview
The RangePreview object used as a lazy proxy struct for proviewing the content of a Range.
Definition
algorithm.hpp:119