Skip to content

Commit

Permalink
#5576: Add a few quick unit tests targeting the hash helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Apr 5, 2021
1 parent cef901e commit 8aada47
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions test/Models.cpp
@@ -1,5 +1,6 @@
#include "RadiantTest.h"

#include <unordered_set>
#include "imodelsurface.h"
#include "imodelcache.h"

Expand Down Expand Up @@ -332,4 +333,40 @@ TEST_F(AseImportTest, VertexNormalTransformation)
expectVertexWithNormal(model->getSurface(0), Vertex3f(-0.140900001, -0.745599985, 0.331900001), Normal3f(-0.998054981, -0.00000000, 0.0623391047));
}


TEST_F(AseImportTest, VertexHashFunction)
{
// Construct two mesh vertices which should be considered equal
ArbitraryMeshVertex vertex1(Vertex3f(-0.0218, -0.7449, 2.2385), Normal3f(-0.8698, 0, -0.493405),
TexCoord2f(0.9808, 0.8198), Vector3(1, 1, 1));

ArbitraryMeshVertex vertex2(Vertex3f(-0.0218, -0.7434, 2.2385), Normal3f(-0.872, 0, -0.489505),
TexCoord2f(0.9808, 0.8198), Vector3(1, 1, 1));

// Construct a that is differing in the normal part
ArbitraryMeshVertex vertex3(Vertex3f(-0.0218, -0.7434, 2.2385), Normal3f(-1, 0, 0),
TexCoord2f(0.9808, 0.8198), Vector3(1, 1, 1));

// Check the hash behaviour
std::hash<ArbitraryMeshVertex> hasher;
EXPECT_EQ(hasher(vertex1), hasher(vertex2));
EXPECT_EQ(hasher(vertex1), hasher(vertex3));

std::equal_to<ArbitraryMeshVertex> equalityComparer;
EXPECT_TRUE(equalityComparer(vertex1, vertex2));
EXPECT_FALSE(equalityComparer(vertex1, vertex3));

// With the included hash specialisations from render/VertexHashing.h, the two vertices should be considered equal
std::unordered_set<ArbitraryMeshVertex> set;

// Insert the first vertex
EXPECT_TRUE(set.insert(vertex1).second);

// Inserting the second vertex should fail
EXPECT_FALSE(set.insert(vertex2).second);

// Inserting the third vertex should succeed
EXPECT_TRUE(set.insert(vertex3).second);
}

}

0 comments on commit 8aada47

Please sign in to comment.