Mesh: add unit tests
This commit is contained in:
@@ -108,7 +108,7 @@ MeshKDTree::~MeshKDTree()
|
||||
delete d;
|
||||
}
|
||||
|
||||
void MeshKDTree::AddPoint(Base::Vector3f& point)
|
||||
void MeshKDTree::AddPoint(const Base::Vector3f& point)
|
||||
{
|
||||
PointIndex index=d->kd_tree.size();
|
||||
d->kd_tree.insert(Point3d(point, index));
|
||||
|
||||
@@ -37,7 +37,7 @@ public:
|
||||
explicit MeshKDTree(const MeshPointArray& points);
|
||||
~MeshKDTree();
|
||||
|
||||
void AddPoint(Base::Vector3f& point);
|
||||
void AddPoint(const Base::Vector3f& point);
|
||||
void AddPoints(const std::vector<Base::Vector3f>& points);
|
||||
void AddPoints(const MeshPointArray& points);
|
||||
|
||||
|
||||
@@ -66,7 +66,9 @@ function(setup_qt_test)
|
||||
endfunction()
|
||||
|
||||
add_executable(Tests_run)
|
||||
add_executable(Mesh_tests_run)
|
||||
add_executable(Part_tests_run)
|
||||
add_executable(Points_tests_run)
|
||||
add_subdirectory(lib)
|
||||
add_subdirectory(src)
|
||||
target_include_directories(Tests_run PUBLIC
|
||||
|
||||
@@ -1 +1,3 @@
|
||||
add_subdirectory(Mesh)
|
||||
add_subdirectory(Part)
|
||||
add_subdirectory(Points)
|
||||
|
||||
6
tests/src/Mod/Mesh/App/CMakeLists.txt
Normal file
6
tests/src/Mod/Mesh/App/CMakeLists.txt
Normal file
@@ -0,0 +1,6 @@
|
||||
target_sources(
|
||||
Mesh_tests_run
|
||||
PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Core/KDTree.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Mesh.cpp
|
||||
)
|
||||
91
tests/src/Mod/Mesh/App/Core/KDTree.cpp
Normal file
91
tests/src/Mod/Mesh/App/Core/KDTree.cpp
Normal file
@@ -0,0 +1,91 @@
|
||||
#include "gtest/gtest.h"
|
||||
#include <Mod/Mesh/App/Core/KDTree.h>
|
||||
|
||||
// NOLINTBEGIN(cppcoreguidelines-*,readability-*)
|
||||
|
||||
class KDTreeTest: public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
void SetUp() override
|
||||
{
|
||||
points.emplace_back(0, 0, 0);
|
||||
points.emplace_back(0, 0, 1);
|
||||
points.emplace_back(0, 1, 0);
|
||||
points.emplace_back(0, 1, 1);
|
||||
points.emplace_back(1, 0, 0);
|
||||
points.emplace_back(1, 0, 1);
|
||||
points.emplace_back(1, 1, 0);
|
||||
points.emplace_back(1, 1, 1);
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{}
|
||||
|
||||
const std::vector<Base::Vector3f>& GetPoints() const
|
||||
{
|
||||
return points;
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<Base::Vector3f> points;
|
||||
};
|
||||
|
||||
TEST_F(KDTreeTest, TestKDTreeEmpty)
|
||||
{
|
||||
MeshCore::MeshKDTree tree;
|
||||
EXPECT_EQ(tree.IsEmpty(), true);
|
||||
}
|
||||
|
||||
TEST_F(KDTreeTest, TestKDTreeNearestEmpty)
|
||||
{
|
||||
MeshCore::MeshKDTree tree;
|
||||
|
||||
Base::Vector3f pnt;
|
||||
Base::Vector3f nor;
|
||||
float dist;
|
||||
EXPECT_EQ(tree.FindNearest(pnt, nor, dist), MeshCore::POINT_INDEX_MAX);
|
||||
}
|
||||
|
||||
TEST_F(KDTreeTest, TestKDTreeNearest)
|
||||
{
|
||||
MeshCore::MeshKDTree tree;
|
||||
tree.AddPoints(GetPoints());
|
||||
EXPECT_EQ(tree.IsEmpty(), false);
|
||||
|
||||
Base::Vector3f nor;
|
||||
float dist;
|
||||
EXPECT_EQ(tree.FindNearest(Base::Vector3f(0.9F, 0.1F, 0.1F), nor, dist), 4);
|
||||
}
|
||||
|
||||
TEST_F(KDTreeTest, TestKDTreeNearestMaxDist)
|
||||
{
|
||||
MeshCore::MeshKDTree tree;
|
||||
tree.AddPoints(GetPoints());
|
||||
EXPECT_EQ(tree.IsEmpty(), false);
|
||||
|
||||
Base::Vector3f nor;
|
||||
float dist;
|
||||
EXPECT_EQ(tree.FindNearest(Base::Vector3f(0.9F, 0.1F, 0.1F), 0.0F, nor, dist),
|
||||
MeshCore::POINT_INDEX_MAX);
|
||||
}
|
||||
|
||||
TEST_F(KDTreeTest, TestKDTreeFindExact)
|
||||
{
|
||||
MeshCore::MeshKDTree tree;
|
||||
tree.AddPoints(GetPoints());
|
||||
|
||||
EXPECT_EQ(tree.FindExact(Base::Vector3f(0.1F, 0, 0)), MeshCore::POINT_INDEX_MAX);
|
||||
EXPECT_EQ(tree.FindExact(Base::Vector3f(0, 0, 0)), 0);
|
||||
}
|
||||
|
||||
TEST_F(KDTreeTest, TestKDTreeFindRange)
|
||||
{
|
||||
MeshCore::MeshKDTree tree;
|
||||
tree.AddPoints(GetPoints());
|
||||
|
||||
std::vector<MeshCore::PointIndex> index;
|
||||
std::vector<MeshCore::PointIndex> result = {0, 4};
|
||||
tree.FindInRange(Base::Vector3f(0.5F, 0, 0), 0.6F, index);
|
||||
EXPECT_EQ(index, result);
|
||||
}
|
||||
// NOLINTEND(cppcoreguidelines-*,readability-*)
|
||||
21
tests/src/Mod/Mesh/App/Mesh.cpp
Normal file
21
tests/src/Mod/Mesh/App/Mesh.cpp
Normal file
@@ -0,0 +1,21 @@
|
||||
#include "gtest/gtest.h"
|
||||
#include <Mod/Mesh/App/Mesh.h>
|
||||
|
||||
// NOLINTBEGIN(cppcoreguidelines-*,readability-*)
|
||||
TEST(MeshTest, TestDefault)
|
||||
{
|
||||
MeshCore::MeshKernel kernel;
|
||||
Base::Vector3f p1 {
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
};
|
||||
Base::Vector3f p2 {0, 0, 1};
|
||||
Base::Vector3f p3 {0, 1, 0};
|
||||
kernel.AddFacet(MeshCore::MeshGeomFacet(p1, p2, p3));
|
||||
|
||||
EXPECT_EQ(kernel.CountPoints(), 3);
|
||||
EXPECT_EQ(kernel.CountEdges(), 3);
|
||||
EXPECT_EQ(kernel.CountFacets(), 1);
|
||||
}
|
||||
// NOLINTEND(cppcoreguidelines-*,readability-*)
|
||||
15
tests/src/Mod/Mesh/CMakeLists.txt
Normal file
15
tests/src/Mod/Mesh/CMakeLists.txt
Normal file
@@ -0,0 +1,15 @@
|
||||
|
||||
target_include_directories(Mesh_tests_run PUBLIC
|
||||
${EIGEN3_INCLUDE_DIR}
|
||||
${OCC_INCLUDE_DIR}
|
||||
${Python3_INCLUDE_DIRS}
|
||||
${XercesC_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
target_link_libraries(Mesh_tests_run
|
||||
gtest_main
|
||||
${Google_Tests_LIBS}
|
||||
Mesh
|
||||
)
|
||||
|
||||
add_subdirectory(App)
|
||||
Reference in New Issue
Block a user