From 7633e8014c37655538e93feb415f5a3bf491c517 Mon Sep 17 00:00:00 2001 From: Martin Kronbichler Date: Wed, 15 Jun 2022 13:34:27 +0200 Subject: [PATCH] Make test more robust: Check tolerance rather than == --- tests/fe/fe_values_view_25b_nonsymmetric.cc | 24 +++++++++++++-------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/tests/fe/fe_values_view_25b_nonsymmetric.cc b/tests/fe/fe_values_view_25b_nonsymmetric.cc index 5911e0ac7b..fd424cdb2c 100644 --- a/tests/fe/fe_values_view_25b_nonsymmetric.cc +++ b/tests/fe/fe_values_view_25b_nonsymmetric.cc @@ -165,19 +165,21 @@ test(const Triangulation &tr, const FiniteElement &fe) dealii::Tensor<2, dim>::unrolled_to_component_indices(k); if (ind_k == nonzero_ind) { - AssertThrow(val_q[ind_k] == scalar_values[i_node][q], + AssertThrow(std::abs(val_q[ind_k] - + scalar_values[i_node][q]) < 1e-12, ExcInternalError()); - AssertThrow((grad_q[ind_k[0]][ind_k[1]] == - scalar_gradients[i_node][q]), + AssertThrow((grad_q[ind_k[0]][ind_k[1]] - + scalar_gradients[i_node][q]) + .norm() < 1e-11, ExcInternalError()); } else { - AssertThrow(val_q[ind_k] == 0., + AssertThrow(std::abs(val_q[ind_k]) < 1e-12, ExcMessage(std::to_string(k) + " " + std::to_string(ind_k[0]) + " " + std::to_string(ind_k[1]))); - AssertThrow((grad_q[ind_k[0]][ind_k[1]] == Tensor<1, dim>()), + AssertThrow(grad_q[ind_k[0]][ind_k[1]].norm() < 1e-11, ExcInternalError()); } } @@ -190,7 +192,8 @@ test(const Triangulation &tr, const FiniteElement &fe) for (unsigned int j = 0; j < dim; ++j) div_tmp += grad_q[i][j][j]; - AssertThrow(div_tmp == div_q[i], ExcInternalError()); + AssertThrow(std::abs(div_tmp - div_q[i]) < 1e-11, + ExcInternalError()); } } } @@ -198,9 +201,12 @@ test(const Triangulation &tr, const FiniteElement &fe) // compare function values/gradients/divergences: for (unsigned int q = 0; q < quadrature.size(); ++q) { - AssertThrow(values_manual[q] == values[q], ExcInternalError()); - AssertThrow(gradients_manual[q] == gradients[q], ExcInternalError()); - AssertThrow(divergences_manual[q] == divergences[q], ExcInternalError()); + AssertThrow((values_manual[q] - values[q]).norm() < 1e-12, + ExcInternalError()); + AssertThrow((gradients_manual[q] - gradients[q]).norm() < 1e-11, + ExcInternalError()); + AssertThrow((divergences_manual[q] - divergences[q]).norm() < 1e-11, + ExcInternalError()); } } -- 2.39.5