Tests/Toponaming: Post-merge cleanup

This commit is contained in:
Chris Hennes
2024-01-27 10:49:59 -06:00
parent 88b5191b5e
commit e24ed34867
9 changed files with 190 additions and 209 deletions

View File

@@ -15,7 +15,6 @@ target_sources(
${CMAKE_CURRENT_SOURCE_DIR}/TopoShape.cpp
${CMAKE_CURRENT_SOURCE_DIR}/TopoShapeCache.cpp
${CMAKE_CURRENT_SOURCE_DIR}/TopoShapeExpansion.cpp
${CMAKE_CURRENT_SOURCE_DIR}/TopoShapeExpansionHelpers.cpp
${CMAKE_CURRENT_SOURCE_DIR}/TopoShapeMakeShapeWithElementMap.cpp
${CMAKE_CURRENT_SOURCE_DIR}/TopoShapeMapper.cpp
)

View File

@@ -1,5 +1,7 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
#include <BRepPrimAPI_MakeBox.hxx>
#include "PartTestHelpers.h"
// NOLINTBEGIN(readability-magic-numbers,cppcoreguidelines-avoid-magic-numbers)
@@ -137,6 +139,22 @@ std::map<IndexedName, MappedName> elementMap(const TopoShape& shape)
return result;
}
std::pair<TopoDS_Shape, TopoDS_Shape> CreateTwoCubes()
{
auto boxMaker1 = BRepPrimAPI_MakeBox(1.0, 1.0, 1.0);
boxMaker1.Build();
auto box1 = boxMaker1.Shape();
auto boxMaker2 = BRepPrimAPI_MakeBox(1.0, 1.0, 1.0);
boxMaker2.Build();
auto box2 = boxMaker2.Shape();
auto transform = gp_Trsf();
transform.SetTranslation(gp_Pnt(0.0, 0.0, 0.0), gp_Pnt(1.0, 0.0, 0.0));
box2.Location(TopLoc_Location(transform));
return {box1, box2};
}
} // namespace PartTestHelpers
// NOLINTEND(readability-magic-numbers,cppcoreguidelines-avoid-magic-numbers)

View File

@@ -57,4 +57,6 @@ boxesMatch(const Base::BoundBox3d& b1, const Base::BoundBox3d& b2, double prec =
std::map<IndexedName, MappedName> elementMap(const TopoShape& shape);
std::pair<TopoDS_Shape, TopoDS_Shape> CreateTwoCubes();
} // namespace PartTestHelpers

View File

