Skip to content

Commit ddc2cd5

Browse files
committed
Fix unit tests by reducing precision of comparison
1 parent d17e09d commit ddc2cd5

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

src/Interface/Modules/Render/Tests/ObjectRotationTests.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,13 @@ TEST_F(RotationTest, CanRotateArbitraryFromArbitrary)
126126

127127
auto t = rotator.computeTransform(25, -42);
128128

129-
//std::cout << std::setprecision(16) << t.transform << std::endl;
130-
131129
glm::mat4 expected;
132130
expected[0] = glm::vec4{0.9994457364082336, -0.003830079222097993, 0.03306873887777328, 0};
133131
expected[1] = glm::vec4{0.002393543953076005, 0.9990561604499817, 0.04337168484926224, 0};
134132
expected[2] = glm::vec4{-0.03320364654064178, -0.04326849430799484, 0.9985115528106689, 0};
135133
expected[3] = glm::vec4{0.09537804126739502, 0.1355232000350952, -0.1153466701507568, 1};
136134

137-
EXPECT_TRUE(t.transform == expected);
135+
//std::cout << std::setprecision(16) << t.transform << std::endl << expected << std::endl;
136+
137+
EXPECT_TRUE(epsilonEqual(t.transform, expected, 1e-5));
138138
}

src/Interface/Modules/Render/Tests/ObjectTransformationHelper.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ namespace SCIRun
5454
glm::mat4 getStaticCameraViewProjection() override { return {}; }
5555
};
5656

57-
bool operator==(const glm::mat4& lhs, const glm::mat4& rhs);
57+
bool operator==(const glm::mat4& lhs, const glm::mat4& rhs);
58+
bool epsilonEqual(const glm::mat4& lhs, const glm::mat4& rhs, float epsilon);
5859
}
5960
}
6061

src/Interface/Modules/Render/Tests/ObjectTranslationTests.cc

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828

2929
#include <gtest/gtest.h>
3030
#include <Interface/Modules/Render/Tests/ObjectTransformationHelper.h>
31+
#include <glm/gtc/epsilon.hpp>
32+
#include <glm/gtc/matrix_access.hpp>
3133

3234
using namespace SCIRun;
3335
using namespace Render;
@@ -70,7 +72,15 @@ TEST_F(TranslationTest, CanConstruct)
7072

7173
bool SCIRun::RenderTesting::operator==(const glm::mat4& lhs, const glm::mat4& rhs)
7274
{
73-
return lhs[0] == rhs[0] && lhs[1] == rhs[1] && lhs[2] == rhs[2] && lhs[3] == rhs[3];
75+
static const float epsilon = 1e-6f;
76+
return epsilonEqual(lhs, rhs, epsilon);
77+
}
78+
79+
bool SCIRun::RenderTesting::epsilonEqual(const glm::mat4& lhs, const glm::mat4& rhs, float epsilon)
80+
{
81+
auto indexes = {0,1,2,3};
82+
return std::all_of(std::begin(indexes), std::end(indexes),
83+
[&](int i) { return glm::all(glm::epsilonEqual(glm::row(lhs, i), glm::row(rhs, i), epsilon)); });
7484
}
7585

7686
TEST_F(TranslationTest, CanTranslateHorizontalFromOrigin)

0 commit comments

Comments
 (0)