30 #define KRATOS_EXPECT_TRUE(IsTrue) if(!(IsTrue)) KRATOS_ERROR << "Check failed because " << #IsTrue << " is not true" << std::endl;
31 #define KRATOS_EXPECT_FALSE(IsFalse) if(IsFalse) KRATOS_ERROR << "Check failed because " << #IsFalse << " is not false" << std::endl;
33 #define KRATOS_EXPECT_EQ(a,b) if(!((a) == (b))) KRATOS_ERROR << "Check failed because " << #a << " is not equal to " << #b
34 #define KRATOS_EXPECT_NE(a,b) if((a) == (b)) KRATOS_ERROR << "Check failed because " << #a << " is equal to " << #b
39 #define KRATOS_EXPECT_STREQ(a,b) if((strcmp(a,b) != 0)) KRATOS_ERROR << "Check failed because \"" << a << "\" is not equal to \"" << b << "\"" << std::endl;
40 #define KRATOS_EXPECT_STRNE(a,b) if((strcmp(a,b) == 0)) KRATOS_ERROR << "Check failed because \"" << a << "\" is equal to \"" << b << "\"" << std::endl;
42 #define KRATOS_EXPECT_LT(a,b) if(!(a < b)) KRATOS_ERROR << "Check failed because " << #a << " is greater than or equal to " << #b << std::endl;
43 #define KRATOS_EXPECT_LE(a,b) if(!(a <= b)) KRATOS_ERROR << "Check failed because " << #a << " is greater than " << #b << std::endl;
45 #define KRATOS_EXPECT_GT(a,b) if(!(a > b)) KRATOS_ERROR << "Check failed because " << #a << " is less than or equal to " << #b
46 #define KRATOS_EXPECT_GE(a,b) if(!(a >= b)) KRATOS_ERROR << "Check failed because " << #a << " is less than " << #b
48 #define KRATOS_EXPECT_HAS_SUBSTRING(TheString, SubString) if (TheString.find(SubString) == std::string::npos ) \
49 KRATOS_ERROR << "The string \"" << SubString << "\" was not found in the given string" << std::endl;
51 #define KRATOS_EXPECT_NEAR(a,b, tolerance) if(!(std::abs(a - b) <= tolerance)) KRATOS_ERROR << "Check failed because " << #a << " = " << a << \
52 " is not near to " << #b << " = " << b << " within the tolerance " << tolerance
53 #define KRATOS_EXPECT_RELATIVE_NEAR(a,b, tolerance) if(!(std::abs(b) <= std::numeric_limits<double>::epsilon())) { KRATOS_ERROR_IF(!(std::abs((a - b)/b) <= tolerance)) << "Check failed because " << #a << " = " << a << \
54 " is not near to " << #b << " = " << b << " within the relative tolerance " << tolerance << std::endl; } else {KRATOS_EXPECT_NEAR(a,b,tolerance);}
55 #define KRATOS_EXPECT_DOUBLE_EQ(a,b) KRATOS_EXPECT_NEAR(a,b,std::numeric_limits<double>::epsilon())
57 #define KRATOS_EXPECT_VECTOR_NEAR(a, b, tolerance) { \
58 KRATOS_ERROR_IF_NOT(a.size() == b.size()) \
59 << "Check failed because vector arguments do not have the same size:" \
61 << "First argument has size " << a.size() << ", " \
62 << "second argument has size " << b.size() << "." << std::endl; \
63 for (std::size_t _i = 0; _i < a.size(); _i++) { \
64 KRATOS_ERROR_IF( !(std::abs(a[_i] - b[_i]) <= tolerance) ) \
65 << "Check failed because vector " << #a << " with values" << std::endl \
67 << "Is not near vector " << #b << " with values" << std::endl \
69 << "Mismatch found in component " << _i << ":" << std::endl \
70 << a[_i] << " not near " << b[_i] \
71 << " within tolerance " << tolerance << "." << std::endl; \
75 #define KRATOS_EXPECT_VECTOR_RELATIVE_NEAR(a, b, tolerance) { \
76 KRATOS_ERROR_IF_NOT(a.size() == b.size()) \
77 << "Check failed because vector arguments do not have the same size:" \
79 << "First argument has size " << a.size() << ", " \
80 << "second argument has size " << b.size() << "." << std::endl; \
81 for (std::size_t _i = 0; _i < a.size(); _i++) { \
82 if (std::abs(b[_i]) > std::numeric_limits<double>::epsilon()) { \
83 KRATOS_ERROR_IF( !(std::abs((a[_i] - b[_i])/b[_i]) <= tolerance) ) \
84 << "Check failed because vector " << #a << " with values" << std::endl \
86 << "Is not near vector " << #b << " with values" << std::endl \
88 << "Mismatch found in component " << _i << ":" << std::endl \
89 << a[_i] << " not near " << b[_i] \
90 << " within relative tolerance " << tolerance << "." << std::endl; \
92 KRATOS_ERROR_IF( !(std::abs(a[_i] - b[_i]) <= tolerance) ) \
93 << "Check failed because vector " << #a << " with values" << std::endl \
95 << "Is not near vector " << #b << " with values" << std::endl \
97 << "Mismatch found in component " << _i << ":" << std::endl \
98 << a[_i] << " not near " << b[_i] \
99 << " within tolerance " << tolerance << "." << std::endl; \
104 #define KRATOS_EXPECT_VECTOR_EQ(a, b) KRATOS_EXPECT_VECTOR_NEAR(a,b,std::numeric_limits<double>::epsilon())
106 #define KRATOS_EXPECT_MATRIX_NEAR(a, b, tolerance) { \
107 KRATOS_ERROR_IF_NOT((a.size1() == b.size1()) && (a.size2() == b.size2())) \
108 << "Check failed because matrix arguments do not have the same dimensions:" \
110 << "First argument has dimensions (" << a.size1() << "," << a.size2() << "), " \
111 << "second argument has dimensions (" << b.size1() << "," << b.size2() << ")." \
113 for (std::size_t _i = 0; _i < a.size1(); _i++) { \
114 for (std::size_t _j = 0; _j < a.size2(); _j++) { \
115 KRATOS_ERROR_IF( !(std::abs(a(_i,_j) - b(_i,_j)) <= tolerance) ) \
116 << "Check failed because matrix " << #a << " with values" << std::endl \
118 << "Is not near matrix " << #b << " with values" << std::endl \
120 << "Mismatch found in component (" << _i << "," << _j << "): " << std::endl \
121 << a(_i,_j) << " not near " << b(_i,_j) \
122 << " within tolerance " << tolerance << "." << std::endl; \
127 #define KRATOS_EXPECT_MATRIX_RELATIVE_NEAR(a, b, tolerance) { \
128 KRATOS_ERROR_IF_NOT((a.size1() == b.size1()) && (a.size2() == b.size2())) \
129 << "Check failed because matrix arguments do not have the same dimensions:" \
131 << "First argument has dimensions (" << a.size1() << "," << a.size2() << "), " \
132 << "second argument has dimensions (" << b.size1() << "," << b.size2() << ")." \
134 for (std::size_t _i = 0; _i < a.size1(); _i++) { \
135 for (std::size_t _j = 0; _j < a.size2(); _j++) { \
136 if (std::abs(b(_i,_j)) > std::numeric_limits<double>::epsilon()) { \
137 KRATOS_ERROR_IF( !(std::abs((a(_i,_j) - b(_i,_j))/b(_i,_j)) <= tolerance) ) \
138 << "Check failed because matrix " << #a << " with values" << std::endl \
140 << "Is not near matrix " << #b << " with values" << std::endl \
142 << "Mismatch found in component (" << _i << "," << _j << "): " << std::endl \
143 << a(_i,_j) << " not near " << b(_i,_j) \
144 << " within relative tolerance " << tolerance << "." << std::endl; \
146 KRATOS_ERROR_IF( !(std::abs(a(_i,_j) - b(_i,_j)) <= tolerance) ) \
147 << "Check failed because matrix " << #a << " with values" << std::endl \
149 << "Is not near matrix " << #b << " with values" << std::endl \
151 << "Mismatch found in component (" << _i << "," << _j << "): " << std::endl \
152 << a(_i,_j) << " not near " << b(_i,_j) \
153 << " within tolerance " << tolerance << "." << std::endl; \
159 #define KRATOS_EXPECT_MATRIX_EQ(a, b) KRATOS_EXPECT_MATRIX_NEAR(a,b,std::numeric_limits<double>::epsilon())
161 #define KRATOS_EXPECT_EXCEPTION_IS_THROWN(TheStatement, TheErrorMessage) \
164 KRATOS_ERROR << #TheStatement << " exited without throwing an error." << std::endl; \
165 } catch (Kratos::Exception& e) { \
166 if ( std::string(e.what()).find( TheErrorMessage ) == std::string::npos ) \
168 << "Test Failed: " << #TheStatement \
169 << " did not throw the expected error." << std::endl \
170 << "Expected:" << std::endl << TheErrorMessage << std::endl \
171 << "Got:" << std::endl << e.what() << std::endl; \
174 #define KRATOS_EXPECT_VARIABLE_IN_NODAL_DATA(TheVariable, TheNode) \
175 KRATOS_ERROR_IF_NOT(TheNode.SolutionStepsDataHas(TheVariable)) \
176 << "Missing " << TheVariable.Name() << " variable in solution step data for node " \
177 << TheNode.Id() << "." << std::endl;
179 #define KRATOS_EXPECT_DOF_IN_NODE(TheVariable, TheNode) \
180 KRATOS_ERROR_IF_NOT(TheNode.HasDofFor(TheVariable)) \
181 << "Missing Degree of Freedom for " << TheVariable.Name() \
182 << " in node " << TheNode.Id() << "." << std::endl;
185 #define KRATOS_DEBUG_EXCEPT_EXCEPTION_IS_THROWN(TheStatement, TheErrorMessage) KRATOS_EXPECT_EXCEPTION_IS_THROWN(TheStatement, TheErrorMessage)
187 #define KRATOS_DEBUG_EXCEPT_EXCEPTION_IS_THROWN(TheStatement, TheErrorMessage) if(false) KRATOS_EXPECT_EXCEPTION_IS_THROWN(TheStatement, TheErrorMessage)