@@ -2,23 +2,21 @@
#include "gtest/gtest.h"
#include "src/App/InitApplication.h"
#include "TopoShapeExpansionHelpers.h"
#include <Mod/Part/App/TopoShape.h>
#include <Mod/Part/App/TopoShapeOpCode.h>
#include "PartTestHelpers.h"
#include <BRepBuilderAPI_MakeEdge.hxx>
#include <BRepBuilderAPI_MakeFace.hxx>
#include <BRepBuilderAPI_MakeWire.hxx>
#include <BRepPrimAPI_MakeBox.hxx>
#include <GC_MakeCircle.hxx>
#include <TopExp_Explorer.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Edge.hxx>
// NOLINTBEGIN(readability-magic-numbers,cppcoreguidelines-avoid-magic-numbers)
using namespace PartTestHelpers;
class TopoShapeExpansionTest: public ::testing::Test
{
@@ -32,7 +30,6 @@ protected:
{
_docName = App::GetApplication().getUniqueDocumentName("test");
App::GetApplication().newDocument(_docName.c_str(), "testUser");
_sids = &_sid;
_hasher = Base::Reference<App::StringHasher>(new App::StringHasher);
ASSERT_EQ(_hasher.getRefCount(), 1);
}
@@ -46,7 +43,6 @@ protected:
private:
std::string _docName;
Data::ElementIDRefs _sid;
QVector<App::StringIDRef>* _sids = nullptr;
App::StringHasherRef _hasher;
};
@@ -129,7 +125,7 @@ TEST_F(TopoShapeExpansionTest, makeElementCompoundTwoShapesGeneratesMap)
TEST_F(TopoShapeExpansionTest, makeElementCompoundTwoCubes)
{
// Arrange
auto [cube1, cube2] = TopoShapeExpansionHelpers::CreateTwoCubes();
auto [cube1, cube2] = CreateTwoCubes();
Part::TopoShape cube1TS {cube1};
cube1TS.Tag = 1;
Part::TopoShape cube2TS {cube2};
@@ -150,42 +146,20 @@ TEST_F(TopoShapeExpansionTest, makeElementCompoundTwoCubes)
// 26 subshapes each
}
std::tuple<TopoDS_Face, TopoDS_Wire, TopoDS_Edge, TopoDS_Edge, TopoDS_Edge, TopoDS_Edge>
CreateRectFace(float len = 2.0, float wid = 3.0)
{
auto edge1 = BRepBuilderAPI_MakeEdge(gp_Pnt(0.0, 0.0, 0.0), gp_Pnt(len, 0.0, 0.0)).Edge();
auto edge2 = BRepBuilderAPI_MakeEdge(gp_Pnt(len, 0.0, 0.0), gp_Pnt(len, wid, 0.0)).Edge();
auto edge3 = BRepBuilderAPI_MakeEdge(gp_Pnt(len, wid, 0.0), gp_Pnt(0.0, wid, 0.0)).Edge();
auto edge4 = BRepBuilderAPI_MakeEdge(gp_Pnt(0.0, wid, 0.0), gp_Pnt(0.0, 0.0, 0.0)).Edge();
auto wire1 = BRepBuilderAPI_MakeWire({edge1, edge2, edge3, edge4}).Wire();
auto face1 = BRepBuilderAPI_MakeFace(wire1).Face();
return {face1, wire1, edge1, edge2, edge3, edge4};
}
std::tuple<TopoDS_Face, TopoDS_Wire, TopoDS_Wire>
CreateFaceWithRoundHole(float len = 2.0, float wid = 3.0, float radius = 1.0)
{
auto [face1, wire1, edge1, edge2, edge3, edge4] = CreateRectFace(len, wid);
auto circ1 =
GC_MakeCircle(gp_Pnt(len / 2.0, wid / 2.0, 0), gp_Dir(0.0, 0.0, 1.0), radius).Value();
auto edge5 = BRepBuilderAPI_MakeEdge(circ1).Edge();
auto wire2 = BRepBuilderAPI_MakeWire(edge5).Wire();
auto face2 = BRepBuilderAPI_MakeFace(face1, wire2).Face();
return {face2, wire1, wire2};
}
TEST_F(TopoShapeExpansionTest, makeElementFaceNull)
{
// Arrange
const double Len = 3, Wid = 2, Rad = 1;
const float Len = 3;
const float Wid = 2;
const float Rad = 1;
auto [face1, wire1, wire2] = CreateFaceWithRoundHole(Len, Wid, Rad);
Part::TopoShape topoShape {face1};
double area = PartTestHelpers::getArea(face1);
double area1 = PartTestHelpers::getArea(topoShape.getShape());
double area = getArea(face1);
double area1 = getArea(topoShape.getShape());
// Act
Part::TopoShape newFace = topoShape.makeElementFace(nullptr);
double area2 = PartTestHelpers::getArea(newFace.getShape());
double area3 = PartTestHelpers::getArea(topoShape.getShape());
double area2 = getArea(newFace.getShape());
double area3 = getArea(topoShape.getShape());
// Assert
EXPECT_FALSE(face1.IsEqual(newFace.getShape()));
EXPECT_FLOAT_EQ(area, Len * Wid + M_PI * Rad * Rad);
@@ -198,15 +172,17 @@ TEST_F(TopoShapeExpansionTest, makeElementFaceNull)
TEST_F(TopoShapeExpansionTest, makeElementFaceSimple)
{
// Arrange
const double Len = 3, Wid = 2, Rad = 1;
const float Len = 3;
const float Wid = 2;
const float Rad = 1;
auto [face1, wire1, wire2] = CreateFaceWithRoundHole(Len, Wid, Rad);
Part::TopoShape topoShape {face1};
double area = PartTestHelpers::getArea(face1);
double area1 = PartTestHelpers::getArea(topoShape.getShape());
double area = getArea(face1);
double area1 = getArea(topoShape.getShape());
// Act
Part::TopoShape newFace = topoShape.makeElementFace(wire1);
double area2 = PartTestHelpers::getArea(newFace.getShape());
double area3 = PartTestHelpers::getArea(topoShape.getShape());
double area2 = getArea(newFace.getShape());
double area3 = getArea(topoShape.getShape());
// Assert
EXPECT_TRUE(newFace.getShape().IsEqual(topoShape.getShape())); // topoShape was altered
EXPECT_FALSE(face1.IsEqual(newFace.getShape()));
@@ -220,16 +196,18 @@ TEST_F(TopoShapeExpansionTest, makeElementFaceSimple)
TEST_F(TopoShapeExpansionTest, makeElementFaceParams)
{
// Arrange
const double Len = 3, Wid = 2, Rad = 1;
const float Len = 3;
const float Wid = 2;
const float Rad = 1;
auto [face1, wire1, wire2] = CreateFaceWithRoundHole(Len, Wid, Rad);
Part::TopoShape topoShape {face1, 1L};
double area = PartTestHelpers::getArea(face1);
double area1 = PartTestHelpers::getArea(topoShape.getShape());
double area = getArea(face1);
double area1 = getArea(topoShape.getShape());
// Act
Part::TopoShape newFace =
topoShape.makeElementFace(wire1, "Cut", "Part::FaceMakerBullseye", nullptr);
double area2 = PartTestHelpers::getArea(newFace.getShape());
double area3 = PartTestHelpers::getArea(topoShape.getShape());
double area2 = getArea(newFace.getShape());
double area3 = getArea(topoShape.getShape());
// Assert
EXPECT_TRUE(newFace.getShape().IsEqual(topoShape.getShape())); // topoShape was altered
EXPECT_FALSE(face1.IsEqual(newFace.getShape()));
@@ -243,16 +221,18 @@ TEST_F(TopoShapeExpansionTest, makeElementFaceParams)
TEST_F(TopoShapeExpansionTest, makeElementFaceFromFace)
{
// Arrange
const double Len = 3, Wid = 2, Rad = 1;
const float Len = 3;
const float Wid = 2;
const float Rad = 1;
auto [face1, wire1, wire2] = CreateFaceWithRoundHole(Len, Wid, Rad);
Part::TopoShape topoShape {face1, 1L};
double area = PartTestHelpers::getArea(face1);
double area1 = PartTestHelpers::getArea(topoShape.getShape());
double area = getArea(face1);
double area1 = getArea(topoShape.getShape());
// Act
Part::TopoShape newFace =
topoShape.makeElementFace(face1, "Cut", "Part::FaceMakerBullseye", nullptr);
double area2 = PartTestHelpers::getArea(newFace.getShape());
double area3 = PartTestHelpers::getArea(topoShape.getShape());
double area2 = getArea(newFace.getShape());
double area3 = getArea(topoShape.getShape());
// Assert
EXPECT_TRUE(newFace.getShape().IsEqual(topoShape.getShape())); // topoShape was altered
EXPECT_FALSE(face1.IsEqual(newFace.getShape()));
@@ -267,15 +247,17 @@ TEST_F(TopoShapeExpansionTest, makeElementFaceFromFace)
TEST_F(TopoShapeExpansionTest, makeElementFaceOpenWire)
{
// Arrange
const double Len = 3, Wid = 2, Rad = 1;
const float Len = 3;
const float Wid = 2;
const float Rad = 1;
auto [face1, wire1, wire2] = CreateFaceWithRoundHole(Len, Wid, Rad);
Part::TopoShape topoShape {wire1, 1L};
double area = PartTestHelpers::getArea(face1);
double area1 = PartTestHelpers::getArea(topoShape.getShape());
double area = getArea(face1);
double area1 = getArea(topoShape.getShape());
// Act
Part::TopoShape newFace = topoShape.makeElementFace(wire1, "Cut", nullptr, nullptr);
double area2 = PartTestHelpers::getArea(newFace.getShape());
double area3 = PartTestHelpers::getArea(topoShape.getShape());
double area2 = getArea(newFace.getShape());
double area3 = getArea(topoShape.getShape());
// Assert
EXPECT_TRUE(newFace.getShape().IsEqual(topoShape.getShape())); // topoShape was altered
EXPECT_FALSE(face1.IsEqual(newFace.getShape()));
@@ -290,16 +272,18 @@ TEST_F(TopoShapeExpansionTest, makeElementFaceOpenWire)
TEST_F(TopoShapeExpansionTest, makeElementFaceClosedWire)
{
// Arrange
const double Len = 3, Wid = 2, Rad = 1;
const float Len = 3;
const float Wid = 2;
const float Rad = 1;
auto [face1, wire1, wire2] = CreateFaceWithRoundHole(Len, Wid, Rad);
Part::TopoShape topoShape {wire2, 1L};
double area = PartTestHelpers::getArea(face1);
double area1 = PartTestHelpers::getArea(topoShape.getShape());
double area = getArea(face1);
double area1 = getArea(topoShape.getShape());
// Act
Part::TopoShape newFace =
topoShape.makeElementFace(wire2, "Cut", "Part::FaceMakerBullseye", nullptr);
double area2 = PartTestHelpers::getArea(newFace.getShape());
double area3 = PartTestHelpers::getArea(topoShape.getShape());
double area2 = getArea(newFace.getShape());
double area3 = getArea(topoShape.getShape());
// Assert
EXPECT_TRUE(newFace.getShape().IsEqual(topoShape.getShape())); // topoShape was altered
EXPECT_FALSE(face1.IsEqual(newFace.getShape()));
@@ -395,7 +379,9 @@ TEST_F(TopoShapeExpansionTest, setElementComboNameCompound)
TEST_F(TopoShapeExpansionTest, splitWires)
{
// Arrange
const double Len = 3, Wid = 2, Rad = 1;
const float Len = 3;
const float Wid = 2;
const float Rad = 1;
auto [face1, wire1, wire2] = CreateFaceWithRoundHole(Len, Wid, Rad);
Part::TopoShape topoShape {face1, 1L};
std::vector<Part::TopoShape> inner;
@@ -405,8 +391,8 @@ TEST_F(TopoShapeExpansionTest, splitWires)
topoShape.splitWires(&inner, Part::TopoShape::SplitWireReorient::ReorientReversed);
// Assert
EXPECT_EQ(inner.size(), 1);
EXPECT_FLOAT_EQ(PartTestHelpers::getLength(wire.getShape()), 2 + 2 + 3 + 3);
EXPECT_FLOAT_EQ(PartTestHelpers::getLength(inner.front().getShape()), M_PI * Rad * 2);
EXPECT_FLOAT_EQ(getLength(wire.getShape()), 2 + 2 + 3 + 3);
EXPECT_FLOAT_EQ(getLength(inner.front().getShape()), M_PI * Rad * 2);
EXPECT_EQ(wire.getShape().Orientation(), TopAbs_REVERSED);
for (Part::TopoShape& shape : inner) {
EXPECT_EQ(shape.getShape().Orientation(), TopAbs_FORWARD);
@@ -415,8 +401,8 @@ TEST_F(TopoShapeExpansionTest, splitWires)
// Possible future tests:
// splitWires without inner Wires
// splitWires with allfour reorientation values NoReorient, ReOrient, ReorientForward,
// ReorientRevesed
// splitWires with all four reorientation values NoReorient, ReOrient, ReorientForward,
// ReorientReversed
TEST_F(TopoShapeExpansionTest, mapSubElementInvalidParm)
{
@@ -442,7 +428,8 @@ TEST_F(TopoShapeExpansionTest, mapSubElementFindShapeByNames)
Part::TopoShape cube2TS {cube2};
cube1TS.Tag = 1;
cube2TS.Tag = 2;
Part::TopoShape topoShape, topoShape1;
Part::TopoShape topoShape;
Part::TopoShape topoShape1;
// Act
int fs1 = topoShape1.findShape(cube1);
@@ -527,8 +514,13 @@ TEST_F(TopoShapeExpansionTest, mapSubElementFindAncestors)
cube2TS.Tag = 2;
cube3TS.Tag = 3;
cube4TS.Tag = 4;
Part::TopoShape topoShape, topoShape1, topoShape2;
Part::TopoShape topoShape3, topoShape4, topoShape5, topoShape6;
Part::TopoShape topoShape;
Part::TopoShape topoShape1;
Part::TopoShape topoShape2;
Part::TopoShape topoShape3;
Part::TopoShape topoShape4;
Part::TopoShape topoShape5;
Part::TopoShape topoShape6;
topoShape.makeElementCompound({cube1TS, cube2TS});
topoShape1.makeElementCompound({cube3TS, cube4TS});
topoShape2.makeElementCompound({cube1TS, cube3TS});
@@ -576,7 +568,8 @@ TEST_F(TopoShapeExpansionTest, makeElementShellInvalid)
TEST_F(TopoShapeExpansionTest, makeElementShellSingle)
{
// Arrange
const double Len = 3, Wid = 2;
const float Len = 3;
const float Wid = 2;
auto [face1, wire1, edge1, edge2, edge3, _] = CreateRectFace(Len, Wid);
Part::TopoShape topoShape {face1, 1L};
// Act
@@ -594,7 +587,8 @@ TEST_F(TopoShapeExpansionTest, makeElementShellSingle)
TEST_F(TopoShapeExpansionTest, makeElementShellOpen)
{
// Arrange
const double Len = 3, Wid = 2;
const float Len = 3;
const float Wid = 2;
auto [face1, wire1, edge1, edge2, edge3, edge4] = CreateRectFace(Len, Wid);
auto transform {gp_Trsf()};
transform.SetRotation(gp_Ax1(gp_Pnt(0, 0, 0), gp_Dir(1, 0, 0)), M_PI / 2);
@@ -625,7 +619,7 @@ TEST_F(TopoShapeExpansionTest, makeElementShellClosed)
Part::TopoShape topoShape {cube1};
std::vector<Part::TopoShape> shapes;
for (const auto& face : topoShape.getSubShapes(TopAbs_FACE)) {
shapes.push_back(Part::TopoShape {face});
shapes.emplace_back(face);
}
// Act
Part::TopoShape topoShape1 {1L};
@@ -652,11 +646,11 @@ TEST_F(TopoShapeExpansionTest, makeElementShellIntersecting)
Part::TopoShape topoShape {cube1};
std::vector<Part::TopoShape> shapes;
for (const auto& face : topoShape.getSubShapes(TopAbs_FACE)) {
shapes.push_back(Part::TopoShape {face});
shapes.emplace_back(face);
}
topoShape.setShape(cube2);
for (const auto& face : topoShape.getSubShapes(TopAbs_FACE)) {
shapes.push_back(Part::TopoShape {face});
shapes.emplace_back(face);
}
// Act
Part::TopoShape topoShape1 {1L};

View File

@@ -1,26 +0,0 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
#include "TopoShapeExpansionHelpers.h"
#include <BRepPrimAPI_MakeBox.hxx>
namespace TopoShapeExpansionHelpers
{
std::pair<TopoDS_Shape, TopoDS_Shape> CreateTwoCubes()
{
auto boxMaker1 = BRepPrimAPI_MakeBox(1.0, 1.0, 1.0);
boxMaker1.Build();
auto box1 = boxMaker1.Shape();
auto boxMaker2 = BRepPrimAPI_MakeBox(1.0, 1.0, 1.0);
boxMaker2.Build();
auto box2 = boxMaker2.Shape();
auto transform = gp_Trsf();
transform.SetTranslation(gp_Pnt(0.0, 0.0, 0.0), gp_Pnt(1.0, 0.0, 0.0));
box2.Location(TopLoc_Location(transform));
return {box1, box2};
}
} // namespace TopoShapeExpansionHelpers

View File

@@ -1,13 +0,0 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
#ifndef FREECAD_TOPOSHAPEEXPANSIONHELPERS_H
#define FREECAD_TOPOSHAPEEXPANSIONHELPERS_H
#include <TopoDS_Shape.hxx>
namespace TopoShapeExpansionHelpers
{
std::pair<TopoDS_Shape, TopoDS_Shape> CreateTwoCubes();
}
#endif // FREECAD_TOPOSHAPEEXPANSIONHELPERS_H

View File

@@ -5,7 +5,7 @@
#include "gtest/gtest.h"
#include "src/App/InitApplication.h"
#include "TopoShapeExpansionHelpers.h"
#include "PartTestHelpers.h"
#include <Mod/Part/App/TopoShape.h>
#include <Mod/Part/App/TopoShapeOpCode.h>
// #include <MappedName.h>
@@ -34,7 +34,6 @@ protected:
{
_docName = App::GetApplication().getUniqueDocumentName("test");
App::GetApplication().newDocument(_docName.c_str(), "testUser");
_sids = &_sid;
}
void TearDown() override
@@ -52,10 +51,12 @@ protected:
return &_mapper;
}
void testFindSourceSubShapesInElementMapForSource(const std::vector<TopoShape>& sources,
const TopoShape& source);
private:
std::string _docName;
Data::ElementIDRefs _sid;
QVector<App::StringIDRef>* _sids = nullptr;
Part::TopoShape _shape;
Part::TopoShape::Mapper _mapper;
};
@@ -63,7 +64,7 @@ private:
TEST_F(TopoShapeMakeShapeWithElementMapTests, nullShapeThrows)
{
// Arrange
auto [cube1, cube2] = TopoShapeExpansionHelpers::CreateTwoCubes();
auto [cube1, cube2] = PartTestHelpers::CreateTwoCubes();
std::vector<Part::TopoShape> sources {cube1, cube2};
TopoDS_Vertex nullVertex;
TopoDS_Edge nullEdge;
@@ -96,11 +97,11 @@ TEST_F(TopoShapeMakeShapeWithElementMapTests, nullShapeThrows)
using Data::IndexedName, Data::MappedName;
using Part::TopoShape;
std::map<IndexedName, MappedName> elementMap(const TopoShape &shape)
std::map<IndexedName, MappedName> elementMap(const TopoShape& shape)
{
std::map<IndexedName, MappedName> result {};
auto elements = shape.getElementMap();
for (auto const & entry : elements) {
for (auto const& entry : elements) {
result[entry.index] = entry.name;
}
return result;
@@ -116,7 +117,7 @@ std::map<IndexedName, MappedName> elementMap(const TopoShape &shape)
TEST_F(TopoShapeMakeShapeWithElementMapTests, mapCompoundCount)
{
// Arrange
auto [cube1, cube2] = TopoShapeExpansionHelpers::CreateTwoCubes();
auto [cube1, cube2] = PartTestHelpers::CreateTwoCubes();
std::vector<TopoShape> sources {cube1, cube2};
sources[0].Tag = 1;
sources[1].Tag = 2;
@@ -127,7 +128,7 @@ TEST_F(TopoShapeMakeShapeWithElementMapTests, mapCompoundCount)
compound.makeShapeWithElementMap(compound.getShape(), *Mapper(), sources);
auto postElements = elementMap(compound); // Map after mapping
// Assert
EXPECT_EQ(preElements.size(), 52); // Check the before map.
EXPECT_EQ(preElements.size(), 52); // Check the before map.
EXPECT_EQ(postElements.size(), 52); // 12 Edges, 8 Vertexes, 6 Faces per each Cube
EXPECT_EQ(postElements.count(IndexedName("Edge", 24)), 1);
EXPECT_EQ(postElements.count(IndexedName("Edge", 25)), 0);
@@ -143,7 +144,7 @@ TEST_F(TopoShapeMakeShapeWithElementMapTests, mapCompoundCount)
TEST_F(TopoShapeMakeShapeWithElementMapTests, mapCompoundMap)
{
// Arrange
auto [cube1, cube2] = TopoShapeExpansionHelpers::CreateTwoCubes();
auto [cube1, cube2] = PartTestHelpers::CreateTwoCubes();
std::vector<TopoShape> sources {cube1, cube2};
sources[0].Tag = 1;
sources[1].Tag = 2;
@@ -165,7 +166,7 @@ TEST_F(TopoShapeMakeShapeWithElementMapTests, mapCompoundMap)
TEST_F(TopoShapeMakeShapeWithElementMapTests, emptySourceShapes)
{
// Arrange
auto [cube1, cube2] = TopoShapeExpansionHelpers::CreateTwoCubes();
auto [cube1, cube2] = PartTestHelpers::CreateTwoCubes();
std::vector<Part::TopoShape> emptySources;
std::vector<Part::TopoShape> nonEmptySources {cube1, cube2};
@@ -183,7 +184,7 @@ TEST_F(TopoShapeMakeShapeWithElementMapTests, emptySourceShapes)
TEST_F(TopoShapeMakeShapeWithElementMapTests, nonMappableSources)
{
// Arrange
auto [cube1, cube2] = TopoShapeExpansionHelpers::CreateTwoCubes();
auto [cube1, cube2] = PartTestHelpers::CreateTwoCubes();
std::vector<Part::TopoShape> sources {cube1, cube2};
// Act and assert
@@ -202,10 +203,34 @@ TEST_F(TopoShapeMakeShapeWithElementMapTests, nonMappableSources)
}
}
void testFindSourceShapesInSingleShape(const Part::TopoShape& cmpdShape,
const Part::TopoShape& source,
const std::vector<Part::TopoShape>& sources,
const TopoShape::Mapper& mapper)
{
std::vector<Part::TopoShape> tmpSources {source};
for (const auto& subSource : sources) {
Part::TopoShape tmpShape {source.getShape()};
tmpShape.makeShapeWithElementMap(source.getShape(), mapper, tmpSources);
if (&source == &subSource) {
EXPECT_NE(tmpShape.findShape(subSource.getShape()),
0); // if tmpShape uses, for example, cube1 and we search for cube1 than
// we should find it
}
else {
EXPECT_EQ(tmpShape.findShape(subSource.getShape()),
0); // if tmpShape uses, for example, cube1 and we search for cube2 than
// we shouldn't find it
}
}
EXPECT_NE(cmpdShape.findShape(source.getShape()),
0); // as cmpdShape is made with cube1 and cube2 we should find both of them
}
TEST_F(TopoShapeMakeShapeWithElementMapTests, findSourceShapesInShape)
{
// Arrange
auto [cube1, cube2] = TopoShapeExpansionHelpers::CreateTwoCubes();
auto [cube1, cube2] = PartTestHelpers::CreateTwoCubes();
std::vector<Part::TopoShape> sources {cube1, cube2};
sources[0].Tag = 1; // setting Tag explicitly otherwise it is likely that this test will be
// more or less the same of nonMappableSources
@@ -216,30 +241,69 @@ TEST_F(TopoShapeMakeShapeWithElementMapTests, findSourceShapesInShape)
// Act and assert
for (const auto& source : sources) {
std::vector<Part::TopoShape> tmpSources {source};
for (const auto& subSource : sources) {
Part::TopoShape tmpShape {source.getShape()};
tmpShape.makeShapeWithElementMap(source.getShape(), *Mapper(), tmpSources);
if (&source == &subSource) {
EXPECT_NE(tmpShape.findShape(subSource.getShape()),
0); // if tmpShape uses, for example, cube1 and we search for cube1 than
// we should find it
}
else {
EXPECT_EQ(tmpShape.findShape(subSource.getShape()),
0); // if tmpShape uses, for example, cube1 and we search for cube2 than
// we shouldn't find it
}
}
EXPECT_NE(cmpdShape.findShape(source.getShape()),
0); // as cmpdShape is made with cube1 and cube2 we should find both of them
testFindSourceShapesInSingleShape(cmpdShape, source, sources, *Mapper());
}
}
void testFindSubShapesForSourceWithTypeAndIndex(const std::string& shapeTypeStr,
std::map<IndexedName, MappedName>& elementStdMap,
unsigned long shapeIndex)
{
std::string shapeIndexStr = std::to_string(shapeIndex);
std::string shapeName {shapeTypeStr + shapeIndexStr};
IndexedName indexedName {shapeTypeStr.c_str(), (int)shapeIndex};
MappedName mappedName {elementStdMap[indexedName]};
const char shapeTypePrefix {indexedName.toString()[0]};
EXPECT_NO_THROW(elementStdMap.at(indexedName)); // We check that the IndexedName
// is one of the keys...
EXPECT_NE(mappedName.find(shapeName.c_str()),
-1); // ... that the element name is in the MappedName...
EXPECT_EQ(mappedName.toString().back(), shapeTypePrefix);
}
void testFindSubShapesForSourceWithType(const TopoShape& source,
const char* shapeType,
std::map<IndexedName, MappedName>& elementStdMap)
{
std::string shapeTypeStr {shapeType};
// ... and all the elements of the various types in the source TopoShape ...
for (unsigned long shapeIndex = 1U; shapeIndex <= source.countSubElements(shapeType);
shapeIndex++) {
testFindSubShapesForSourceWithTypeAndIndex(shapeTypeStr, elementStdMap, shapeIndex);
}
// ... we also check that we don't find shapes that don't exist and therefore don't
// have either an IndexedName or a MappedName
IndexedName fakeIndexedName {shapeTypeStr.c_str(), (int)source.countSubElements(shapeType) + 1};
EXPECT_THROW(elementStdMap.at(fakeIndexedName), std::out_of_range);
}
void TopoShapeMakeShapeWithElementMapTests::testFindSourceSubShapesInElementMapForSource(
const std::vector<TopoShape>& sources,
const TopoShape& source)
{
TopoShape tmpShape {source.getShape()};
tmpShape.makeShapeWithElementMap(source.getShape(), *Mapper(), sources);
// First we create a map with the IndexedNames and MappedNames
std::map<IndexedName, MappedName> elementStdMap;
for (const auto& mappedElement : tmpShape.getElementMap()) {
elementStdMap.emplace(mappedElement.index, mappedElement.name);
}
// Then for all the elements types (Vertex, Edge, Face) ...
for (const auto& shapeType : source.getElementTypes()) {
testFindSubShapesForSourceWithType(source, shapeType, elementStdMap);
}
}
TEST_F(TopoShapeMakeShapeWithElementMapTests, findSourceSubShapesInElementMap)
{
// Arrange
auto [cube1, cube2] = TopoShapeExpansionHelpers::CreateTwoCubes();
auto [cube1, cube2] = PartTestHelpers::CreateTwoCubes();
std::vector<TopoShape> sources {cube1, cube2};
sources[0].Tag = 1; // setting Tag explicitly otherwise it is likely that this test will be
// more or less the same of nonMappableSources
@@ -249,52 +313,14 @@ TEST_F(TopoShapeMakeShapeWithElementMapTests, findSourceSubShapesInElementMap)
// Act and assert
// Testing with all the source TopoShapes
for (const auto& source : sources) {
TopoShape tmpShape {source.getShape()};
tmpShape.makeShapeWithElementMap(source.getShape(), *Mapper(), sources);
// First we create a map with the IndexedNames and MappedNames
std::map<IndexedName, MappedName> elementStdMap;
for (const auto& mappedElement : tmpShape.getElementMap()) {
elementStdMap.emplace(mappedElement.index, mappedElement.name);
}
// Then for all the elements types (Vertex, Edge, Face) ...
for (const auto& shapeType : source.getElementTypes()) {
std::string shapeTypeStr {shapeType};
// ... and all the elements of the various types in the source TopoShape ...
for (unsigned long shapeIndex = 1U; shapeIndex <= source.countSubElements(shapeType);
shapeIndex++) {
std::string shapeIndexStr = std::to_string(shapeIndex);
std::string shapeName {shapeTypeStr + shapeIndexStr};
IndexedName indexedName {shapeTypeStr.c_str(), (int)shapeIndex};
MappedName mappedName {elementStdMap[indexedName]};
const char shapeTypePrefix[1] {indexedName.toString()[0]};
EXPECT_NO_THROW(elementStdMap.at(indexedName)); // .. we check that the IndexedName
// is one of the keys...
EXPECT_NE(mappedName.find(shapeName.c_str()),
-1); // ... that the element name is in the MappedName...
EXPECT_EQ(
mappedName.rfind(shapeTypePrefix),
mappedName.toString().length()
- 1); // ... that the element prefix is at the end of the MappedName ...
}
// ... we also check that we don't find shapes that don't exist and therefor that don't
// have neither an IndexedName nor a MappedName
IndexedName fakeIndexedName {shapeTypeStr.c_str(),
(int)source.countSubElements(shapeType) + 1};
EXPECT_THROW(elementStdMap.at(fakeIndexedName), std::out_of_range);
}
testFindSourceSubShapesInElementMapForSource(sources, source);
}
}
TEST_F(TopoShapeMakeShapeWithElementMapTests, findMakerOpInElementMap)
{
// Arrange
auto [cube1, cube2] = TopoShapeExpansionHelpers::CreateTwoCubes();
auto [cube1, cube2] = PartTestHelpers::CreateTwoCubes();
std::vector<TopoShape> sources {cube1, cube2};
sources[0].Tag = 1; // setting Tag explicitly otherwise it is likely that this test will be
// more or less the same of nonMappableSources