Skip to content

Commit

Permalink
add statement of need
Browse files Browse the repository at this point in the history
  • Loading branch information
schuhmaj committed May 8, 2024
1 parent 6c42716 commit 675a1e4
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions test/model/GoogleTestMatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,17 @@

#include "gtest/gtest.h"
#include "gmock/gmock.h"
#include "polyhedralGravity/util/UtilityFloatArithmetic.h"

/*
* This file provides several matchers to be used with ASSERT_TAHT(..) statements for multi-dimensional containers
* with flotaing points as content.
* GoogleTest provides matchers like DoubleNear(..), ContainerEq(..) and Pointwise(..). These work great when working
* with 1D containers. However, there is a lack of these matchers for multi-dimensional containers.
* This files provides Matcher for comparing nested containers with floating points where the comparison is
* conducted with an epsilon to counter the effect of potential rounding erros due to floating point arithmetic.
*/

#include "polyhedralGravity/util/UtilityFloatArithmetic.h"

MATCHER_P(FloatContainter1D, container, "Comparing 1D Containers") {
if (container.size() != arg.size()) {
Expand All @@ -13,7 +21,9 @@ MATCHER_P(FloatContainter1D, container, "Comparing 1D Containers") {
}
for (size_t idx = 0; idx < std::size(container); ++idx) {
if (!polyhedralGravity::util::almostEqualRelative(container[idx], arg[idx])) {
*result_listener << "The elements at idx = " << idx << " do not match. Values: " << container[idx]<< " != " << arg[idx];
*result_listener
<< "The elements at idx = " << idx << " do not match. Values: "
<< container[idx] << " != " << arg[idx];
return false;
}
}
Expand All @@ -29,12 +39,16 @@ MATCHER_P(FloatContainter2D, container, "Comparing 2D Containers") {
}
for (size_t idx = 0; idx < std::size(container); ++idx) {
if (container[idx].size() != arg[idx].size()) {
*result_listener << "The container sizes at idx = " << idx << " do not match. Sizes: " << container[idx].size() << " != " << arg[idx].size();
*result_listener
<< "The container sizes at idx = " << idx << " do not match. Sizes: "
<< container[idx].size() << " != " << arg[idx].size();
return false;
}
for (size_t idy = 0; idy < std::size(container[idx]); ++idy) {
if (!polyhedralGravity::util::almostEqualRelative(container[idx][idy], arg[idx][idy])) {
*result_listener << "The elements at idx = " << idx << " and idy = " << idy << " do not match. Values: " << container[idx][idy] << " != " << arg[idx][idy];
*result_listener
<< "The elements at idx = " << idx << " and idy = " << idy << " do not match. Values: "
<< container[idx][idy] << " != " << arg[idx][idy];
return false;
}
}
Expand All @@ -51,17 +65,23 @@ MATCHER_P(FloatContainter3D, container, "Comparing 3D Containers") {
}
for (size_t idx = 0; idx < std::size(container); ++idx) {
if (container[idx].size() != arg[idx].size()) {
*result_listener << "The container sizes at idx = " << idx << " do not match. Sizes: " << container[idx].size() << " != " << arg[idx].size();
*result_listener
<< "The container sizes at idx = " << idx << " do not match. Sizes: "
<< container[idx].size() << " != " << arg[idx].size();
return false;
}
for (size_t idy = 0; idy < std::size(container[idx]); ++idy) {
if (container[idx][idy].size() != arg[idx][idy].size()) {
*result_listener << "The container sizes at idx = " << idx << " do not match. Sizes: " << container[idx].size() << " != " << arg[idx].size();
*result_listener
<< "The container sizes at idx = " << idx << " do not match. Sizes: "
<< container[idx].size() << " != " << arg[idx].size();
return false;
}
for (size_t idz = 0; idz < std::size(container[idx][idy]); ++idz) {
if (!polyhedralGravity::util::almostEqualRelative(container[idx][idy][idz], arg[idx][idy][idz])) {
*result_listener << "The elements at idx = " << idx << " and idy = " << idy << " and idz = " << idz << " do not match. Values: " << container[idx][idy][idz] << " != " << arg[idx][idy][idz];
*result_listener
<< "The elements at idx = " << idx << " and idy = " << idy << " and idz = " << idz << " do not match. Values: "
<< container[idx][idy][idz] << " != " << arg[idx][idy][idz];
return false;
}
}
Expand Down

0 comments on commit 675a1e4

Please sign in to comment.