preCICE v3.1.1
Loading...
Searching...
No Matches
DifferencesTest.cpp
Go to the documentation of this file.
1#include <Eigen/Core>
3#include "math/constants.hpp"
6#include "testing/Testing.hpp"
7
8using namespace precice;
9using namespace precice::math;
10
11BOOST_AUTO_TEST_SUITE(MathTests)
12BOOST_AUTO_TEST_SUITE(Differences)
13
15{
16 PRECICE_TEST(1_rank);
17 double a = 1.0;
18 double b = 2.0;
19 double eps = 1e-14;
20
21 BOOST_CHECK(greater(b, a, eps));
22 BOOST_CHECK(not greater(a, a - eps, eps));
23 BOOST_CHECK(greater(a, a - 10.0 * eps, eps));
24
25 BOOST_CHECK(not greaterEquals(a, b, eps));
26 BOOST_CHECK(greaterEquals(b, a, eps));
27 BOOST_CHECK(greaterEquals(a, a, eps));
28 BOOST_CHECK(greaterEquals(a, a + 0.1 * eps, eps));
29 BOOST_CHECK(not greaterEquals(a, a + 10 * eps, eps));
30
31 BOOST_CHECK(smaller(a, b, eps));
32 BOOST_CHECK(not smaller(a, a + eps, eps));
33 BOOST_CHECK(smaller(a, a + 10.0 * eps, eps));
34
35 BOOST_CHECK(smallerEquals(a, b, eps));
36 BOOST_CHECK(smallerEquals(a, a + eps, eps));
37 BOOST_CHECK(smallerEquals(a + eps, a, eps));
38 BOOST_CHECK(smallerEquals(a, a + 10.0 * eps, eps));
39
40 BOOST_CHECK(not equals(a, b, eps));
41 BOOST_CHECK(equals(a, a, eps));
42 BOOST_CHECK(equals(a, a + eps, eps));
43 BOOST_CHECK(not equals(a, a + 10.0 * eps, eps));
44 BOOST_CHECK(equals(a, a + 10.0 * eps, 10.0 * eps));
45}
46
48{
49 PRECICE_TEST(1_rank);
50 Eigen::Vector3d vec0(1.0, 2.0, 3.0);
51 Eigen::Vector3d vec1(vec0);
52 BOOST_CHECK(equals(vec0, vec1));
53 BOOST_CHECK(not oneGreater(vec0, vec1));
54 BOOST_CHECK(oneGreaterEquals(vec0, vec1));
55 BOOST_CHECK(not allGreater(vec0, vec1));
56
57 vec0 << 2.0, 2.0, 3.0;
58 BOOST_CHECK(not equals(vec0, vec1));
59 BOOST_CHECK(oneGreater(vec0, vec1));
60 BOOST_CHECK(oneGreaterEquals(vec0, vec1));
61 BOOST_CHECK(not allGreater(vec0, vec1));
62
63 vec0 << 2.0, 3.0, 4.0;
64 BOOST_CHECK(not equals(vec0, vec1));
65 BOOST_CHECK(oneGreater(vec0, vec1));
66 BOOST_CHECK(oneGreaterEquals(vec0, vec1));
67 BOOST_CHECK(allGreater(vec0, vec1));
68
69 // up to here vec1=vec0
70 const double tolerance = 1e-14;
71 vec0(0) = vec1(0);
72 vec0(1) = vec1(1);
73 vec0(2) = vec1(2) + 0.99 * tolerance;
74 BOOST_CHECK(equals(vec0, vec1, tolerance));
75 BOOST_CHECK(not oneGreater(vec0, vec1, tolerance));
76 BOOST_CHECK(oneGreaterEquals(vec0, vec1));
77 BOOST_CHECK(not allGreater(vec0, vec1, tolerance));
78
79 vec0(2) = vec1(2) + 10.0 * tolerance;
80 BOOST_CHECK(not equals(vec0, vec1, tolerance));
81 BOOST_CHECK(oneGreater(vec0, vec1, tolerance));
82 BOOST_CHECK(oneGreaterEquals(vec0, vec1));
83 BOOST_CHECK(not allGreater(vec0, vec1, tolerance));
84
85 vec0 << 1.0, 2.0, 3.0;
86 vec0 = vec0.array() + (10.0 * tolerance);
87 BOOST_CHECK(not equals(vec0, vec1, tolerance));
88 BOOST_CHECK(oneGreater(vec0, vec1, tolerance));
89 BOOST_CHECK(oneGreaterEquals(vec0, vec1));
90 BOOST_CHECK(allGreater(vec0, vec1, tolerance));
91
92 vec0 << 1.0, 2.0, 3.0;
93 vec0 = vec0.array() - 0.99 * tolerance;
94 BOOST_CHECK(oneGreaterEquals(vec0, vec1));
95}
96
97BOOST_AUTO_TEST_SUITE_END() // Differences
98
BOOST_AUTO_TEST_CASE(Scalar)
BOOST_AUTO_TEST_SUITE(PreProcess)
BOOST_AUTO_TEST_SUITE_END()
#define PRECICE_TEST(...)
Definition Testing.hpp:27
provides general mathematical constants and functions.
Definition barycenter.cpp:9
constexpr bool equals(const Eigen::MatrixBase< DerivedA > &A, const Eigen::MatrixBase< DerivedB > &B, double tolerance=NUMERICAL_ZERO_DIFFERENCE)
Compares two Eigen::MatrixBase for equality up to tolerance.
bool oneGreaterEquals(const Eigen::MatrixBase< DerivedA > &A, const Eigen::MatrixBase< DerivedB > &B, double tolerance=math::NUMERICAL_ZERO_DIFFERENCE)
std::enable_if< std::is_arithmetic< Scalar >::value, bool >::type smallerEquals(Scalar A, Scalar B, Scalar tolerance=NUMERICAL_ZERO_DIFFERENCE)
std::enable_if< std::is_arithmetic< Scalar >::value, bool >::type greaterEquals(Scalar A, Scalar B, Scalar tolerance=NUMERICAL_ZERO_DIFFERENCE)
std::enable_if< std::is_arithmetic< Scalar >::value, bool >::type smaller(Scalar A, Scalar B, Scalar tolerance=NUMERICAL_ZERO_DIFFERENCE)
bool allGreater(const Eigen::MatrixBase< DerivedA > &A, const Eigen::MatrixBase< DerivedB > &B, double tolerance=math::NUMERICAL_ZERO_DIFFERENCE)
bool oneGreater(const Eigen::MatrixBase< DerivedA > &A, const Eigen::MatrixBase< DerivedB > &B, double tolerance=math::NUMERICAL_ZERO_DIFFERENCE)
std::enable_if< std::is_arithmetic< Scalar >::value, bool >::type greater(Scalar A, Scalar B, Scalar tolerance=NUMERICAL_ZERO_DIFFERENCE)
Main namespace of the precice library.