From 93917a186dd1b7b0c402be4b3f7c7398cd02ba70 Mon Sep 17 00:00:00 2001 From: bgbsww Date: Thu, 21 Dec 2023 11:45:34 -0500 Subject: [PATCH 01/16] Preliminary cpp tests for Part boolean operations --- tests/src/Mod/Part/App/CMakeLists.txt | 5 +- tests/src/Mod/Part/App/FeaturePartCommon.cpp | 242 +++++++++++++++++++ tests/src/Mod/Part/App/FeaturePartCut.cpp | 212 ++++++++++++++++ tests/src/Mod/Part/App/FeaturePartFuse.cpp | 232 ++++++++++++++++++ 4 files changed, 690 insertions(+), 1 deletion(-) create mode 100644 tests/src/Mod/Part/App/FeaturePartCommon.cpp create mode 100644 tests/src/Mod/Part/App/FeaturePartCut.cpp create mode 100644 tests/src/Mod/Part/App/FeaturePartFuse.cpp diff --git a/tests/src/Mod/Part/App/CMakeLists.txt b/tests/src/Mod/Part/App/CMakeLists.txt index f8169423c6..1530cd4bb2 100644 --- a/tests/src/Mod/Part/App/CMakeLists.txt +++ b/tests/src/Mod/Part/App/CMakeLists.txt @@ -3,4 +3,7 @@ target_sources( Part_tests_run PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/TopoShape.cpp -) + ${CMAKE_CURRENT_SOURCE_DIR}/FeaturePartCommon.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/FeaturePartCut.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/FeaturePartFuse.cpp + ) diff --git a/tests/src/Mod/Part/App/FeaturePartCommon.cpp b/tests/src/Mod/Part/App/FeaturePartCommon.cpp new file mode 100644 index 0000000000..c9aa1c2c36 --- /dev/null +++ b/tests/src/Mod/Part/App/FeaturePartCommon.cpp @@ -0,0 +1,242 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later + +#include "gtest/gtest.h" + +#include +#include +#include +#include +#include +#include +#include "Mod/Part/App/FeaturePartBox.h" +#include "Mod/Part/App/FeaturePartCommon.h" +#include + +// #include + +// Should some of this go into a FeaturePartBoolean.cpp test suite? + +class FeaturePartCommonTest: public ::testing::Test +{ +protected: + static void SetUpTestSuite() + { + tests::initApplication(); + } + + + void SetUp() override { + _docName = App::GetApplication().getUniqueDocumentName("test"); + _doc = App::GetApplication().newDocument(_docName.c_str(), "testUser"); + _box1obj = static_cast(_doc->addObject("Part::Box")); + _box2obj = static_cast(_doc->addObject("Part::Box")); + _box3obj = static_cast(_doc->addObject("Part::Box")); + _box4obj = static_cast(_doc->addObject("Part::Box")); + _box5obj = static_cast(_doc->addObject("Part::Box")); + _box6obj = static_cast(_doc->addObject("Part::Box")); + _box1obj->Length.setValue(1); + _box1obj->Width.setValue(2); + _box1obj->Height.setValue(3); + _box1obj->Placement.setValue(Base::Placement(Base::Vector3d(), Base::Rotation(), Base::Vector3d())); + _box2obj->Placement.setValue(Base::Placement(Base::Vector3d(0, 1, 0), Base::Rotation(), Base::Vector3d())); + _box2obj->Length.setValue(1); + _box2obj->Width.setValue(2); + _box2obj->Height.setValue(3); + _box3obj->Placement.setValue(Base::Placement(Base::Vector3d(0, 3, 0), Base::Rotation(), Base::Vector3d())); + _box3obj->Length.setValue(1); + _box3obj->Width.setValue(2); + _box3obj->Height.setValue(3); + _box4obj->Placement.setValue(Base::Placement(Base::Vector3d(0, 2, 0), Base::Rotation(), Base::Vector3d())); + _box4obj->Length.setValue(1); + _box4obj->Width.setValue(2); + _box4obj->Height.setValue(3); + _box5obj->Placement.setValue(Base::Placement(Base::Vector3d(0, 2 + Base::Precision::Confusion(), 0), Base::Rotation(), Base::Vector3d())); + _box5obj->Length.setValue(1); + _box5obj->Width.setValue(2); + _box5obj->Height.setValue(3); + _box6obj->Placement.setValue(Base::Placement(Base::Vector3d(0, 2 - Base::Precision::Confusion()*1000, 0), Base::Rotation(), Base::Vector3d())); + _box6obj->Length.setValue(1); + _box6obj->Width.setValue(2); + _box6obj->Height.setValue(3); + _common = + static_cast(_doc->addObject("Part::Common")); + } + + void TearDown() override { + + } + + + Part::Box *_box1obj, *_box2obj, *_box3obj, *_box4obj, *_box5obj, *_box6obj; + Part::Common *_common; + App::Document *_doc; +private: + std::string _docName; +}; + +TEST_F(FeaturePartCommonTest, testIntersecting) +{ + // Arrange + _common->Base.setValue(_box1obj); + _common->Tool.setValue(_box2obj); + + // Act + _common->execute(); + Part::TopoShape ts = _common->Shape.getValue(); + Base::BoundBox3d bb = ts.getBoundBox(); + + // Assert + EXPECT_EQ(bb.MinX, 0 ); + EXPECT_EQ(bb.MinY, 1 ); + EXPECT_EQ(bb.MinZ, 0 ); + EXPECT_EQ(bb.MaxX, 1 ); + EXPECT_EQ(bb.MaxY, 2 ); + EXPECT_EQ(bb.MaxZ, 3 ); +} + +TEST_F(FeaturePartCommonTest, testNonIntersecting) +{ + // Arrange + _common->Base.setValue(_box1obj); + _common->Tool.setValue(_box3obj); + + // Act + _common->execute(); + Part::TopoShape ts = _common->Shape.getValue(); + Base::BoundBox3d bb = ts.getBoundBox(); + + // Assert + EXPECT_FALSE(bb.IsValid()); + // EXPECT_EQ(bb.Volume(),-1); + // EXPECT_EQ(bb.Volume(),0); +} + +TEST_F(FeaturePartCommonTest, testTouching) +{ + // Arrange + _common->Base.setValue(_box1obj); + _common->Tool.setValue(_box4obj); + + // Act + _common->execute(); + Part::TopoShape ts = _common->Shape.getValue(); + Base::BoundBox3d bb = ts.getBoundBox(); + + // Assert + EXPECT_FALSE(bb.IsValid()); + // EXPECT_EQ(bb.Volume(),0); +} + +TEST_F(FeaturePartCommonTest, testAlmostTouching) +{ + // Arrange + _common->Base.setValue(_box1obj); + _common->Tool.setValue(_box5obj); + + // Act + _common->execute(); + Part::TopoShape ts = _common->Shape.getValue(); + Base::BoundBox3d bb = ts.getBoundBox(); + + // Assert + EXPECT_FALSE(bb.IsValid()); + // EXPECT_EQ(bb.Volume(),-1); + // EXPECT_EQ(bb.Volume(),0); +} + +TEST_F(FeaturePartCommonTest, testBarelyIntersecting) +{ + // Arrange + _common->Base.setValue(_box1obj); + _common->Tool.setValue(_box6obj); + + // Act + _common->execute(); + Part::TopoShape ts = _common->Shape.getValue(); + Base::BoundBox3d bb = ts.getBoundBox(); + + // Assert + EXPECT_EQ(bb.MinX, 0 ); + EXPECT_EQ(bb.MinY, 1.9999 ); + EXPECT_EQ(bb.MinZ, 0 ); + EXPECT_EQ(bb.MaxX, 1 ); + EXPECT_EQ(bb.MaxY, 2 ); + EXPECT_EQ(bb.MaxZ, 3 ); +} + +TEST_F(FeaturePartCommonTest, testMustExecute) +{ + // Act + short mE = _common->mustExecute(); + // Assert + EXPECT_FALSE(mE); + _common->Base.setValue(_box1obj); + // Assert + mE = _common->mustExecute(); + EXPECT_FALSE(mE); + // Act + _common->Tool.setValue(_box2obj); + // Assert + mE = _common->mustExecute(); + EXPECT_TRUE(mE); + _doc->recompute(); + mE = _common->mustExecute(); + EXPECT_FALSE(mE); +} + +TEST_F(FeaturePartCommonTest, testGetProviderName) +{ + // Arrange + + // Act + _common->execute(); + const char * name = _common->getViewProviderName(); + // Assert + EXPECT_STREQ(name,"PartGui::ViewProviderBoolean"); +} + +namespace Part { + void PrintTo(ShapeHistory sh, std::ostream* os) { + const char *types[] = { "Compound", "CompSolid", "Solid", "Shell", "Face", "Wire", "Edge", "Vertex", "Shape" }; + *os << "History for " << types[sh.type] << " is "; + for (const auto & it : sh.shapeMap) { + int old_shape_index = it.first; + *os << " " << old_shape_index << ": "; + if (! it.second.empty()) + for ( auto it2 : it.second) + *os << it2 << " "; + } + *os << std::endl; + } +} + +TEST_F(FeaturePartCommonTest, testHistory) +{ + // Arrange + _common->Base.setValue(_box1obj); + _common->Tool.setValue(_box2obj); + + // Act and Assert + std::vector hist = _common->History.getValues(); + EXPECT_EQ(hist.size(),0); + + // This creates the histories classically generated by FreeCAD for comparison + using MapList = std::map >; + using List = std::vector; + MapList compare1 = { {0, List{0}}, {1, List{5}}, {2, List()}, {3, List{2}}, {4, List{3}}, {5, List{1}} }; + MapList compare2 = { {0, List{0}}, {1, List{5}}, {2, List{4}}, {3, List()}, {4, List{3}}, {5, List{1}} }; + + _common->execute(); + hist = _common->History.getValues(); + EXPECT_EQ(hist.size(),2); + EXPECT_EQ(hist[0].shapeMap,compare1); + EXPECT_EQ(hist[1].shapeMap,compare2); + _common->Base.setValue(_box2obj); + _common->Tool.setValue(_box1obj); + _common->execute(); + hist = _common->History.getValues(); + // std::cout << testing::PrintToString(hist[0]) << testing::PrintToString(hist[1]); + EXPECT_EQ(hist.size(),2); + EXPECT_EQ(hist[1].shapeMap,compare1); + EXPECT_EQ(hist[0].shapeMap,compare2); +} diff --git a/tests/src/Mod/Part/App/FeaturePartCut.cpp b/tests/src/Mod/Part/App/FeaturePartCut.cpp new file mode 100644 index 0000000000..748a7a6d15 --- /dev/null +++ b/tests/src/Mod/Part/App/FeaturePartCut.cpp @@ -0,0 +1,212 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later + +#include "gtest/gtest.h" + +#include +#include +#include +#include +#include +#include +#include "Mod/Part/App/FeaturePartBox.h" +#include "Mod/Part/App/FeaturePartCut.h" +#include + +#include + +// MOST OF THIS SHOULD GO INTO A FeaturePartBoolean.cpp test suite! + +class FeaturePartCutTest: public ::testing::Test +{ +protected: + static void SetUpTestSuite() + { + tests::initApplication(); + } + + + void SetUp() override { + _docName = App::GetApplication().getUniqueDocumentName("test"); + _doc = App::GetApplication().newDocument(_docName.c_str(), "testUser"); + _box1obj = + static_cast(_doc->addObject("Part::Box")); + _box1obj->Length.setValue(1); + _box1obj->Width.setValue(2); + _box1obj->Height.setValue(3); + _box1obj->Placement.setValue(Base::Placement(Base::Vector3d(0, 0, 0), Base::Rotation(), Base::Vector3d(0,0,0))); + _box2obj = + static_cast(_doc->addObject("Part::Box")); + _box2obj->Placement.setValue(Base::Placement(Base::Vector3d(0, 1, 0), Base::Rotation(), Base::Vector3d(0,0,0))); + _box2obj->Length.setValue(1); + _box2obj->Width.setValue(2); + _box2obj->Height.setValue(3); + _box3obj = + static_cast(_doc->addObject("Part::Box")); + _box3obj->Placement.setValue(Base::Placement(Base::Vector3d(0, 3, 0), Base::Rotation(), Base::Vector3d(0,0,0))); + _box3obj->Length.setValue(1); + _box3obj->Width.setValue(2); + _box3obj->Height.setValue(3); + _box4obj = + static_cast(_doc->addObject("Part::Box")); + _box4obj->Placement.setValue(Base::Placement(Base::Vector3d(0, 2, 0), Base::Rotation(), Base::Vector3d(0,0,0))); + _box4obj->Length.setValue(1); + _box4obj->Width.setValue(2); + _box4obj->Height.setValue(3); + _box5obj = + static_cast(_doc->addObject("Part::Box")); + _box5obj->Placement.setValue(Base::Placement(Base::Vector3d(0, 2 + Base::Precision::Confusion(), 0), Base::Rotation(), Base::Vector3d())); + _box5obj->Length.setValue(1); + _box5obj->Width.setValue(2); + _box5obj->Height.setValue(3); + _box6obj = + static_cast(_doc->addObject("Part::Box")); + _box6obj->Placement.setValue(Base::Placement(Base::Vector3d(0, 2 - Base::Precision::Confusion()*1000, 0), Base::Rotation(), Base::Vector3d())); + _box6obj->Length.setValue(1); + _box6obj->Width.setValue(2); + _box6obj->Height.setValue(3); + _cut = + static_cast(_doc->addObject("Part::Cut")); + } + + void TearDown() override { + + } + + + Part::Box *_box1obj, *_box2obj, *_box3obj, *_box4obj, *_box5obj, *_box6obj; + Part::Cut *_cut; + App::Document *_doc; +private: + std::string _docName; +}; + +TEST_F(FeaturePartCutTest, testIntersecting) +{ + // Arrange + _cut->Base.setValue(_box1obj); + _cut->Tool.setValue(_box2obj); + + // Act + _cut->execute(); + Part::TopoShape ts = _cut->Shape.getValue(); + Base::BoundBox3d bb = ts.getBoundBox(); + + // Assert + EXPECT_EQ(bb.MinX, 0 ); + EXPECT_EQ(bb.MinY, 0 ); + EXPECT_EQ(bb.MinZ, 0 ); + EXPECT_EQ(bb.MaxX, 1 ); + EXPECT_EQ(bb.MaxY, 1 ); + EXPECT_EQ(bb.MaxZ, 3 ); +} + +TEST_F(FeaturePartCutTest, testNonIntersecting) +{ + // Arrange + _cut->Base.setValue(_box1obj); + _cut->Tool.setValue(_box3obj); + + // Act + _cut->execute(); + Part::TopoShape ts = _cut->Shape.getValue(); + Base::BoundBox3d bb = ts.getBoundBox(); + + // Assert + EXPECT_EQ(bb.MinX, 0 ); + EXPECT_EQ(bb.MinY, 0 ); + EXPECT_EQ(bb.MinZ, 0 ); + EXPECT_EQ(bb.MaxX, 1 ); + EXPECT_EQ(bb.MaxY, 2 ); + EXPECT_EQ(bb.MaxZ, 3 ); +} + +TEST_F(FeaturePartCutTest, testTouching) +{ + // Arrange + _cut->Base.setValue(_box1obj); + _cut->Tool.setValue(_box4obj); + + // Act + _cut->execute(); + Part::TopoShape ts = _cut->Shape.getValue(); + Base::BoundBox3d bb = ts.getBoundBox(); + + // Assert + EXPECT_EQ(bb.MinX, 0 ); + EXPECT_EQ(bb.MinY, 0 ); + EXPECT_EQ(bb.MinZ, 0 ); + EXPECT_EQ(bb.MaxX, 1 ); + EXPECT_EQ(bb.MaxY, 2 ); + EXPECT_EQ(bb.MaxZ, 3 ); +} + +TEST_F(FeaturePartCutTest, testAlmostTouching) +{ + // Arrange + _cut->Base.setValue(_box1obj); + _cut->Tool.setValue(_box5obj); + + // Act + _cut->execute(); + Part::TopoShape ts = _cut->Shape.getValue(); + Base::BoundBox3d bb = ts.getBoundBox(); + + // Assert + EXPECT_EQ(bb.MinX, 0 ); + EXPECT_EQ(bb.MinY, 0 ); + EXPECT_EQ(bb.MinZ, 0 ); + EXPECT_EQ(bb.MaxX, 1 ); + EXPECT_EQ(bb.MaxY, 2 ); + EXPECT_EQ(bb.MaxZ, 3 ); +} + +TEST_F(FeaturePartCutTest, testBarelyIntersecting) +{ + // Arrange + _cut->Base.setValue(_box1obj); + _cut->Tool.setValue(_box6obj); + + // Act + _cut->execute(); + Part::TopoShape ts = _cut->Shape.getValue(); + Base::BoundBox3d bb = ts.getBoundBox(); + + // Assert + EXPECT_EQ(bb.MinX, 0 ); + EXPECT_EQ(bb.MinY, 0 ); + EXPECT_EQ(bb.MinZ, 0 ); + EXPECT_EQ(bb.MaxX, 1 ); + EXPECT_EQ(bb.MaxY, 1.9999 ); + EXPECT_EQ(bb.MaxZ, 3 ); +} + +TEST_F(FeaturePartCutTest, testMustExecute) +{ + // Act + short mE = _cut->mustExecute(); + // Assert + EXPECT_FALSE(mE); + _cut->Base.setValue(_box1obj); + // Assert + mE = _cut->mustExecute(); + EXPECT_FALSE(mE); + // Act + _cut->Tool.setValue(_box2obj); + // Assert + mE = _cut->mustExecute(); + EXPECT_TRUE(mE); + _doc->recompute(); + mE = _cut->mustExecute(); + EXPECT_FALSE(mE); +} + +TEST_F(FeaturePartCutTest, testGetProviderName) +{ + // Arrange + + // Act + _cut->execute(); + const char * name = _cut->getViewProviderName(); + // Assert + EXPECT_STREQ(name,"PartGui::ViewProviderBoolean"); +} diff --git a/tests/src/Mod/Part/App/FeaturePartFuse.cpp b/tests/src/Mod/Part/App/FeaturePartFuse.cpp new file mode 100644 index 0000000000..20818dcee5 --- /dev/null +++ b/tests/src/Mod/Part/App/FeaturePartFuse.cpp @@ -0,0 +1,232 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later + +#include "gtest/gtest.h" + +#include +#include +#include +#include +#include +#include +#include "Mod/Part/App/FeaturePartBox.h" +#include "Mod/Part/App/FeaturePartFuse.h" +#include + +#include + +// MOST OF THIS SHOULD GO INTO A FeaturePartBoolean.cpp test suite! + +class FeaturePartFuseTest: public ::testing::Test +{ +protected: + static void SetUpTestSuite() + { + tests::initApplication(); + } + + + void SetUp() override { + _docName = App::GetApplication().getUniqueDocumentName("test"); + _doc = App::GetApplication().newDocument(_docName.c_str(), "testUser"); + _box1obj = + static_cast(_doc->addObject("Part::Box")); + _box1obj->Length.setValue(1); + _box1obj->Width.setValue(2); + _box1obj->Height.setValue(3); + _box1obj->Placement.setValue(Base::Placement(Base::Vector3d(0, 0, 0), Base::Rotation(), Base::Vector3d(0,0,0))); + _box2obj = + static_cast(_doc->addObject("Part::Box")); + _box2obj->Placement.setValue(Base::Placement(Base::Vector3d(0, 1, 0), Base::Rotation(), Base::Vector3d(0,0,0))); + _box2obj->Length.setValue(1); + _box2obj->Width.setValue(2); + _box2obj->Height.setValue(3); + _box3obj = + static_cast(_doc->addObject("Part::Box")); + _box3obj->Placement.setValue(Base::Placement(Base::Vector3d(0, 3, 0), Base::Rotation(), Base::Vector3d(0,0,0))); + _box3obj->Length.setValue(1); + _box3obj->Width.setValue(2); + _box3obj->Height.setValue(3); + _box4obj = + static_cast(_doc->addObject("Part::Box")); + _box4obj->Placement.setValue(Base::Placement(Base::Vector3d(0, 2, 0), Base::Rotation(), Base::Vector3d(0,0,0))); + _box4obj->Length.setValue(1); + _box4obj->Width.setValue(2); + _box4obj->Height.setValue(3); + _box5obj = + static_cast(_doc->addObject("Part::Box")); + _box5obj->Placement.setValue(Base::Placement(Base::Vector3d(0, 2 + Base::Precision::Confusion(), 0), Base::Rotation(), Base::Vector3d())); + _box5obj->Length.setValue(1); + _box5obj->Width.setValue(2); + _box5obj->Height.setValue(3); + _box6obj = + static_cast(_doc->addObject("Part::Box")); + _box6obj->Placement.setValue(Base::Placement(Base::Vector3d(0, 2 - Base::Precision::Confusion()*1000, 0), Base::Rotation(), Base::Vector3d())); + _box6obj->Length.setValue(1); + _box6obj->Width.setValue(2); + _box6obj->Height.setValue(3); + _fuse = + static_cast(_doc->addObject("Part::Fuse")); + } + + void TearDown() override { + + } + + + Part::Box *_box1obj, *_box2obj, *_box3obj, *_box4obj, *_box5obj, *_box6obj; + Part::Fuse *_fuse; + App::Document *_doc; +private: + std::string _docName; +}; + +TEST_F(FeaturePartFuseTest, testIntersecting) +{ + // Arrange + _fuse->Base.setValue(_box1obj); + _fuse->Tool.setValue(_box2obj); + + // Act + _fuse->execute(); + Part::TopoShape ts = _fuse->Shape.getValue(); + Base::BoundBox3d bb = ts.getBoundBox(); + + // Assert + EXPECT_FLOAT_EQ(bb.MinX, 0 ); + EXPECT_FLOAT_EQ(bb.MinY, 0 ); + EXPECT_FLOAT_EQ(bb.MinZ, 0 ); + EXPECT_FLOAT_EQ(bb.MaxX, 1 ); + EXPECT_FLOAT_EQ(bb.MaxY, 3 ); + EXPECT_FLOAT_EQ(bb.MaxZ, 3 ); +} + +TEST_F(FeaturePartFuseTest, testNonIntersecting) +{ + // Arrange + _fuse->Base.setValue(_box1obj); + _fuse->Tool.setValue(_box3obj); + + // Act + _fuse->execute(); + Part::TopoShape ts = _fuse->Shape.getValue(); + Base::BoundBox3d bb = ts.getBoundBox(); + + // Assert + EXPECT_FLOAT_EQ(bb.MinX, 0 ); + EXPECT_FLOAT_EQ(bb.MinY, 0 ); + EXPECT_FLOAT_EQ(bb.MinZ, 0 ); + EXPECT_FLOAT_EQ(bb.MaxX, 1 ); + EXPECT_FLOAT_EQ(bb.MaxY, 5 ); + EXPECT_FLOAT_EQ(bb.MaxZ, 3 ); +} + +TEST_F(FeaturePartFuseTest, testTouching) +{ + // Arrange + _fuse->Base.setValue(_box1obj); + _fuse->Tool.setValue(_box4obj); + + // Act + _fuse->execute(); + Part::TopoShape ts = _fuse->Shape.getValue(); + Base::BoundBox3d bb = ts.getBoundBox(); + + // Assert + EXPECT_FLOAT_EQ(bb.MinX, 0 ); + EXPECT_FLOAT_EQ(bb.MinY, 0 ); + EXPECT_FLOAT_EQ(bb.MinZ, 0 ); + EXPECT_FLOAT_EQ(bb.MaxX, 1 ); + EXPECT_FLOAT_EQ(bb.MaxY, 4 ); + EXPECT_FLOAT_EQ(bb.MaxZ, 3 ); +} + +TEST_F(FeaturePartFuseTest, testAlmostTouching) +{ + // Arrange + _fuse->Base.setValue(_box1obj); + _fuse->Tool.setValue(_box5obj); + + // Act + _fuse->execute(); + Part::TopoShape ts = _fuse->Shape.getValue(); + Base::BoundBox3d bb = ts.getBoundBox(); + + // Assert + EXPECT_FLOAT_EQ(bb.MinX, 0 ); + EXPECT_FLOAT_EQ(bb.MinY, 0 ); + EXPECT_FLOAT_EQ(bb.MinZ, 0 ); + EXPECT_FLOAT_EQ(bb.MaxX, 1 ); + EXPECT_FLOAT_EQ(bb.MaxY, 4 ); + EXPECT_FLOAT_EQ(bb.MaxZ, 3 ); +} + +TEST_F(FeaturePartFuseTest, testBarelyIntersecting) +{ + // Arrange + _fuse->Base.setValue(_box1obj); + _fuse->Tool.setValue(_box6obj); + + // Act + _fuse->execute(); + Part::TopoShape ts = _fuse->Shape.getValue(); + Base::BoundBox3d bb = ts.getBoundBox(); + + // Assert + EXPECT_FLOAT_EQ(bb.MinX, 0 ); + EXPECT_FLOAT_EQ(bb.MinY, 0 ); + EXPECT_FLOAT_EQ(bb.MinZ, 0 ); + EXPECT_FLOAT_EQ(bb.MaxX, 1 ); + EXPECT_FLOAT_EQ(bb.MaxY, 3.9999 ); + EXPECT_FLOAT_EQ(bb.MaxZ, 3 ); +} + +TEST_F(FeaturePartFuseTest, testMustExecute) +{ + // Act + short mE = _fuse->mustExecute(); + // Assert + EXPECT_FALSE(mE); + _fuse->Base.setValue(_box1obj); + // Assert + mE = _fuse->mustExecute(); + EXPECT_FALSE(mE); + // Act + _fuse->Tool.setValue(_box2obj); + // Assert + mE = _fuse->mustExecute(); + EXPECT_TRUE(mE); + _doc->recompute(); + mE = _fuse->mustExecute(); + EXPECT_FALSE(mE); +} + +TEST_F(FeaturePartFuseTest, testGetProviderName) +{ + // Arrange + + // Act + _fuse->execute(); + const char * name = _fuse->getViewProviderName(); + // Assert + EXPECT_STREQ(name,"PartGui::ViewProviderBoolean"); +} + +TEST_F(FeaturePartFuseTest, testRefine) +{ + // Arrange + _fuse->Base.setValue(_box1obj); + _fuse->Tool.setValue(_box2obj); + + // Act + _fuse->execute(); + Part::TopoShape ts = _fuse->Shape.getValue(); + // what's the wire or face count here? + std::vector subs = ts.getSubTopoShapes(TopAbs_FACE); // WIRE + EXPECT_EQ(subs.size(), 14); + // Assert + _fuse->Refine.setValue(true); + _fuse->execute(); + ts = _fuse->Shape.getValue(); + subs = ts.getSubTopoShapes(TopAbs_FACE); // WIRE + EXPECT_EQ(subs.size(), 6); +} From 05bb3d1bcb130ae69e65ade670a31b9e7abb65e4 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 21 Dec 2023 17:06:19 +0000 Subject: [PATCH 02/16] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/src/Mod/Part/App/FeaturePartCommon.cpp | 115 ++++++++++-------- tests/src/Mod/Part/App/FeaturePartCut.cpp | 120 ++++++++++--------- tests/src/Mod/Part/App/FeaturePartFuse.cpp | 120 ++++++++++--------- 3 files changed, 190 insertions(+), 165 deletions(-) diff --git a/tests/src/Mod/Part/App/FeaturePartCommon.cpp b/tests/src/Mod/Part/App/FeaturePartCommon.cpp index c9aa1c2c36..fa8616a6e9 100644 --- a/tests/src/Mod/Part/App/FeaturePartCommon.cpp +++ b/tests/src/Mod/Part/App/FeaturePartCommon.cpp @@ -25,7 +25,8 @@ protected: } - void SetUp() override { + void SetUp() override + { _docName = App::GetApplication().getUniqueDocumentName("test"); _doc = App::GetApplication().newDocument(_docName.c_str(), "testUser"); _box1obj = static_cast(_doc->addObject("Part::Box")); @@ -37,39 +38,48 @@ protected: _box1obj->Length.setValue(1); _box1obj->Width.setValue(2); _box1obj->Height.setValue(3); - _box1obj->Placement.setValue(Base::Placement(Base::Vector3d(), Base::Rotation(), Base::Vector3d())); - _box2obj->Placement.setValue(Base::Placement(Base::Vector3d(0, 1, 0), Base::Rotation(), Base::Vector3d())); + _box1obj->Placement.setValue( + Base::Placement(Base::Vector3d(), Base::Rotation(), Base::Vector3d())); + _box2obj->Placement.setValue( + Base::Placement(Base::Vector3d(0, 1, 0), Base::Rotation(), Base::Vector3d())); _box2obj->Length.setValue(1); _box2obj->Width.setValue(2); _box2obj->Height.setValue(3); - _box3obj->Placement.setValue(Base::Placement(Base::Vector3d(0, 3, 0), Base::Rotation(), Base::Vector3d())); + _box3obj->Placement.setValue( + Base::Placement(Base::Vector3d(0, 3, 0), Base::Rotation(), Base::Vector3d())); _box3obj->Length.setValue(1); _box3obj->Width.setValue(2); _box3obj->Height.setValue(3); - _box4obj->Placement.setValue(Base::Placement(Base::Vector3d(0, 2, 0), Base::Rotation(), Base::Vector3d())); + _box4obj->Placement.setValue( + Base::Placement(Base::Vector3d(0, 2, 0), Base::Rotation(), Base::Vector3d())); _box4obj->Length.setValue(1); _box4obj->Width.setValue(2); _box4obj->Height.setValue(3); - _box5obj->Placement.setValue(Base::Placement(Base::Vector3d(0, 2 + Base::Precision::Confusion(), 0), Base::Rotation(), Base::Vector3d())); + _box5obj->Placement.setValue( + Base::Placement(Base::Vector3d(0, 2 + Base::Precision::Confusion(), 0), + Base::Rotation(), + Base::Vector3d())); _box5obj->Length.setValue(1); _box5obj->Width.setValue(2); _box5obj->Height.setValue(3); - _box6obj->Placement.setValue(Base::Placement(Base::Vector3d(0, 2 - Base::Precision::Confusion()*1000, 0), Base::Rotation(), Base::Vector3d())); + _box6obj->Placement.setValue( + Base::Placement(Base::Vector3d(0, 2 - Base::Precision::Confusion() * 1000, 0), + Base::Rotation(), + Base::Vector3d())); _box6obj->Length.setValue(1); _box6obj->Width.setValue(2); _box6obj->Height.setValue(3); - _common = - static_cast(_doc->addObject("Part::Common")); + _common = static_cast(_doc->addObject("Part::Common")); } - void TearDown() override { - - } + void TearDown() override + {} Part::Box *_box1obj, *_box2obj, *_box3obj, *_box4obj, *_box5obj, *_box6obj; - Part::Common *_common; - App::Document *_doc; + Part::Common* _common; + App::Document* _doc; + private: std::string _docName; }; @@ -86,12 +96,12 @@ TEST_F(FeaturePartCommonTest, testIntersecting) Base::BoundBox3d bb = ts.getBoundBox(); // Assert - EXPECT_EQ(bb.MinX, 0 ); - EXPECT_EQ(bb.MinY, 1 ); - EXPECT_EQ(bb.MinZ, 0 ); - EXPECT_EQ(bb.MaxX, 1 ); - EXPECT_EQ(bb.MaxY, 2 ); - EXPECT_EQ(bb.MaxZ, 3 ); + EXPECT_EQ(bb.MinX, 0); + EXPECT_EQ(bb.MinY, 1); + EXPECT_EQ(bb.MinZ, 0); + EXPECT_EQ(bb.MaxX, 1); + EXPECT_EQ(bb.MaxY, 2); + EXPECT_EQ(bb.MaxZ, 3); } TEST_F(FeaturePartCommonTest, testNonIntersecting) @@ -156,12 +166,12 @@ TEST_F(FeaturePartCommonTest, testBarelyIntersecting) Base::BoundBox3d bb = ts.getBoundBox(); // Assert - EXPECT_EQ(bb.MinX, 0 ); - EXPECT_EQ(bb.MinY, 1.9999 ); - EXPECT_EQ(bb.MinZ, 0 ); - EXPECT_EQ(bb.MaxX, 1 ); - EXPECT_EQ(bb.MaxY, 2 ); - EXPECT_EQ(bb.MaxZ, 3 ); + EXPECT_EQ(bb.MinX, 0); + EXPECT_EQ(bb.MinY, 1.9999); + EXPECT_EQ(bb.MinZ, 0); + EXPECT_EQ(bb.MaxX, 1); + EXPECT_EQ(bb.MaxY, 2); + EXPECT_EQ(bb.MaxZ, 3); } TEST_F(FeaturePartCommonTest, testMustExecute) @@ -190,25 +200,30 @@ TEST_F(FeaturePartCommonTest, testGetProviderName) // Act _common->execute(); - const char * name = _common->getViewProviderName(); + const char* name = _common->getViewProviderName(); // Assert - EXPECT_STREQ(name,"PartGui::ViewProviderBoolean"); + EXPECT_STREQ(name, "PartGui::ViewProviderBoolean"); } -namespace Part { - void PrintTo(ShapeHistory sh, std::ostream* os) { - const char *types[] = { "Compound", "CompSolid", "Solid", "Shell", "Face", "Wire", "Edge", "Vertex", "Shape" }; - *os << "History for " << types[sh.type] << " is "; - for (const auto & it : sh.shapeMap) { - int old_shape_index = it.first; - *os << " " << old_shape_index << ": "; - if (! it.second.empty()) - for ( auto it2 : it.second) - *os << it2 << " "; +namespace Part +{ +void PrintTo(ShapeHistory sh, std::ostream* os) +{ + const char* types[] = + {"Compound", "CompSolid", "Solid", "Shell", "Face", "Wire", "Edge", "Vertex", "Shape"}; + *os << "History for " << types[sh.type] << " is "; + for (const auto& it : sh.shapeMap) { + int old_shape_index = it.first; + *os << " " << old_shape_index << ": "; + if (!it.second.empty()) { + for (auto it2 : it.second) { + *os << it2 << " "; + } } - *os << std::endl; } + *os << std::endl; } +} // namespace Part TEST_F(FeaturePartCommonTest, testHistory) { @@ -218,25 +233,27 @@ TEST_F(FeaturePartCommonTest, testHistory) // Act and Assert std::vector hist = _common->History.getValues(); - EXPECT_EQ(hist.size(),0); + EXPECT_EQ(hist.size(), 0); // This creates the histories classically generated by FreeCAD for comparison - using MapList = std::map >; + using MapList = std::map>; using List = std::vector; - MapList compare1 = { {0, List{0}}, {1, List{5}}, {2, List()}, {3, List{2}}, {4, List{3}}, {5, List{1}} }; - MapList compare2 = { {0, List{0}}, {1, List{5}}, {2, List{4}}, {3, List()}, {4, List{3}}, {5, List{1}} }; + MapList compare1 = + {{0, List {0}}, {1, List {5}}, {2, List()}, {3, List {2}}, {4, List {3}}, {5, List {1}}}; + MapList compare2 = + {{0, List {0}}, {1, List {5}}, {2, List {4}}, {3, List()}, {4, List {3}}, {5, List {1}}}; _common->execute(); hist = _common->History.getValues(); - EXPECT_EQ(hist.size(),2); - EXPECT_EQ(hist[0].shapeMap,compare1); - EXPECT_EQ(hist[1].shapeMap,compare2); + EXPECT_EQ(hist.size(), 2); + EXPECT_EQ(hist[0].shapeMap, compare1); + EXPECT_EQ(hist[1].shapeMap, compare2); _common->Base.setValue(_box2obj); _common->Tool.setValue(_box1obj); _common->execute(); hist = _common->History.getValues(); // std::cout << testing::PrintToString(hist[0]) << testing::PrintToString(hist[1]); - EXPECT_EQ(hist.size(),2); - EXPECT_EQ(hist[1].shapeMap,compare1); - EXPECT_EQ(hist[0].shapeMap,compare2); + EXPECT_EQ(hist.size(), 2); + EXPECT_EQ(hist[1].shapeMap, compare1); + EXPECT_EQ(hist[0].shapeMap, compare2); } diff --git a/tests/src/Mod/Part/App/FeaturePartCut.cpp b/tests/src/Mod/Part/App/FeaturePartCut.cpp index 748a7a6d15..5f2e8fbee4 100644 --- a/tests/src/Mod/Part/App/FeaturePartCut.cpp +++ b/tests/src/Mod/Part/App/FeaturePartCut.cpp @@ -25,57 +25,61 @@ protected: } - void SetUp() override { + void SetUp() override + { _docName = App::GetApplication().getUniqueDocumentName("test"); _doc = App::GetApplication().newDocument(_docName.c_str(), "testUser"); - _box1obj = - static_cast(_doc->addObject("Part::Box")); + _box1obj = static_cast(_doc->addObject("Part::Box")); _box1obj->Length.setValue(1); _box1obj->Width.setValue(2); _box1obj->Height.setValue(3); - _box1obj->Placement.setValue(Base::Placement(Base::Vector3d(0, 0, 0), Base::Rotation(), Base::Vector3d(0,0,0))); - _box2obj = - static_cast(_doc->addObject("Part::Box")); - _box2obj->Placement.setValue(Base::Placement(Base::Vector3d(0, 1, 0), Base::Rotation(), Base::Vector3d(0,0,0))); + _box1obj->Placement.setValue( + Base::Placement(Base::Vector3d(0, 0, 0), Base::Rotation(), Base::Vector3d(0, 0, 0))); + _box2obj = static_cast(_doc->addObject("Part::Box")); + _box2obj->Placement.setValue( + Base::Placement(Base::Vector3d(0, 1, 0), Base::Rotation(), Base::Vector3d(0, 0, 0))); _box2obj->Length.setValue(1); _box2obj->Width.setValue(2); _box2obj->Height.setValue(3); - _box3obj = - static_cast(_doc->addObject("Part::Box")); - _box3obj->Placement.setValue(Base::Placement(Base::Vector3d(0, 3, 0), Base::Rotation(), Base::Vector3d(0,0,0))); + _box3obj = static_cast(_doc->addObject("Part::Box")); + _box3obj->Placement.setValue( + Base::Placement(Base::Vector3d(0, 3, 0), Base::Rotation(), Base::Vector3d(0, 0, 0))); _box3obj->Length.setValue(1); _box3obj->Width.setValue(2); _box3obj->Height.setValue(3); - _box4obj = - static_cast(_doc->addObject("Part::Box")); - _box4obj->Placement.setValue(Base::Placement(Base::Vector3d(0, 2, 0), Base::Rotation(), Base::Vector3d(0,0,0))); + _box4obj = static_cast(_doc->addObject("Part::Box")); + _box4obj->Placement.setValue( + Base::Placement(Base::Vector3d(0, 2, 0), Base::Rotation(), Base::Vector3d(0, 0, 0))); _box4obj->Length.setValue(1); _box4obj->Width.setValue(2); _box4obj->Height.setValue(3); - _box5obj = - static_cast(_doc->addObject("Part::Box")); - _box5obj->Placement.setValue(Base::Placement(Base::Vector3d(0, 2 + Base::Precision::Confusion(), 0), Base::Rotation(), Base::Vector3d())); + _box5obj = static_cast(_doc->addObject("Part::Box")); + _box5obj->Placement.setValue( + Base::Placement(Base::Vector3d(0, 2 + Base::Precision::Confusion(), 0), + Base::Rotation(), + Base::Vector3d())); _box5obj->Length.setValue(1); _box5obj->Width.setValue(2); _box5obj->Height.setValue(3); - _box6obj = - static_cast(_doc->addObject("Part::Box")); - _box6obj->Placement.setValue(Base::Placement(Base::Vector3d(0, 2 - Base::Precision::Confusion()*1000, 0), Base::Rotation(), Base::Vector3d())); + _box6obj = static_cast(_doc->addObject("Part::Box")); + _box6obj->Placement.setValue( + Base::Placement(Base::Vector3d(0, 2 - Base::Precision::Confusion() * 1000, 0), + Base::Rotation(), + Base::Vector3d())); _box6obj->Length.setValue(1); _box6obj->Width.setValue(2); _box6obj->Height.setValue(3); - _cut = - static_cast(_doc->addObject("Part::Cut")); + _cut = static_cast(_doc->addObject("Part::Cut")); } - void TearDown() override { - - } + void TearDown() override + {} Part::Box *_box1obj, *_box2obj, *_box3obj, *_box4obj, *_box5obj, *_box6obj; - Part::Cut *_cut; - App::Document *_doc; + Part::Cut* _cut; + App::Document* _doc; + private: std::string _docName; }; @@ -92,12 +96,12 @@ TEST_F(FeaturePartCutTest, testIntersecting) Base::BoundBox3d bb = ts.getBoundBox(); // Assert - EXPECT_EQ(bb.MinX, 0 ); - EXPECT_EQ(bb.MinY, 0 ); - EXPECT_EQ(bb.MinZ, 0 ); - EXPECT_EQ(bb.MaxX, 1 ); - EXPECT_EQ(bb.MaxY, 1 ); - EXPECT_EQ(bb.MaxZ, 3 ); + EXPECT_EQ(bb.MinX, 0); + EXPECT_EQ(bb.MinY, 0); + EXPECT_EQ(bb.MinZ, 0); + EXPECT_EQ(bb.MaxX, 1); + EXPECT_EQ(bb.MaxY, 1); + EXPECT_EQ(bb.MaxZ, 3); } TEST_F(FeaturePartCutTest, testNonIntersecting) @@ -112,12 +116,12 @@ TEST_F(FeaturePartCutTest, testNonIntersecting) Base::BoundBox3d bb = ts.getBoundBox(); // Assert - EXPECT_EQ(bb.MinX, 0 ); - EXPECT_EQ(bb.MinY, 0 ); - EXPECT_EQ(bb.MinZ, 0 ); - EXPECT_EQ(bb.MaxX, 1 ); - EXPECT_EQ(bb.MaxY, 2 ); - EXPECT_EQ(bb.MaxZ, 3 ); + EXPECT_EQ(bb.MinX, 0); + EXPECT_EQ(bb.MinY, 0); + EXPECT_EQ(bb.MinZ, 0); + EXPECT_EQ(bb.MaxX, 1); + EXPECT_EQ(bb.MaxY, 2); + EXPECT_EQ(bb.MaxZ, 3); } TEST_F(FeaturePartCutTest, testTouching) @@ -132,12 +136,12 @@ TEST_F(FeaturePartCutTest, testTouching) Base::BoundBox3d bb = ts.getBoundBox(); // Assert - EXPECT_EQ(bb.MinX, 0 ); - EXPECT_EQ(bb.MinY, 0 ); - EXPECT_EQ(bb.MinZ, 0 ); - EXPECT_EQ(bb.MaxX, 1 ); - EXPECT_EQ(bb.MaxY, 2 ); - EXPECT_EQ(bb.MaxZ, 3 ); + EXPECT_EQ(bb.MinX, 0); + EXPECT_EQ(bb.MinY, 0); + EXPECT_EQ(bb.MinZ, 0); + EXPECT_EQ(bb.MaxX, 1); + EXPECT_EQ(bb.MaxY, 2); + EXPECT_EQ(bb.MaxZ, 3); } TEST_F(FeaturePartCutTest, testAlmostTouching) @@ -152,12 +156,12 @@ TEST_F(FeaturePartCutTest, testAlmostTouching) Base::BoundBox3d bb = ts.getBoundBox(); // Assert - EXPECT_EQ(bb.MinX, 0 ); - EXPECT_EQ(bb.MinY, 0 ); - EXPECT_EQ(bb.MinZ, 0 ); - EXPECT_EQ(bb.MaxX, 1 ); - EXPECT_EQ(bb.MaxY, 2 ); - EXPECT_EQ(bb.MaxZ, 3 ); + EXPECT_EQ(bb.MinX, 0); + EXPECT_EQ(bb.MinY, 0); + EXPECT_EQ(bb.MinZ, 0); + EXPECT_EQ(bb.MaxX, 1); + EXPECT_EQ(bb.MaxY, 2); + EXPECT_EQ(bb.MaxZ, 3); } TEST_F(FeaturePartCutTest, testBarelyIntersecting) @@ -172,12 +176,12 @@ TEST_F(FeaturePartCutTest, testBarelyIntersecting) Base::BoundBox3d bb = ts.getBoundBox(); // Assert - EXPECT_EQ(bb.MinX, 0 ); - EXPECT_EQ(bb.MinY, 0 ); - EXPECT_EQ(bb.MinZ, 0 ); - EXPECT_EQ(bb.MaxX, 1 ); - EXPECT_EQ(bb.MaxY, 1.9999 ); - EXPECT_EQ(bb.MaxZ, 3 ); + EXPECT_EQ(bb.MinX, 0); + EXPECT_EQ(bb.MinY, 0); + EXPECT_EQ(bb.MinZ, 0); + EXPECT_EQ(bb.MaxX, 1); + EXPECT_EQ(bb.MaxY, 1.9999); + EXPECT_EQ(bb.MaxZ, 3); } TEST_F(FeaturePartCutTest, testMustExecute) @@ -206,7 +210,7 @@ TEST_F(FeaturePartCutTest, testGetProviderName) // Act _cut->execute(); - const char * name = _cut->getViewProviderName(); + const char* name = _cut->getViewProviderName(); // Assert - EXPECT_STREQ(name,"PartGui::ViewProviderBoolean"); + EXPECT_STREQ(name, "PartGui::ViewProviderBoolean"); } diff --git a/tests/src/Mod/Part/App/FeaturePartFuse.cpp b/tests/src/Mod/Part/App/FeaturePartFuse.cpp index 20818dcee5..b8025ac5cd 100644 --- a/tests/src/Mod/Part/App/FeaturePartFuse.cpp +++ b/tests/src/Mod/Part/App/FeaturePartFuse.cpp @@ -25,57 +25,61 @@ protected: } - void SetUp() override { + void SetUp() override + { _docName = App::GetApplication().getUniqueDocumentName("test"); _doc = App::GetApplication().newDocument(_docName.c_str(), "testUser"); - _box1obj = - static_cast(_doc->addObject("Part::Box")); + _box1obj = static_cast(_doc->addObject("Part::Box")); _box1obj->Length.setValue(1); _box1obj->Width.setValue(2); _box1obj->Height.setValue(3); - _box1obj->Placement.setValue(Base::Placement(Base::Vector3d(0, 0, 0), Base::Rotation(), Base::Vector3d(0,0,0))); - _box2obj = - static_cast(_doc->addObject("Part::Box")); - _box2obj->Placement.setValue(Base::Placement(Base::Vector3d(0, 1, 0), Base::Rotation(), Base::Vector3d(0,0,0))); + _box1obj->Placement.setValue( + Base::Placement(Base::Vector3d(0, 0, 0), Base::Rotation(), Base::Vector3d(0, 0, 0))); + _box2obj = static_cast(_doc->addObject("Part::Box")); + _box2obj->Placement.setValue( + Base::Placement(Base::Vector3d(0, 1, 0), Base::Rotation(), Base::Vector3d(0, 0, 0))); _box2obj->Length.setValue(1); _box2obj->Width.setValue(2); _box2obj->Height.setValue(3); - _box3obj = - static_cast(_doc->addObject("Part::Box")); - _box3obj->Placement.setValue(Base::Placement(Base::Vector3d(0, 3, 0), Base::Rotation(), Base::Vector3d(0,0,0))); + _box3obj = static_cast(_doc->addObject("Part::Box")); + _box3obj->Placement.setValue( + Base::Placement(Base::Vector3d(0, 3, 0), Base::Rotation(), Base::Vector3d(0, 0, 0))); _box3obj->Length.setValue(1); _box3obj->Width.setValue(2); _box3obj->Height.setValue(3); - _box4obj = - static_cast(_doc->addObject("Part::Box")); - _box4obj->Placement.setValue(Base::Placement(Base::Vector3d(0, 2, 0), Base::Rotation(), Base::Vector3d(0,0,0))); + _box4obj = static_cast(_doc->addObject("Part::Box")); + _box4obj->Placement.setValue( + Base::Placement(Base::Vector3d(0, 2, 0), Base::Rotation(), Base::Vector3d(0, 0, 0))); _box4obj->Length.setValue(1); _box4obj->Width.setValue(2); _box4obj->Height.setValue(3); - _box5obj = - static_cast(_doc->addObject("Part::Box")); - _box5obj->Placement.setValue(Base::Placement(Base::Vector3d(0, 2 + Base::Precision::Confusion(), 0), Base::Rotation(), Base::Vector3d())); + _box5obj = static_cast(_doc->addObject("Part::Box")); + _box5obj->Placement.setValue( + Base::Placement(Base::Vector3d(0, 2 + Base::Precision::Confusion(), 0), + Base::Rotation(), + Base::Vector3d())); _box5obj->Length.setValue(1); _box5obj->Width.setValue(2); _box5obj->Height.setValue(3); - _box6obj = - static_cast(_doc->addObject("Part::Box")); - _box6obj->Placement.setValue(Base::Placement(Base::Vector3d(0, 2 - Base::Precision::Confusion()*1000, 0), Base::Rotation(), Base::Vector3d())); + _box6obj = static_cast(_doc->addObject("Part::Box")); + _box6obj->Placement.setValue( + Base::Placement(Base::Vector3d(0, 2 - Base::Precision::Confusion() * 1000, 0), + Base::Rotation(), + Base::Vector3d())); _box6obj->Length.setValue(1); _box6obj->Width.setValue(2); _box6obj->Height.setValue(3); - _fuse = - static_cast(_doc->addObject("Part::Fuse")); + _fuse = static_cast(_doc->addObject("Part::Fuse")); } - void TearDown() override { - - } + void TearDown() override + {} Part::Box *_box1obj, *_box2obj, *_box3obj, *_box4obj, *_box5obj, *_box6obj; - Part::Fuse *_fuse; - App::Document *_doc; + Part::Fuse* _fuse; + App::Document* _doc; + private: std::string _docName; }; @@ -92,12 +96,12 @@ TEST_F(FeaturePartFuseTest, testIntersecting) Base::BoundBox3d bb = ts.getBoundBox(); // Assert - EXPECT_FLOAT_EQ(bb.MinX, 0 ); - EXPECT_FLOAT_EQ(bb.MinY, 0 ); - EXPECT_FLOAT_EQ(bb.MinZ, 0 ); - EXPECT_FLOAT_EQ(bb.MaxX, 1 ); - EXPECT_FLOAT_EQ(bb.MaxY, 3 ); - EXPECT_FLOAT_EQ(bb.MaxZ, 3 ); + EXPECT_FLOAT_EQ(bb.MinX, 0); + EXPECT_FLOAT_EQ(bb.MinY, 0); + EXPECT_FLOAT_EQ(bb.MinZ, 0); + EXPECT_FLOAT_EQ(bb.MaxX, 1); + EXPECT_FLOAT_EQ(bb.MaxY, 3); + EXPECT_FLOAT_EQ(bb.MaxZ, 3); } TEST_F(FeaturePartFuseTest, testNonIntersecting) @@ -112,12 +116,12 @@ TEST_F(FeaturePartFuseTest, testNonIntersecting) Base::BoundBox3d bb = ts.getBoundBox(); // Assert - EXPECT_FLOAT_EQ(bb.MinX, 0 ); - EXPECT_FLOAT_EQ(bb.MinY, 0 ); - EXPECT_FLOAT_EQ(bb.MinZ, 0 ); - EXPECT_FLOAT_EQ(bb.MaxX, 1 ); - EXPECT_FLOAT_EQ(bb.MaxY, 5 ); - EXPECT_FLOAT_EQ(bb.MaxZ, 3 ); + EXPECT_FLOAT_EQ(bb.MinX, 0); + EXPECT_FLOAT_EQ(bb.MinY, 0); + EXPECT_FLOAT_EQ(bb.MinZ, 0); + EXPECT_FLOAT_EQ(bb.MaxX, 1); + EXPECT_FLOAT_EQ(bb.MaxY, 5); + EXPECT_FLOAT_EQ(bb.MaxZ, 3); } TEST_F(FeaturePartFuseTest, testTouching) @@ -132,12 +136,12 @@ TEST_F(FeaturePartFuseTest, testTouching) Base::BoundBox3d bb = ts.getBoundBox(); // Assert - EXPECT_FLOAT_EQ(bb.MinX, 0 ); - EXPECT_FLOAT_EQ(bb.MinY, 0 ); - EXPECT_FLOAT_EQ(bb.MinZ, 0 ); - EXPECT_FLOAT_EQ(bb.MaxX, 1 ); - EXPECT_FLOAT_EQ(bb.MaxY, 4 ); - EXPECT_FLOAT_EQ(bb.MaxZ, 3 ); + EXPECT_FLOAT_EQ(bb.MinX, 0); + EXPECT_FLOAT_EQ(bb.MinY, 0); + EXPECT_FLOAT_EQ(bb.MinZ, 0); + EXPECT_FLOAT_EQ(bb.MaxX, 1); + EXPECT_FLOAT_EQ(bb.MaxY, 4); + EXPECT_FLOAT_EQ(bb.MaxZ, 3); } TEST_F(FeaturePartFuseTest, testAlmostTouching) @@ -152,12 +156,12 @@ TEST_F(FeaturePartFuseTest, testAlmostTouching) Base::BoundBox3d bb = ts.getBoundBox(); // Assert - EXPECT_FLOAT_EQ(bb.MinX, 0 ); - EXPECT_FLOAT_EQ(bb.MinY, 0 ); - EXPECT_FLOAT_EQ(bb.MinZ, 0 ); - EXPECT_FLOAT_EQ(bb.MaxX, 1 ); - EXPECT_FLOAT_EQ(bb.MaxY, 4 ); - EXPECT_FLOAT_EQ(bb.MaxZ, 3 ); + EXPECT_FLOAT_EQ(bb.MinX, 0); + EXPECT_FLOAT_EQ(bb.MinY, 0); + EXPECT_FLOAT_EQ(bb.MinZ, 0); + EXPECT_FLOAT_EQ(bb.MaxX, 1); + EXPECT_FLOAT_EQ(bb.MaxY, 4); + EXPECT_FLOAT_EQ(bb.MaxZ, 3); } TEST_F(FeaturePartFuseTest, testBarelyIntersecting) @@ -172,12 +176,12 @@ TEST_F(FeaturePartFuseTest, testBarelyIntersecting) Base::BoundBox3d bb = ts.getBoundBox(); // Assert - EXPECT_FLOAT_EQ(bb.MinX, 0 ); - EXPECT_FLOAT_EQ(bb.MinY, 0 ); - EXPECT_FLOAT_EQ(bb.MinZ, 0 ); - EXPECT_FLOAT_EQ(bb.MaxX, 1 ); - EXPECT_FLOAT_EQ(bb.MaxY, 3.9999 ); - EXPECT_FLOAT_EQ(bb.MaxZ, 3 ); + EXPECT_FLOAT_EQ(bb.MinX, 0); + EXPECT_FLOAT_EQ(bb.MinY, 0); + EXPECT_FLOAT_EQ(bb.MinZ, 0); + EXPECT_FLOAT_EQ(bb.MaxX, 1); + EXPECT_FLOAT_EQ(bb.MaxY, 3.9999); + EXPECT_FLOAT_EQ(bb.MaxZ, 3); } TEST_F(FeaturePartFuseTest, testMustExecute) @@ -206,9 +210,9 @@ TEST_F(FeaturePartFuseTest, testGetProviderName) // Act _fuse->execute(); - const char * name = _fuse->getViewProviderName(); + const char* name = _fuse->getViewProviderName(); // Assert - EXPECT_STREQ(name,"PartGui::ViewProviderBoolean"); + EXPECT_STREQ(name, "PartGui::ViewProviderBoolean"); } TEST_F(FeaturePartFuseTest, testRefine) From 7b3946d7b817150b9babd76991c7302cf86e4657 Mon Sep 17 00:00:00 2001 From: bgbsww Date: Thu, 21 Dec 2023 14:34:37 -0500 Subject: [PATCH 03/16] First pass cleanup of test code --- tests/src/Mod/Part/App/FeaturePartCommon.cpp | 4 -- tests/src/Mod/Part/App/FeaturePartCut.cpp | 62 ++++++++++---------- tests/src/Mod/Part/App/FeaturePartFuse.cpp | 2 - 3 files changed, 30 insertions(+), 38 deletions(-) diff --git a/tests/src/Mod/Part/App/FeaturePartCommon.cpp b/tests/src/Mod/Part/App/FeaturePartCommon.cpp index fa8616a6e9..82a0d0ec77 100644 --- a/tests/src/Mod/Part/App/FeaturePartCommon.cpp +++ b/tests/src/Mod/Part/App/FeaturePartCommon.cpp @@ -12,8 +12,6 @@ #include "Mod/Part/App/FeaturePartCommon.h" #include -// #include - // Should some of this go into a FeaturePartBoolean.cpp test suite? class FeaturePartCommonTest: public ::testing::Test @@ -196,8 +194,6 @@ TEST_F(FeaturePartCommonTest, testMustExecute) TEST_F(FeaturePartCommonTest, testGetProviderName) { - // Arrange - // Act _common->execute(); const char* name = _common->getViewProviderName(); diff --git a/tests/src/Mod/Part/App/FeaturePartCut.cpp b/tests/src/Mod/Part/App/FeaturePartCut.cpp index 5f2e8fbee4..260b0d6e0f 100644 --- a/tests/src/Mod/Part/App/FeaturePartCut.cpp +++ b/tests/src/Mod/Part/App/FeaturePartCut.cpp @@ -96,12 +96,12 @@ TEST_F(FeaturePartCutTest, testIntersecting) Base::BoundBox3d bb = ts.getBoundBox(); // Assert - EXPECT_EQ(bb.MinX, 0); - EXPECT_EQ(bb.MinY, 0); - EXPECT_EQ(bb.MinZ, 0); - EXPECT_EQ(bb.MaxX, 1); - EXPECT_EQ(bb.MaxY, 1); - EXPECT_EQ(bb.MaxZ, 3); + EXPECT_FLOAT_EQ(bb.MinX, 0); + EXPECT_FLOAT_EQ(bb.MinY, 0); + EXPECT_FLOAT_EQ(bb.MinZ, 0); + EXPECT_FLOAT_EQ(bb.MaxX, 1); + EXPECT_FLOAT_EQ(bb.MaxY, 1); + EXPECT_FLOAT_EQ(bb.MaxZ, 3); } TEST_F(FeaturePartCutTest, testNonIntersecting) @@ -116,12 +116,12 @@ TEST_F(FeaturePartCutTest, testNonIntersecting) Base::BoundBox3d bb = ts.getBoundBox(); // Assert - EXPECT_EQ(bb.MinX, 0); - EXPECT_EQ(bb.MinY, 0); - EXPECT_EQ(bb.MinZ, 0); - EXPECT_EQ(bb.MaxX, 1); - EXPECT_EQ(bb.MaxY, 2); - EXPECT_EQ(bb.MaxZ, 3); + EXPECT_FLOAT_EQ(bb.MinX, 0); + EXPECT_FLOAT_EQ(bb.MinY, 0); + EXPECT_FLOAT_EQ(bb.MinZ, 0); + EXPECT_FLOAT_EQ(bb.MaxX, 1); + EXPECT_FLOAT_EQ(bb.MaxY, 2); + EXPECT_FLOAT_EQ(bb.MaxZ, 3); } TEST_F(FeaturePartCutTest, testTouching) @@ -136,12 +136,12 @@ TEST_F(FeaturePartCutTest, testTouching) Base::BoundBox3d bb = ts.getBoundBox(); // Assert - EXPECT_EQ(bb.MinX, 0); - EXPECT_EQ(bb.MinY, 0); - EXPECT_EQ(bb.MinZ, 0); - EXPECT_EQ(bb.MaxX, 1); - EXPECT_EQ(bb.MaxY, 2); - EXPECT_EQ(bb.MaxZ, 3); + EXPECT_FLOAT_EQ(bb.MinX, 0); + EXPECT_FLOAT_EQ(bb.MinY, 0); + EXPECT_FLOAT_EQ(bb.MinZ, 0); + EXPECT_FLOAT_EQ(bb.MaxX, 1); + EXPECT_FLOAT_EQ(bb.MaxY, 2); + EXPECT_FLOAT_EQ(bb.MaxZ, 3); } TEST_F(FeaturePartCutTest, testAlmostTouching) @@ -156,12 +156,12 @@ TEST_F(FeaturePartCutTest, testAlmostTouching) Base::BoundBox3d bb = ts.getBoundBox(); // Assert - EXPECT_EQ(bb.MinX, 0); - EXPECT_EQ(bb.MinY, 0); - EXPECT_EQ(bb.MinZ, 0); - EXPECT_EQ(bb.MaxX, 1); - EXPECT_EQ(bb.MaxY, 2); - EXPECT_EQ(bb.MaxZ, 3); + EXPECT_FLOAT_EQ(bb.MinX, 0); + EXPECT_FLOAT_EQ(bb.MinY, 0); + EXPECT_FLOAT_EQ(bb.MinZ, 0); + EXPECT_FLOAT_EQ(bb.MaxX, 1); + EXPECT_FLOAT_EQ(bb.MaxY, 2); + EXPECT_FLOAT_EQ(bb.MaxZ, 3); } TEST_F(FeaturePartCutTest, testBarelyIntersecting) @@ -176,12 +176,12 @@ TEST_F(FeaturePartCutTest, testBarelyIntersecting) Base::BoundBox3d bb = ts.getBoundBox(); // Assert - EXPECT_EQ(bb.MinX, 0); - EXPECT_EQ(bb.MinY, 0); - EXPECT_EQ(bb.MinZ, 0); - EXPECT_EQ(bb.MaxX, 1); - EXPECT_EQ(bb.MaxY, 1.9999); - EXPECT_EQ(bb.MaxZ, 3); + EXPECT_FLOAT_EQ(bb.MinX, 0); + EXPECT_FLOAT_EQ(bb.MinY, 0); + EXPECT_FLOAT_EQ(bb.MinZ, 0); + EXPECT_FLOAT_EQ(bb.MaxX, 1); + EXPECT_FLOAT_EQ(bb.MaxY, 1.9999); + EXPECT_FLOAT_EQ(bb.MaxZ, 3); } TEST_F(FeaturePartCutTest, testMustExecute) @@ -206,8 +206,6 @@ TEST_F(FeaturePartCutTest, testMustExecute) TEST_F(FeaturePartCutTest, testGetProviderName) { - // Arrange - // Act _cut->execute(); const char* name = _cut->getViewProviderName(); diff --git a/tests/src/Mod/Part/App/FeaturePartFuse.cpp b/tests/src/Mod/Part/App/FeaturePartFuse.cpp index b8025ac5cd..da60adfaca 100644 --- a/tests/src/Mod/Part/App/FeaturePartFuse.cpp +++ b/tests/src/Mod/Part/App/FeaturePartFuse.cpp @@ -206,8 +206,6 @@ TEST_F(FeaturePartFuseTest, testMustExecute) TEST_F(FeaturePartFuseTest, testGetProviderName) { - // Arrange - // Act _fuse->execute(); const char* name = _fuse->getViewProviderName(); From d75b158dcf58e465ec122249cf38ac6f277b22cf Mon Sep 17 00:00:00 2001 From: bgbsww Date: Fri, 22 Dec 2023 16:16:20 -0500 Subject: [PATCH 04/16] Use inheritance and namespaces to keep tests DRY --- tests/src/Mod/Part/App/CMakeLists.txt | 4 +- tests/src/Mod/Part/App/FeaturePartCommon.cpp | 92 ++++----------- tests/src/Mod/Part/App/FeaturePartCut.cpp | 115 +++--------------- tests/src/Mod/Part/App/FeaturePartFuse.cpp | 117 +++---------------- tests/src/Mod/Part/App/PartTestHelpers.cpp | 46 ++++++++ tests/src/Mod/Part/App/PartTestHelpers.h | 22 ++++ 6 files changed, 122 insertions(+), 274 deletions(-) create mode 100644 tests/src/Mod/Part/App/PartTestHelpers.cpp create mode 100644 tests/src/Mod/Part/App/PartTestHelpers.h diff --git a/tests/src/Mod/Part/App/CMakeLists.txt b/tests/src/Mod/Part/App/CMakeLists.txt index 1530cd4bb2..6b1d9a429a 100644 --- a/tests/src/Mod/Part/App/CMakeLists.txt +++ b/tests/src/Mod/Part/App/CMakeLists.txt @@ -6,4 +6,6 @@ target_sources( ${CMAKE_CURRENT_SOURCE_DIR}/FeaturePartCommon.cpp ${CMAKE_CURRENT_SOURCE_DIR}/FeaturePartCut.cpp ${CMAKE_CURRENT_SOURCE_DIR}/FeaturePartFuse.cpp - ) + # ${CMAKE_CURRENT_SOURCE_DIR}/FeatureFillet.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/PartTestHelpers.cpp +) diff --git a/tests/src/Mod/Part/App/FeaturePartCommon.cpp b/tests/src/Mod/Part/App/FeaturePartCommon.cpp index 82a0d0ec77..839c0dc45c 100644 --- a/tests/src/Mod/Part/App/FeaturePartCommon.cpp +++ b/tests/src/Mod/Part/App/FeaturePartCommon.cpp @@ -2,19 +2,12 @@ #include "gtest/gtest.h" -#include -#include -#include -#include -#include -#include -#include "Mod/Part/App/FeaturePartBox.h" #include "Mod/Part/App/FeaturePartCommon.h" #include -// Should some of this go into a FeaturePartBoolean.cpp test suite? +#include "PartTestHelpers.h" -class FeaturePartCommonTest: public ::testing::Test +class FeaturePartCommonTest: public ::testing::Test, public PartTestHelpers::PartTestHelperClass { protected: static void SetUpTestSuite() @@ -25,61 +18,14 @@ protected: void SetUp() override { - _docName = App::GetApplication().getUniqueDocumentName("test"); - _doc = App::GetApplication().newDocument(_docName.c_str(), "testUser"); - _box1obj = static_cast(_doc->addObject("Part::Box")); - _box2obj = static_cast(_doc->addObject("Part::Box")); - _box3obj = static_cast(_doc->addObject("Part::Box")); - _box4obj = static_cast(_doc->addObject("Part::Box")); - _box5obj = static_cast(_doc->addObject("Part::Box")); - _box6obj = static_cast(_doc->addObject("Part::Box")); - _box1obj->Length.setValue(1); - _box1obj->Width.setValue(2); - _box1obj->Height.setValue(3); - _box1obj->Placement.setValue( - Base::Placement(Base::Vector3d(), Base::Rotation(), Base::Vector3d())); - _box2obj->Placement.setValue( - Base::Placement(Base::Vector3d(0, 1, 0), Base::Rotation(), Base::Vector3d())); - _box2obj->Length.setValue(1); - _box2obj->Width.setValue(2); - _box2obj->Height.setValue(3); - _box3obj->Placement.setValue( - Base::Placement(Base::Vector3d(0, 3, 0), Base::Rotation(), Base::Vector3d())); - _box3obj->Length.setValue(1); - _box3obj->Width.setValue(2); - _box3obj->Height.setValue(3); - _box4obj->Placement.setValue( - Base::Placement(Base::Vector3d(0, 2, 0), Base::Rotation(), Base::Vector3d())); - _box4obj->Length.setValue(1); - _box4obj->Width.setValue(2); - _box4obj->Height.setValue(3); - _box5obj->Placement.setValue( - Base::Placement(Base::Vector3d(0, 2 + Base::Precision::Confusion(), 0), - Base::Rotation(), - Base::Vector3d())); - _box5obj->Length.setValue(1); - _box5obj->Width.setValue(2); - _box5obj->Height.setValue(3); - _box6obj->Placement.setValue( - Base::Placement(Base::Vector3d(0, 2 - Base::Precision::Confusion() * 1000, 0), - Base::Rotation(), - Base::Vector3d())); - _box6obj->Length.setValue(1); - _box6obj->Width.setValue(2); - _box6obj->Height.setValue(3); + createTestFile(); _common = static_cast(_doc->addObject("Part::Common")); } void TearDown() override {} - - Part::Box *_box1obj, *_box2obj, *_box3obj, *_box4obj, *_box5obj, *_box6obj; Part::Common* _common; - App::Document* _doc; - -private: - std::string _docName; }; TEST_F(FeaturePartCommonTest, testIntersecting) @@ -91,15 +37,18 @@ TEST_F(FeaturePartCommonTest, testIntersecting) // Act _common->execute(); Part::TopoShape ts = _common->Shape.getValue(); - Base::BoundBox3d bb = ts.getBoundBox(); + // Base::BoundBox3d bb = ts.getBoundBox(); // Assert - EXPECT_EQ(bb.MinX, 0); - EXPECT_EQ(bb.MinY, 1); - EXPECT_EQ(bb.MinZ, 0); - EXPECT_EQ(bb.MaxX, 1); - EXPECT_EQ(bb.MaxY, 2); - EXPECT_EQ(bb.MaxZ, 3); + // If we wanted to be excessive, we could check the bounds: + // EXPECT_EQ(bb.MinX, 0); + // EXPECT_EQ(bb.MinY, 1); + // EXPECT_EQ(bb.MinZ, 0); + // EXPECT_EQ(bb.MaxX, 1); + // EXPECT_EQ(bb.MaxY, 2); + // EXPECT_EQ(bb.MaxZ, 3); + double volume = PartTestHelpers::getVolume(ts.getShape()); + EXPECT_DOUBLE_EQ(volume,3.0); } TEST_F(FeaturePartCommonTest, testNonIntersecting) @@ -115,8 +64,8 @@ TEST_F(FeaturePartCommonTest, testNonIntersecting) // Assert EXPECT_FALSE(bb.IsValid()); - // EXPECT_EQ(bb.Volume(),-1); - // EXPECT_EQ(bb.Volume(),0); + double volume = PartTestHelpers::getVolume(ts.getShape()); + EXPECT_DOUBLE_EQ(volume,0.0); } TEST_F(FeaturePartCommonTest, testTouching) @@ -132,7 +81,8 @@ TEST_F(FeaturePartCommonTest, testTouching) // Assert EXPECT_FALSE(bb.IsValid()); - // EXPECT_EQ(bb.Volume(),0); + double volume = PartTestHelpers::getVolume(ts.getShape()); + EXPECT_DOUBLE_EQ(volume,0.0); } TEST_F(FeaturePartCommonTest, testAlmostTouching) @@ -148,8 +98,8 @@ TEST_F(FeaturePartCommonTest, testAlmostTouching) // Assert EXPECT_FALSE(bb.IsValid()); - // EXPECT_EQ(bb.Volume(),-1); - // EXPECT_EQ(bb.Volume(),0); + double volume = PartTestHelpers::getVolume(ts.getShape()); + EXPECT_DOUBLE_EQ(volume,0.0); } TEST_F(FeaturePartCommonTest, testBarelyIntersecting) @@ -170,6 +120,10 @@ TEST_F(FeaturePartCommonTest, testBarelyIntersecting) EXPECT_EQ(bb.MaxX, 1); EXPECT_EQ(bb.MaxY, 2); EXPECT_EQ(bb.MaxZ, 3); + double volume = PartTestHelpers::getVolume(ts.getShape()); + double target = Base::Precision::Confusion() * 3 * 1000; + // FLOAT, not DOUBLE here, because ULP accuracy would be too precise. + EXPECT_FLOAT_EQ(volume,target); // 0.00029999999999996696); } TEST_F(FeaturePartCommonTest, testMustExecute) diff --git a/tests/src/Mod/Part/App/FeaturePartCut.cpp b/tests/src/Mod/Part/App/FeaturePartCut.cpp index 260b0d6e0f..a788691402 100644 --- a/tests/src/Mod/Part/App/FeaturePartCut.cpp +++ b/tests/src/Mod/Part/App/FeaturePartCut.cpp @@ -2,21 +2,12 @@ #include "gtest/gtest.h" -#include -#include -#include -#include -#include -#include -#include "Mod/Part/App/FeaturePartBox.h" #include "Mod/Part/App/FeaturePartCut.h" #include -#include +#include "PartTestHelpers.h" -// MOST OF THIS SHOULD GO INTO A FeaturePartBoolean.cpp test suite! - -class FeaturePartCutTest: public ::testing::Test +class FeaturePartCutTest: public ::testing::Test, public PartTestHelpers::PartTestHelperClass { protected: static void SetUpTestSuite() @@ -27,48 +18,7 @@ protected: void SetUp() override { - _docName = App::GetApplication().getUniqueDocumentName("test"); - _doc = App::GetApplication().newDocument(_docName.c_str(), "testUser"); - _box1obj = static_cast(_doc->addObject("Part::Box")); - _box1obj->Length.setValue(1); - _box1obj->Width.setValue(2); - _box1obj->Height.setValue(3); - _box1obj->Placement.setValue( - Base::Placement(Base::Vector3d(0, 0, 0), Base::Rotation(), Base::Vector3d(0, 0, 0))); - _box2obj = static_cast(_doc->addObject("Part::Box")); - _box2obj->Placement.setValue( - Base::Placement(Base::Vector3d(0, 1, 0), Base::Rotation(), Base::Vector3d(0, 0, 0))); - _box2obj->Length.setValue(1); - _box2obj->Width.setValue(2); - _box2obj->Height.setValue(3); - _box3obj = static_cast(_doc->addObject("Part::Box")); - _box3obj->Placement.setValue( - Base::Placement(Base::Vector3d(0, 3, 0), Base::Rotation(), Base::Vector3d(0, 0, 0))); - _box3obj->Length.setValue(1); - _box3obj->Width.setValue(2); - _box3obj->Height.setValue(3); - _box4obj = static_cast(_doc->addObject("Part::Box")); - _box4obj->Placement.setValue( - Base::Placement(Base::Vector3d(0, 2, 0), Base::Rotation(), Base::Vector3d(0, 0, 0))); - _box4obj->Length.setValue(1); - _box4obj->Width.setValue(2); - _box4obj->Height.setValue(3); - _box5obj = static_cast(_doc->addObject("Part::Box")); - _box5obj->Placement.setValue( - Base::Placement(Base::Vector3d(0, 2 + Base::Precision::Confusion(), 0), - Base::Rotation(), - Base::Vector3d())); - _box5obj->Length.setValue(1); - _box5obj->Width.setValue(2); - _box5obj->Height.setValue(3); - _box6obj = static_cast(_doc->addObject("Part::Box")); - _box6obj->Placement.setValue( - Base::Placement(Base::Vector3d(0, 2 - Base::Precision::Confusion() * 1000, 0), - Base::Rotation(), - Base::Vector3d())); - _box6obj->Length.setValue(1); - _box6obj->Width.setValue(2); - _box6obj->Height.setValue(3); + createTestFile(); _cut = static_cast(_doc->addObject("Part::Cut")); } @@ -76,12 +26,7 @@ protected: {} - Part::Box *_box1obj, *_box2obj, *_box3obj, *_box4obj, *_box5obj, *_box6obj; Part::Cut* _cut; - App::Document* _doc; - -private: - std::string _docName; }; TEST_F(FeaturePartCutTest, testIntersecting) @@ -93,15 +38,8 @@ TEST_F(FeaturePartCutTest, testIntersecting) // Act _cut->execute(); Part::TopoShape ts = _cut->Shape.getValue(); - Base::BoundBox3d bb = ts.getBoundBox(); - - // Assert - EXPECT_FLOAT_EQ(bb.MinX, 0); - EXPECT_FLOAT_EQ(bb.MinY, 0); - EXPECT_FLOAT_EQ(bb.MinZ, 0); - EXPECT_FLOAT_EQ(bb.MaxX, 1); - EXPECT_FLOAT_EQ(bb.MaxY, 1); - EXPECT_FLOAT_EQ(bb.MaxZ, 3); + double volume = PartTestHelpers::getVolume(ts.getShape()); + EXPECT_DOUBLE_EQ(volume,3.0); } TEST_F(FeaturePartCutTest, testNonIntersecting) @@ -113,15 +51,8 @@ TEST_F(FeaturePartCutTest, testNonIntersecting) // Act _cut->execute(); Part::TopoShape ts = _cut->Shape.getValue(); - Base::BoundBox3d bb = ts.getBoundBox(); - - // Assert - EXPECT_FLOAT_EQ(bb.MinX, 0); - EXPECT_FLOAT_EQ(bb.MinY, 0); - EXPECT_FLOAT_EQ(bb.MinZ, 0); - EXPECT_FLOAT_EQ(bb.MaxX, 1); - EXPECT_FLOAT_EQ(bb.MaxY, 2); - EXPECT_FLOAT_EQ(bb.MaxZ, 3); + double volume = PartTestHelpers::getVolume(ts.getShape()); + EXPECT_DOUBLE_EQ(volume,6.0); } TEST_F(FeaturePartCutTest, testTouching) @@ -133,15 +64,10 @@ TEST_F(FeaturePartCutTest, testTouching) // Act _cut->execute(); Part::TopoShape ts = _cut->Shape.getValue(); - Base::BoundBox3d bb = ts.getBoundBox(); + double volume = PartTestHelpers::getVolume(ts.getShape()); // Assert - EXPECT_FLOAT_EQ(bb.MinX, 0); - EXPECT_FLOAT_EQ(bb.MinY, 0); - EXPECT_FLOAT_EQ(bb.MinZ, 0); - EXPECT_FLOAT_EQ(bb.MaxX, 1); - EXPECT_FLOAT_EQ(bb.MaxY, 2); - EXPECT_FLOAT_EQ(bb.MaxZ, 3); + EXPECT_DOUBLE_EQ(volume,6.0); } TEST_F(FeaturePartCutTest, testAlmostTouching) @@ -153,15 +79,8 @@ TEST_F(FeaturePartCutTest, testAlmostTouching) // Act _cut->execute(); Part::TopoShape ts = _cut->Shape.getValue(); - Base::BoundBox3d bb = ts.getBoundBox(); - - // Assert - EXPECT_FLOAT_EQ(bb.MinX, 0); - EXPECT_FLOAT_EQ(bb.MinY, 0); - EXPECT_FLOAT_EQ(bb.MinZ, 0); - EXPECT_FLOAT_EQ(bb.MaxX, 1); - EXPECT_FLOAT_EQ(bb.MaxY, 2); - EXPECT_FLOAT_EQ(bb.MaxZ, 3); + double volume = PartTestHelpers::getVolume(ts.getShape()); + EXPECT_DOUBLE_EQ(volume,6.0); } TEST_F(FeaturePartCutTest, testBarelyIntersecting) @@ -173,15 +92,9 @@ TEST_F(FeaturePartCutTest, testBarelyIntersecting) // Act _cut->execute(); Part::TopoShape ts = _cut->Shape.getValue(); - Base::BoundBox3d bb = ts.getBoundBox(); - - // Assert - EXPECT_FLOAT_EQ(bb.MinX, 0); - EXPECT_FLOAT_EQ(bb.MinY, 0); - EXPECT_FLOAT_EQ(bb.MinZ, 0); - EXPECT_FLOAT_EQ(bb.MaxX, 1); - EXPECT_FLOAT_EQ(bb.MaxY, 1.9999); - EXPECT_FLOAT_EQ(bb.MaxZ, 3); + double volume = PartTestHelpers::getVolume(ts.getShape()); + double target = 6 - Base::Precision::Confusion() * 3 * 1000; + EXPECT_FLOAT_EQ(volume,target); } TEST_F(FeaturePartCutTest, testMustExecute) diff --git a/tests/src/Mod/Part/App/FeaturePartFuse.cpp b/tests/src/Mod/Part/App/FeaturePartFuse.cpp index da60adfaca..7e666de6b0 100644 --- a/tests/src/Mod/Part/App/FeaturePartFuse.cpp +++ b/tests/src/Mod/Part/App/FeaturePartFuse.cpp @@ -2,21 +2,13 @@ #include "gtest/gtest.h" -#include -#include -#include -#include -#include -#include -#include "Mod/Part/App/FeaturePartBox.h" #include "Mod/Part/App/FeaturePartFuse.h" #include -#include +#include "PartTestHelpers.h" -// MOST OF THIS SHOULD GO INTO A FeaturePartBoolean.cpp test suite! -class FeaturePartFuseTest: public ::testing::Test +class FeaturePartFuseTest: public ::testing::Test, public PartTestHelpers::PartTestHelperClass { protected: static void SetUpTestSuite() @@ -27,61 +19,14 @@ protected: void SetUp() override { - _docName = App::GetApplication().getUniqueDocumentName("test"); - _doc = App::GetApplication().newDocument(_docName.c_str(), "testUser"); - _box1obj = static_cast(_doc->addObject("Part::Box")); - _box1obj->Length.setValue(1); - _box1obj->Width.setValue(2); - _box1obj->Height.setValue(3); - _box1obj->Placement.setValue( - Base::Placement(Base::Vector3d(0, 0, 0), Base::Rotation(), Base::Vector3d(0, 0, 0))); - _box2obj = static_cast(_doc->addObject("Part::Box")); - _box2obj->Placement.setValue( - Base::Placement(Base::Vector3d(0, 1, 0), Base::Rotation(), Base::Vector3d(0, 0, 0))); - _box2obj->Length.setValue(1); - _box2obj->Width.setValue(2); - _box2obj->Height.setValue(3); - _box3obj = static_cast(_doc->addObject("Part::Box")); - _box3obj->Placement.setValue( - Base::Placement(Base::Vector3d(0, 3, 0), Base::Rotation(), Base::Vector3d(0, 0, 0))); - _box3obj->Length.setValue(1); - _box3obj->Width.setValue(2); - _box3obj->Height.setValue(3); - _box4obj = static_cast(_doc->addObject("Part::Box")); - _box4obj->Placement.setValue( - Base::Placement(Base::Vector3d(0, 2, 0), Base::Rotation(), Base::Vector3d(0, 0, 0))); - _box4obj->Length.setValue(1); - _box4obj->Width.setValue(2); - _box4obj->Height.setValue(3); - _box5obj = static_cast(_doc->addObject("Part::Box")); - _box5obj->Placement.setValue( - Base::Placement(Base::Vector3d(0, 2 + Base::Precision::Confusion(), 0), - Base::Rotation(), - Base::Vector3d())); - _box5obj->Length.setValue(1); - _box5obj->Width.setValue(2); - _box5obj->Height.setValue(3); - _box6obj = static_cast(_doc->addObject("Part::Box")); - _box6obj->Placement.setValue( - Base::Placement(Base::Vector3d(0, 2 - Base::Precision::Confusion() * 1000, 0), - Base::Rotation(), - Base::Vector3d())); - _box6obj->Length.setValue(1); - _box6obj->Width.setValue(2); - _box6obj->Height.setValue(3); + createTestFile(); _fuse = static_cast(_doc->addObject("Part::Fuse")); } void TearDown() override {} - - Part::Box *_box1obj, *_box2obj, *_box3obj, *_box4obj, *_box5obj, *_box6obj; Part::Fuse* _fuse; - App::Document* _doc; - -private: - std::string _docName; }; TEST_F(FeaturePartFuseTest, testIntersecting) @@ -93,15 +38,8 @@ TEST_F(FeaturePartFuseTest, testIntersecting) // Act _fuse->execute(); Part::TopoShape ts = _fuse->Shape.getValue(); - Base::BoundBox3d bb = ts.getBoundBox(); - - // Assert - EXPECT_FLOAT_EQ(bb.MinX, 0); - EXPECT_FLOAT_EQ(bb.MinY, 0); - EXPECT_FLOAT_EQ(bb.MinZ, 0); - EXPECT_FLOAT_EQ(bb.MaxX, 1); - EXPECT_FLOAT_EQ(bb.MaxY, 3); - EXPECT_FLOAT_EQ(bb.MaxZ, 3); + double volume = PartTestHelpers::getVolume(ts.getShape()); + EXPECT_DOUBLE_EQ(volume,9.0); } TEST_F(FeaturePartFuseTest, testNonIntersecting) @@ -113,15 +51,8 @@ TEST_F(FeaturePartFuseTest, testNonIntersecting) // Act _fuse->execute(); Part::TopoShape ts = _fuse->Shape.getValue(); - Base::BoundBox3d bb = ts.getBoundBox(); - - // Assert - EXPECT_FLOAT_EQ(bb.MinX, 0); - EXPECT_FLOAT_EQ(bb.MinY, 0); - EXPECT_FLOAT_EQ(bb.MinZ, 0); - EXPECT_FLOAT_EQ(bb.MaxX, 1); - EXPECT_FLOAT_EQ(bb.MaxY, 5); - EXPECT_FLOAT_EQ(bb.MaxZ, 3); + double volume = PartTestHelpers::getVolume(ts.getShape()); + EXPECT_DOUBLE_EQ(volume,12.0); } TEST_F(FeaturePartFuseTest, testTouching) @@ -133,15 +64,8 @@ TEST_F(FeaturePartFuseTest, testTouching) // Act _fuse->execute(); Part::TopoShape ts = _fuse->Shape.getValue(); - Base::BoundBox3d bb = ts.getBoundBox(); - - // Assert - EXPECT_FLOAT_EQ(bb.MinX, 0); - EXPECT_FLOAT_EQ(bb.MinY, 0); - EXPECT_FLOAT_EQ(bb.MinZ, 0); - EXPECT_FLOAT_EQ(bb.MaxX, 1); - EXPECT_FLOAT_EQ(bb.MaxY, 4); - EXPECT_FLOAT_EQ(bb.MaxZ, 3); + double volume = PartTestHelpers::getVolume(ts.getShape()); + EXPECT_DOUBLE_EQ(volume,12.0); } TEST_F(FeaturePartFuseTest, testAlmostTouching) @@ -153,15 +77,8 @@ TEST_F(FeaturePartFuseTest, testAlmostTouching) // Act _fuse->execute(); Part::TopoShape ts = _fuse->Shape.getValue(); - Base::BoundBox3d bb = ts.getBoundBox(); - - // Assert - EXPECT_FLOAT_EQ(bb.MinX, 0); - EXPECT_FLOAT_EQ(bb.MinY, 0); - EXPECT_FLOAT_EQ(bb.MinZ, 0); - EXPECT_FLOAT_EQ(bb.MaxX, 1); - EXPECT_FLOAT_EQ(bb.MaxY, 4); - EXPECT_FLOAT_EQ(bb.MaxZ, 3); + double volume = PartTestHelpers::getVolume(ts.getShape()); + EXPECT_FLOAT_EQ(volume,12.0); } TEST_F(FeaturePartFuseTest, testBarelyIntersecting) @@ -173,15 +90,9 @@ TEST_F(FeaturePartFuseTest, testBarelyIntersecting) // Act _fuse->execute(); Part::TopoShape ts = _fuse->Shape.getValue(); - Base::BoundBox3d bb = ts.getBoundBox(); - - // Assert - EXPECT_FLOAT_EQ(bb.MinX, 0); - EXPECT_FLOAT_EQ(bb.MinY, 0); - EXPECT_FLOAT_EQ(bb.MinZ, 0); - EXPECT_FLOAT_EQ(bb.MaxX, 1); - EXPECT_FLOAT_EQ(bb.MaxY, 3.9999); - EXPECT_FLOAT_EQ(bb.MaxZ, 3); + double volume = PartTestHelpers::getVolume(ts.getShape()); + double target = 12 - Base::Precision::Confusion() * 3 * 1000; + EXPECT_FLOAT_EQ(volume,target); } TEST_F(FeaturePartFuseTest, testMustExecute) diff --git a/tests/src/Mod/Part/App/PartTestHelpers.cpp b/tests/src/Mod/Part/App/PartTestHelpers.cpp new file mode 100644 index 0000000000..1de59e7cfd --- /dev/null +++ b/tests/src/Mod/Part/App/PartTestHelpers.cpp @@ -0,0 +1,46 @@ + +#include "PartTestHelpers.h" + +namespace PartTestHelpers { + +double getVolume(TopoDS_Shape shape) +{ + GProp_GProps prop; + BRepGProp::VolumeProperties(shape, prop); + return prop.Mass(); +} + +void PartTestHelperClass::createTestFile() +{ + _docName = App::GetApplication().getUniqueDocumentName("test"); + _doc = App::GetApplication().newDocument(_docName.c_str(), "testUser"); + _box1obj = static_cast(_doc->addObject("Part::Box")); + _box2obj = static_cast(_doc->addObject("Part::Box")); + _box3obj = static_cast(_doc->addObject("Part::Box")); + _box4obj = static_cast(_doc->addObject("Part::Box")); + _box5obj = static_cast(_doc->addObject("Part::Box")); + _box6obj = static_cast(_doc->addObject("Part::Box")); + for ( auto _box : {_box1obj, _box2obj, _box3obj, _box4obj, _box5obj, _box6obj} ) { + _box->Length.setValue(1); + _box->Width.setValue(2); + _box->Height.setValue(3); + } + _box1obj->Placement.setValue( + Base::Placement(Base::Vector3d(), Base::Rotation(), Base::Vector3d())); + _box2obj->Placement.setValue( + Base::Placement(Base::Vector3d(0, 1, 0), Base::Rotation(), Base::Vector3d())); + _box3obj->Placement.setValue( + Base::Placement(Base::Vector3d(0, 3, 0), Base::Rotation(), Base::Vector3d())); + _box4obj->Placement.setValue( + Base::Placement(Base::Vector3d(0, 2, 0), Base::Rotation(), Base::Vector3d())); + _box5obj->Placement.setValue( + Base::Placement(Base::Vector3d(0, 2 + Base::Precision::Confusion(), 0), + Base::Rotation(), + Base::Vector3d())); + _box6obj->Placement.setValue( + Base::Placement(Base::Vector3d(0, 2 - Base::Precision::Confusion() * 1000, 0), + Base::Rotation(), + Base::Vector3d())); +} + +} \ No newline at end of file diff --git a/tests/src/Mod/Part/App/PartTestHelpers.h b/tests/src/Mod/Part/App/PartTestHelpers.h new file mode 100644 index 0000000000..a6bdfd37b9 --- /dev/null +++ b/tests/src/Mod/Part/App/PartTestHelpers.h @@ -0,0 +1,22 @@ +#include +#include +#include +#include "Mod/Part/App/FeaturePartBox.h" +#include "Mod/Part/App/FeaturePartFuse.h" +#include "Mod/Part/App/FeatureFillet.h" +#include + +namespace PartTestHelpers { + +double getVolume(TopoDS_Shape shape); + +class PartTestHelperClass { +public: + App::Document* _doc; + std::string _docName; + Part::Box *_box1obj, *_box2obj, *_box3obj, *_box4obj, *_box5obj, *_box6obj; + + void createTestFile(); +}; + +} \ No newline at end of file From 5d480149993cc188a6504977d5535f15dec6de88 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 22 Dec 2023 21:17:02 +0000 Subject: [PATCH 05/16] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/src/Mod/Part/App/FeaturePartCommon.cpp | 10 ++-- tests/src/Mod/Part/App/FeaturePartCut.cpp | 10 ++-- tests/src/Mod/Part/App/FeaturePartFuse.cpp | 10 ++-- tests/src/Mod/Part/App/PartTestHelpers.cpp | 63 ++++++++++---------- tests/src/Mod/Part/App/PartTestHelpers.h | 8 ++- 5 files changed, 52 insertions(+), 49 deletions(-) diff --git a/tests/src/Mod/Part/App/FeaturePartCommon.cpp b/tests/src/Mod/Part/App/FeaturePartCommon.cpp index 839c0dc45c..f4487b4dcb 100644 --- a/tests/src/Mod/Part/App/FeaturePartCommon.cpp +++ b/tests/src/Mod/Part/App/FeaturePartCommon.cpp @@ -48,7 +48,7 @@ TEST_F(FeaturePartCommonTest, testIntersecting) // EXPECT_EQ(bb.MaxY, 2); // EXPECT_EQ(bb.MaxZ, 3); double volume = PartTestHelpers::getVolume(ts.getShape()); - EXPECT_DOUBLE_EQ(volume,3.0); + EXPECT_DOUBLE_EQ(volume, 3.0); } TEST_F(FeaturePartCommonTest, testNonIntersecting) @@ -65,7 +65,7 @@ TEST_F(FeaturePartCommonTest, testNonIntersecting) // Assert EXPECT_FALSE(bb.IsValid()); double volume = PartTestHelpers::getVolume(ts.getShape()); - EXPECT_DOUBLE_EQ(volume,0.0); + EXPECT_DOUBLE_EQ(volume, 0.0); } TEST_F(FeaturePartCommonTest, testTouching) @@ -82,7 +82,7 @@ TEST_F(FeaturePartCommonTest, testTouching) // Assert EXPECT_FALSE(bb.IsValid()); double volume = PartTestHelpers::getVolume(ts.getShape()); - EXPECT_DOUBLE_EQ(volume,0.0); + EXPECT_DOUBLE_EQ(volume, 0.0); } TEST_F(FeaturePartCommonTest, testAlmostTouching) @@ -99,7 +99,7 @@ TEST_F(FeaturePartCommonTest, testAlmostTouching) // Assert EXPECT_FALSE(bb.IsValid()); double volume = PartTestHelpers::getVolume(ts.getShape()); - EXPECT_DOUBLE_EQ(volume,0.0); + EXPECT_DOUBLE_EQ(volume, 0.0); } TEST_F(FeaturePartCommonTest, testBarelyIntersecting) @@ -123,7 +123,7 @@ TEST_F(FeaturePartCommonTest, testBarelyIntersecting) double volume = PartTestHelpers::getVolume(ts.getShape()); double target = Base::Precision::Confusion() * 3 * 1000; // FLOAT, not DOUBLE here, because ULP accuracy would be too precise. - EXPECT_FLOAT_EQ(volume,target); // 0.00029999999999996696); + EXPECT_FLOAT_EQ(volume, target); // 0.00029999999999996696); } TEST_F(FeaturePartCommonTest, testMustExecute) diff --git a/tests/src/Mod/Part/App/FeaturePartCut.cpp b/tests/src/Mod/Part/App/FeaturePartCut.cpp index a788691402..1da983a4b9 100644 --- a/tests/src/Mod/Part/App/FeaturePartCut.cpp +++ b/tests/src/Mod/Part/App/FeaturePartCut.cpp @@ -39,7 +39,7 @@ TEST_F(FeaturePartCutTest, testIntersecting) _cut->execute(); Part::TopoShape ts = _cut->Shape.getValue(); double volume = PartTestHelpers::getVolume(ts.getShape()); - EXPECT_DOUBLE_EQ(volume,3.0); + EXPECT_DOUBLE_EQ(volume, 3.0); } TEST_F(FeaturePartCutTest, testNonIntersecting) @@ -52,7 +52,7 @@ TEST_F(FeaturePartCutTest, testNonIntersecting) _cut->execute(); Part::TopoShape ts = _cut->Shape.getValue(); double volume = PartTestHelpers::getVolume(ts.getShape()); - EXPECT_DOUBLE_EQ(volume,6.0); + EXPECT_DOUBLE_EQ(volume, 6.0); } TEST_F(FeaturePartCutTest, testTouching) @@ -67,7 +67,7 @@ TEST_F(FeaturePartCutTest, testTouching) double volume = PartTestHelpers::getVolume(ts.getShape()); // Assert - EXPECT_DOUBLE_EQ(volume,6.0); + EXPECT_DOUBLE_EQ(volume, 6.0); } TEST_F(FeaturePartCutTest, testAlmostTouching) @@ -80,7 +80,7 @@ TEST_F(FeaturePartCutTest, testAlmostTouching) _cut->execute(); Part::TopoShape ts = _cut->Shape.getValue(); double volume = PartTestHelpers::getVolume(ts.getShape()); - EXPECT_DOUBLE_EQ(volume,6.0); + EXPECT_DOUBLE_EQ(volume, 6.0); } TEST_F(FeaturePartCutTest, testBarelyIntersecting) @@ -94,7 +94,7 @@ TEST_F(FeaturePartCutTest, testBarelyIntersecting) Part::TopoShape ts = _cut->Shape.getValue(); double volume = PartTestHelpers::getVolume(ts.getShape()); double target = 6 - Base::Precision::Confusion() * 3 * 1000; - EXPECT_FLOAT_EQ(volume,target); + EXPECT_FLOAT_EQ(volume, target); } TEST_F(FeaturePartCutTest, testMustExecute) diff --git a/tests/src/Mod/Part/App/FeaturePartFuse.cpp b/tests/src/Mod/Part/App/FeaturePartFuse.cpp index 7e666de6b0..c0694ac23a 100644 --- a/tests/src/Mod/Part/App/FeaturePartFuse.cpp +++ b/tests/src/Mod/Part/App/FeaturePartFuse.cpp @@ -39,7 +39,7 @@ TEST_F(FeaturePartFuseTest, testIntersecting) _fuse->execute(); Part::TopoShape ts = _fuse->Shape.getValue(); double volume = PartTestHelpers::getVolume(ts.getShape()); - EXPECT_DOUBLE_EQ(volume,9.0); + EXPECT_DOUBLE_EQ(volume, 9.0); } TEST_F(FeaturePartFuseTest, testNonIntersecting) @@ -52,7 +52,7 @@ TEST_F(FeaturePartFuseTest, testNonIntersecting) _fuse->execute(); Part::TopoShape ts = _fuse->Shape.getValue(); double volume = PartTestHelpers::getVolume(ts.getShape()); - EXPECT_DOUBLE_EQ(volume,12.0); + EXPECT_DOUBLE_EQ(volume, 12.0); } TEST_F(FeaturePartFuseTest, testTouching) @@ -65,7 +65,7 @@ TEST_F(FeaturePartFuseTest, testTouching) _fuse->execute(); Part::TopoShape ts = _fuse->Shape.getValue(); double volume = PartTestHelpers::getVolume(ts.getShape()); - EXPECT_DOUBLE_EQ(volume,12.0); + EXPECT_DOUBLE_EQ(volume, 12.0); } TEST_F(FeaturePartFuseTest, testAlmostTouching) @@ -78,7 +78,7 @@ TEST_F(FeaturePartFuseTest, testAlmostTouching) _fuse->execute(); Part::TopoShape ts = _fuse->Shape.getValue(); double volume = PartTestHelpers::getVolume(ts.getShape()); - EXPECT_FLOAT_EQ(volume,12.0); + EXPECT_FLOAT_EQ(volume, 12.0); } TEST_F(FeaturePartFuseTest, testBarelyIntersecting) @@ -92,7 +92,7 @@ TEST_F(FeaturePartFuseTest, testBarelyIntersecting) Part::TopoShape ts = _fuse->Shape.getValue(); double volume = PartTestHelpers::getVolume(ts.getShape()); double target = 12 - Base::Precision::Confusion() * 3 * 1000; - EXPECT_FLOAT_EQ(volume,target); + EXPECT_FLOAT_EQ(volume, target); } TEST_F(FeaturePartFuseTest, testMustExecute) diff --git a/tests/src/Mod/Part/App/PartTestHelpers.cpp b/tests/src/Mod/Part/App/PartTestHelpers.cpp index 1de59e7cfd..11e6b17999 100644 --- a/tests/src/Mod/Part/App/PartTestHelpers.cpp +++ b/tests/src/Mod/Part/App/PartTestHelpers.cpp @@ -1,7 +1,8 @@ #include "PartTestHelpers.h" -namespace PartTestHelpers { +namespace PartTestHelpers +{ double getVolume(TopoDS_Shape shape) { @@ -12,35 +13,35 @@ double getVolume(TopoDS_Shape shape) void PartTestHelperClass::createTestFile() { - _docName = App::GetApplication().getUniqueDocumentName("test"); - _doc = App::GetApplication().newDocument(_docName.c_str(), "testUser"); - _box1obj = static_cast(_doc->addObject("Part::Box")); - _box2obj = static_cast(_doc->addObject("Part::Box")); - _box3obj = static_cast(_doc->addObject("Part::Box")); - _box4obj = static_cast(_doc->addObject("Part::Box")); - _box5obj = static_cast(_doc->addObject("Part::Box")); - _box6obj = static_cast(_doc->addObject("Part::Box")); - for ( auto _box : {_box1obj, _box2obj, _box3obj, _box4obj, _box5obj, _box6obj} ) { - _box->Length.setValue(1); - _box->Width.setValue(2); - _box->Height.setValue(3); - } - _box1obj->Placement.setValue( - Base::Placement(Base::Vector3d(), Base::Rotation(), Base::Vector3d())); - _box2obj->Placement.setValue( - Base::Placement(Base::Vector3d(0, 1, 0), Base::Rotation(), Base::Vector3d())); - _box3obj->Placement.setValue( - Base::Placement(Base::Vector3d(0, 3, 0), Base::Rotation(), Base::Vector3d())); - _box4obj->Placement.setValue( - Base::Placement(Base::Vector3d(0, 2, 0), Base::Rotation(), Base::Vector3d())); - _box5obj->Placement.setValue( - Base::Placement(Base::Vector3d(0, 2 + Base::Precision::Confusion(), 0), - Base::Rotation(), - Base::Vector3d())); - _box6obj->Placement.setValue( - Base::Placement(Base::Vector3d(0, 2 - Base::Precision::Confusion() * 1000, 0), - Base::Rotation(), - Base::Vector3d())); + _docName = App::GetApplication().getUniqueDocumentName("test"); + _doc = App::GetApplication().newDocument(_docName.c_str(), "testUser"); + _box1obj = static_cast(_doc->addObject("Part::Box")); + _box2obj = static_cast(_doc->addObject("Part::Box")); + _box3obj = static_cast(_doc->addObject("Part::Box")); + _box4obj = static_cast(_doc->addObject("Part::Box")); + _box5obj = static_cast(_doc->addObject("Part::Box")); + _box6obj = static_cast(_doc->addObject("Part::Box")); + for (auto _box : {_box1obj, _box2obj, _box3obj, _box4obj, _box5obj, _box6obj}) { + _box->Length.setValue(1); + _box->Width.setValue(2); + _box->Height.setValue(3); + } + _box1obj->Placement.setValue( + Base::Placement(Base::Vector3d(), Base::Rotation(), Base::Vector3d())); + _box2obj->Placement.setValue( + Base::Placement(Base::Vector3d(0, 1, 0), Base::Rotation(), Base::Vector3d())); + _box3obj->Placement.setValue( + Base::Placement(Base::Vector3d(0, 3, 0), Base::Rotation(), Base::Vector3d())); + _box4obj->Placement.setValue( + Base::Placement(Base::Vector3d(0, 2, 0), Base::Rotation(), Base::Vector3d())); + _box5obj->Placement.setValue( + Base::Placement(Base::Vector3d(0, 2 + Base::Precision::Confusion(), 0), + Base::Rotation(), + Base::Vector3d())); + _box6obj->Placement.setValue( + Base::Placement(Base::Vector3d(0, 2 - Base::Precision::Confusion() * 1000, 0), + Base::Rotation(), + Base::Vector3d())); } -} \ No newline at end of file +} // namespace PartTestHelpers diff --git a/tests/src/Mod/Part/App/PartTestHelpers.h b/tests/src/Mod/Part/App/PartTestHelpers.h index a6bdfd37b9..1b6ffa1d8e 100644 --- a/tests/src/Mod/Part/App/PartTestHelpers.h +++ b/tests/src/Mod/Part/App/PartTestHelpers.h @@ -6,11 +6,13 @@ #include "Mod/Part/App/FeatureFillet.h" #include -namespace PartTestHelpers { +namespace PartTestHelpers +{ double getVolume(TopoDS_Shape shape); -class PartTestHelperClass { +class PartTestHelperClass +{ public: App::Document* _doc; std::string _docName; @@ -19,4 +21,4 @@ public: void createTestFile(); }; -} \ No newline at end of file +} // namespace PartTestHelpers From 619d2c970f5be256639c751e9149e0bed760fba0 Mon Sep 17 00:00:00 2001 From: bgbsww Date: Sat, 23 Dec 2023 05:47:39 -0500 Subject: [PATCH 06/16] Cleanups per pesc0 review notes; general code tightening --- tests/src/Mod/Part/App/FeaturePartCommon.cpp | 151 ++++++++----------- tests/src/Mod/Part/App/FeaturePartCut.cpp | 106 +++++++++---- tests/src/Mod/Part/App/FeaturePartFuse.cpp | 122 ++++++++++----- tests/src/Mod/Part/App/PartTestHelpers.cpp | 75 +++++---- tests/src/Mod/Part/App/PartTestHelpers.h | 5 +- 5 files changed, 277 insertions(+), 182 deletions(-) diff --git a/tests/src/Mod/Part/App/FeaturePartCommon.cpp b/tests/src/Mod/Part/App/FeaturePartCommon.cpp index f4487b4dcb..d379df6b5c 100644 --- a/tests/src/Mod/Part/App/FeaturePartCommon.cpp +++ b/tests/src/Mod/Part/App/FeaturePartCommon.cpp @@ -18,7 +18,7 @@ protected: void SetUp() override { - createTestFile(); + createTestDoc(); _common = static_cast(_doc->addObject("Part::Common")); } @@ -31,119 +31,119 @@ protected: TEST_F(FeaturePartCommonTest, testIntersecting) { // Arrange - _common->Base.setValue(_box1obj); - _common->Tool.setValue(_box2obj); + _common->Base.setValue(_boxes[0]); + _common->Tool.setValue(_boxes[1]); // Act _common->execute(); Part::TopoShape ts = _common->Shape.getValue(); - // Base::BoundBox3d bb = ts.getBoundBox(); + double volume = PartTestHelpers::getVolume(ts.getShape()); + Base::BoundBox3d bb = ts.getBoundBox(); // Assert - // If we wanted to be excessive, we could check the bounds: - // EXPECT_EQ(bb.MinX, 0); - // EXPECT_EQ(bb.MinY, 1); - // EXPECT_EQ(bb.MinZ, 0); - // EXPECT_EQ(bb.MaxX, 1); - // EXPECT_EQ(bb.MaxY, 2); - // EXPECT_EQ(bb.MaxZ, 3); - double volume = PartTestHelpers::getVolume(ts.getShape()); EXPECT_DOUBLE_EQ(volume, 3.0); + // double check using bounds: + EXPECT_DOUBLE_EQ(bb.MinX, 0.0); + EXPECT_DOUBLE_EQ(bb.MinY, 1.0); + EXPECT_DOUBLE_EQ(bb.MinZ, 0.0); + EXPECT_DOUBLE_EQ(bb.MaxX, 1.0); + EXPECT_DOUBLE_EQ(bb.MaxY, 2.0); + EXPECT_DOUBLE_EQ(bb.MaxZ, 3.0); } TEST_F(FeaturePartCommonTest, testNonIntersecting) { // Arrange - _common->Base.setValue(_box1obj); - _common->Tool.setValue(_box3obj); + _common->Base.setValue(_boxes[0]); + _common->Tool.setValue(_boxes[2]); // Act _common->execute(); Part::TopoShape ts = _common->Shape.getValue(); + double volume = PartTestHelpers::getVolume(ts.getShape()); Base::BoundBox3d bb = ts.getBoundBox(); // Assert EXPECT_FALSE(bb.IsValid()); - double volume = PartTestHelpers::getVolume(ts.getShape()); EXPECT_DOUBLE_EQ(volume, 0.0); } TEST_F(FeaturePartCommonTest, testTouching) { // Arrange - _common->Base.setValue(_box1obj); - _common->Tool.setValue(_box4obj); + _common->Base.setValue(_boxes[0]); + _common->Tool.setValue(_boxes[3]); // Act _common->execute(); Part::TopoShape ts = _common->Shape.getValue(); + double volume = PartTestHelpers::getVolume(ts.getShape()); Base::BoundBox3d bb = ts.getBoundBox(); // Assert EXPECT_FALSE(bb.IsValid()); - double volume = PartTestHelpers::getVolume(ts.getShape()); EXPECT_DOUBLE_EQ(volume, 0.0); } TEST_F(FeaturePartCommonTest, testAlmostTouching) { // Arrange - _common->Base.setValue(_box1obj); - _common->Tool.setValue(_box5obj); + _common->Base.setValue(_boxes[0]); + _common->Tool.setValue(_boxes[4]); // Act _common->execute(); Part::TopoShape ts = _common->Shape.getValue(); + double volume = PartTestHelpers::getVolume(ts.getShape()); Base::BoundBox3d bb = ts.getBoundBox(); // Assert EXPECT_FALSE(bb.IsValid()); - double volume = PartTestHelpers::getVolume(ts.getShape()); EXPECT_DOUBLE_EQ(volume, 0.0); } TEST_F(FeaturePartCommonTest, testBarelyIntersecting) { // Arrange - _common->Base.setValue(_box1obj); - _common->Tool.setValue(_box6obj); + _common->Base.setValue(_boxes[0]); + _common->Tool.setValue(_boxes[5]); // Act _common->execute(); Part::TopoShape ts = _common->Shape.getValue(); + double volume = PartTestHelpers::getVolume(ts.getShape()); + double target = Base::Precision::Confusion() * 3 * 1000; // Reduce precision to 1e04 over 3 dimensions Base::BoundBox3d bb = ts.getBoundBox(); // Assert - EXPECT_EQ(bb.MinX, 0); - EXPECT_EQ(bb.MinY, 1.9999); - EXPECT_EQ(bb.MinZ, 0); - EXPECT_EQ(bb.MaxX, 1); - EXPECT_EQ(bb.MaxY, 2); - EXPECT_EQ(bb.MaxZ, 3); - double volume = PartTestHelpers::getVolume(ts.getShape()); - double target = Base::Precision::Confusion() * 3 * 1000; - // FLOAT, not DOUBLE here, because ULP accuracy would be too precise. - EXPECT_FLOAT_EQ(volume, target); // 0.00029999999999996696); + // Using FLOAT, not DOUBLE here so test library comparison is of reasonable precision 1e07 rather than 1e15 + // See https://google.github.io/googletest/reference/assertions.html#floating-point + EXPECT_FLOAT_EQ(volume, target); // Should be approximately 0.00029999999999996696 + // double check using bounds: + EXPECT_DOUBLE_EQ(bb.MinX, 0.0); + EXPECT_DOUBLE_EQ(bb.MinY, 1.9999); + EXPECT_DOUBLE_EQ(bb.MinZ, 0.0); + EXPECT_DOUBLE_EQ(bb.MaxX, 1.0); + EXPECT_DOUBLE_EQ(bb.MaxY, 2.0); + EXPECT_DOUBLE_EQ(bb.MaxZ, 3.0); } TEST_F(FeaturePartCommonTest, testMustExecute) { - // Act - short mE = _common->mustExecute(); - // Assert - EXPECT_FALSE(mE); - _common->Base.setValue(_box1obj); - // Assert - mE = _common->mustExecute(); - EXPECT_FALSE(mE); - // Act - _common->Tool.setValue(_box2obj); - // Assert - mE = _common->mustExecute(); - EXPECT_TRUE(mE); + // Assert initially we don't need to execute + EXPECT_FALSE(_common->mustExecute()); + // Act to change one property + _common->Base.setValue(_boxes[0]); + // Assert we still can't execute + EXPECT_FALSE(_common->mustExecute()); + // Act to complete the properties we need + _common->Tool.setValue(_boxes[1]); + // Assert that we now must execute + EXPECT_TRUE(_common->mustExecute()); + // Act to execute _doc->recompute(); - mE = _common->mustExecute(); - EXPECT_FALSE(mE); + // Assert we don't need to execute anymore + EXPECT_FALSE(_common->mustExecute()); } TEST_F(FeaturePartCommonTest, testGetProviderName) @@ -155,55 +155,38 @@ TEST_F(FeaturePartCommonTest, testGetProviderName) EXPECT_STREQ(name, "PartGui::ViewProviderBoolean"); } -namespace Part -{ -void PrintTo(ShapeHistory sh, std::ostream* os) -{ - const char* types[] = - {"Compound", "CompSolid", "Solid", "Shell", "Face", "Wire", "Edge", "Vertex", "Shape"}; - *os << "History for " << types[sh.type] << " is "; - for (const auto& it : sh.shapeMap) { - int old_shape_index = it.first; - *os << " " << old_shape_index << ": "; - if (!it.second.empty()) { - for (auto it2 : it.second) { - *os << it2 << " "; - } - } - } - *os << std::endl; -} -} // namespace Part - TEST_F(FeaturePartCommonTest, testHistory) { // Arrange - _common->Base.setValue(_box1obj); - _common->Tool.setValue(_box2obj); - - // Act and Assert - std::vector hist = _common->History.getValues(); - EXPECT_EQ(hist.size(), 0); - - // This creates the histories classically generated by FreeCAD for comparison + _common->Base.setValue(_boxes[0]); + _common->Tool.setValue(_boxes[1]); + // Manually create the histories classically generated by FreeCAD for comparison using MapList = std::map>; using List = std::vector; MapList compare1 = - {{0, List {0}}, {1, List {5}}, {2, List()}, {3, List {2}}, {4, List {3}}, {5, List {1}}}; + {{0, List {0}}, {1, List {5}}, {2, List () }, {3, List {2}}, {4, List {3}}, {5, List {1}}}; MapList compare2 = - {{0, List {0}}, {1, List {5}}, {2, List {4}}, {3, List()}, {4, List {3}}, {5, List {1}}}; + {{0, List {0}}, {1, List {5}}, {2, List {4}}, {3, List () }, {4, List {3}}, {5, List {1}}}; + // Act and Assert no histories yet + std::vector hist = _common->History.getValues(); + EXPECT_EQ(hist.size(), 0); + + // Act to generate histories _common->execute(); hist = _common->History.getValues(); - EXPECT_EQ(hist.size(), 2); + // Assert + ASSERT_EQ(hist.size(), 2); EXPECT_EQ(hist[0].shapeMap, compare1); EXPECT_EQ(hist[1].shapeMap, compare2); - _common->Base.setValue(_box2obj); - _common->Tool.setValue(_box1obj); + + // Act to reverse the histories + _common->Base.setValue(_boxes[1]); + _common->Tool.setValue(_boxes[0]); _common->execute(); hist = _common->History.getValues(); - // std::cout << testing::PrintToString(hist[0]) << testing::PrintToString(hist[1]); - EXPECT_EQ(hist.size(), 2); - EXPECT_EQ(hist[1].shapeMap, compare1); + // Assert + ASSERT_EQ(hist.size(), 2); EXPECT_EQ(hist[0].shapeMap, compare2); + EXPECT_EQ(hist[1].shapeMap, compare1); } diff --git a/tests/src/Mod/Part/App/FeaturePartCut.cpp b/tests/src/Mod/Part/App/FeaturePartCut.cpp index 1da983a4b9..798785c0da 100644 --- a/tests/src/Mod/Part/App/FeaturePartCut.cpp +++ b/tests/src/Mod/Part/App/FeaturePartCut.cpp @@ -15,106 +15,152 @@ protected: tests::initApplication(); } - void SetUp() override { - createTestFile(); + createTestDoc(); _cut = static_cast(_doc->addObject("Part::Cut")); } void TearDown() override {} - Part::Cut* _cut; }; TEST_F(FeaturePartCutTest, testIntersecting) { // Arrange - _cut->Base.setValue(_box1obj); - _cut->Tool.setValue(_box2obj); + _cut->Base.setValue(_boxes[0]); + _cut->Tool.setValue(_boxes[1]); // Act _cut->execute(); Part::TopoShape ts = _cut->Shape.getValue(); double volume = PartTestHelpers::getVolume(ts.getShape()); + Base::BoundBox3d bb = ts.getBoundBox(); + + // Assert EXPECT_DOUBLE_EQ(volume, 3.0); + // double check using bounds: + EXPECT_DOUBLE_EQ(bb.MinX, 0.0); + EXPECT_DOUBLE_EQ(bb.MinY, 0.0); + EXPECT_DOUBLE_EQ(bb.MinZ, 0.0); + EXPECT_DOUBLE_EQ(bb.MaxX, 1.0); + EXPECT_DOUBLE_EQ(bb.MaxY, 1.0); + EXPECT_DOUBLE_EQ(bb.MaxZ, 3.0); } TEST_F(FeaturePartCutTest, testNonIntersecting) { // Arrange - _cut->Base.setValue(_box1obj); - _cut->Tool.setValue(_box3obj); + _cut->Base.setValue(_boxes[0]); + _cut->Tool.setValue(_boxes[2]); // Act _cut->execute(); Part::TopoShape ts = _cut->Shape.getValue(); double volume = PartTestHelpers::getVolume(ts.getShape()); + Base::BoundBox3d bb = ts.getBoundBox(); + + // Assert EXPECT_DOUBLE_EQ(volume, 6.0); + // double check using bounds: + EXPECT_DOUBLE_EQ(bb.MinX, 0.0); + EXPECT_DOUBLE_EQ(bb.MinY, 0.0); + EXPECT_DOUBLE_EQ(bb.MinZ, 0.0); + EXPECT_DOUBLE_EQ(bb.MaxX, 1.0); + EXPECT_DOUBLE_EQ(bb.MaxY, 2.0); + EXPECT_DOUBLE_EQ(bb.MaxZ, 3.0); } TEST_F(FeaturePartCutTest, testTouching) { // Arrange - _cut->Base.setValue(_box1obj); - _cut->Tool.setValue(_box4obj); + _cut->Base.setValue(_boxes[0]); + _cut->Tool.setValue(_boxes[3]); // Act _cut->execute(); Part::TopoShape ts = _cut->Shape.getValue(); double volume = PartTestHelpers::getVolume(ts.getShape()); + Base::BoundBox3d bb = ts.getBoundBox(); // Assert EXPECT_DOUBLE_EQ(volume, 6.0); + // double check using bounds: + EXPECT_DOUBLE_EQ(bb.MinX, 0.0); + EXPECT_DOUBLE_EQ(bb.MinY, 0.0); + EXPECT_DOUBLE_EQ(bb.MinZ, 0.0); + EXPECT_DOUBLE_EQ(bb.MaxX, 1.0); + EXPECT_DOUBLE_EQ(bb.MaxY, 2.0); + EXPECT_DOUBLE_EQ(bb.MaxZ, 3.0); } TEST_F(FeaturePartCutTest, testAlmostTouching) { // Arrange - _cut->Base.setValue(_box1obj); - _cut->Tool.setValue(_box5obj); + _cut->Base.setValue(_boxes[0]); + _cut->Tool.setValue(_boxes[4]); // Act _cut->execute(); Part::TopoShape ts = _cut->Shape.getValue(); double volume = PartTestHelpers::getVolume(ts.getShape()); + Base::BoundBox3d bb = ts.getBoundBox(); + + // Assert EXPECT_DOUBLE_EQ(volume, 6.0); + // double check using bounds: + EXPECT_DOUBLE_EQ(bb.MinX, 0.0); + EXPECT_DOUBLE_EQ(bb.MinY, 0.0); + EXPECT_DOUBLE_EQ(bb.MinZ, 0.0); + EXPECT_DOUBLE_EQ(bb.MaxX, 1.0); + EXPECT_DOUBLE_EQ(bb.MaxY, 2.0); + EXPECT_DOUBLE_EQ(bb.MaxZ, 3.0); } TEST_F(FeaturePartCutTest, testBarelyIntersecting) { // Arrange - _cut->Base.setValue(_box1obj); - _cut->Tool.setValue(_box6obj); + _cut->Base.setValue(_boxes[0]); + _cut->Tool.setValue(_boxes[5]); // Act _cut->execute(); Part::TopoShape ts = _cut->Shape.getValue(); double volume = PartTestHelpers::getVolume(ts.getShape()); - double target = 6 - Base::Precision::Confusion() * 3 * 1000; + double target = 6 - Base::Precision::Confusion() * 3 * 1000; // Reduce precision to 1e04 over 3 dimensions + Base::BoundBox3d bb = ts.getBoundBox(); + + // Assert + // Using FLOAT, not DOUBLE here so test library comparison is of reasonable precision 1e07 rather than 1e15 + // See https://google.github.io/googletest/reference/assertions.html#floating-point EXPECT_FLOAT_EQ(volume, target); + // double check using bounds: + EXPECT_DOUBLE_EQ(bb.MinX, 0.0); + EXPECT_DOUBLE_EQ(bb.MinY, 0.0); + EXPECT_DOUBLE_EQ(bb.MinZ, 0.0); + EXPECT_DOUBLE_EQ(bb.MaxX, 1.0); + EXPECT_DOUBLE_EQ(bb.MaxY, 1.9999); + EXPECT_DOUBLE_EQ(bb.MaxZ, 3.0); } TEST_F(FeaturePartCutTest, testMustExecute) { - // Act - short mE = _cut->mustExecute(); - // Assert - EXPECT_FALSE(mE); - _cut->Base.setValue(_box1obj); - // Assert - mE = _cut->mustExecute(); - EXPECT_FALSE(mE); - // Act - _cut->Tool.setValue(_box2obj); - // Assert - mE = _cut->mustExecute(); - EXPECT_TRUE(mE); + // Assert initially we don't need to execute + EXPECT_FALSE(_cut->mustExecute()); + // Act to change one property + _cut->Base.setValue(_boxes[0]); + // Assert we still can't execute + EXPECT_FALSE(_cut->mustExecute()); + // Act to complete the properties we need + _cut->Tool.setValue(_boxes[1]); + // Assert that we now must execute + EXPECT_TRUE(_cut->mustExecute()); + // Act to execute _doc->recompute(); - mE = _cut->mustExecute(); - EXPECT_FALSE(mE); + // Assert we don't need to execute anymore + EXPECT_FALSE(_cut->mustExecute()); } TEST_F(FeaturePartCutTest, testGetProviderName) @@ -125,3 +171,5 @@ TEST_F(FeaturePartCutTest, testGetProviderName) // Assert EXPECT_STREQ(name, "PartGui::ViewProviderBoolean"); } + +// See FeaturePartCommon.cpp for a history test. It would be exactly the same and redundant here. \ No newline at end of file diff --git a/tests/src/Mod/Part/App/FeaturePartFuse.cpp b/tests/src/Mod/Part/App/FeaturePartFuse.cpp index c0694ac23a..304e02f9a4 100644 --- a/tests/src/Mod/Part/App/FeaturePartFuse.cpp +++ b/tests/src/Mod/Part/App/FeaturePartFuse.cpp @@ -16,10 +16,9 @@ protected: tests::initApplication(); } - void SetUp() override { - createTestFile(); + createTestDoc(); _fuse = static_cast(_doc->addObject("Part::Fuse")); } @@ -32,87 +31,137 @@ protected: TEST_F(FeaturePartFuseTest, testIntersecting) { // Arrange - _fuse->Base.setValue(_box1obj); - _fuse->Tool.setValue(_box2obj); + _fuse->Base.setValue(_boxes[0]); + _fuse->Tool.setValue(_boxes[1]); // Act _fuse->execute(); Part::TopoShape ts = _fuse->Shape.getValue(); double volume = PartTestHelpers::getVolume(ts.getShape()); + Base::BoundBox3d bb = ts.getBoundBox(); + + // Assert EXPECT_DOUBLE_EQ(volume, 9.0); + // double check using bounds: + EXPECT_DOUBLE_EQ(bb.MinX, 0.0); + EXPECT_DOUBLE_EQ(bb.MinY, 0.0); + EXPECT_DOUBLE_EQ(bb.MinZ, 0.0); + EXPECT_DOUBLE_EQ(bb.MaxX, 1.0); + EXPECT_DOUBLE_EQ(bb.MaxY, 3.0); + EXPECT_DOUBLE_EQ(bb.MaxZ, 3.0); } TEST_F(FeaturePartFuseTest, testNonIntersecting) { // Arrange - _fuse->Base.setValue(_box1obj); - _fuse->Tool.setValue(_box3obj); + _fuse->Base.setValue(_boxes[0]); + _fuse->Tool.setValue(_boxes[2]); // Act _fuse->execute(); Part::TopoShape ts = _fuse->Shape.getValue(); double volume = PartTestHelpers::getVolume(ts.getShape()); + Base::BoundBox3d bb = ts.getBoundBox(); + + // Assert EXPECT_DOUBLE_EQ(volume, 12.0); + // double check using bounds: + EXPECT_DOUBLE_EQ(bb.MinX, 0.0); + EXPECT_DOUBLE_EQ(bb.MinY, 0.0); + EXPECT_DOUBLE_EQ(bb.MinZ, 0.0); + EXPECT_DOUBLE_EQ(bb.MaxX, 1.0); + EXPECT_DOUBLE_EQ(bb.MaxY, 5.0); + EXPECT_DOUBLE_EQ(bb.MaxZ, 3.0); } TEST_F(FeaturePartFuseTest, testTouching) { // Arrange - _fuse->Base.setValue(_box1obj); - _fuse->Tool.setValue(_box4obj); + _fuse->Base.setValue(_boxes[0]); + _fuse->Tool.setValue(_boxes[3]); // Act _fuse->execute(); Part::TopoShape ts = _fuse->Shape.getValue(); double volume = PartTestHelpers::getVolume(ts.getShape()); + Base::BoundBox3d bb = ts.getBoundBox(); + + // Assert EXPECT_DOUBLE_EQ(volume, 12.0); + // double check using bounds: + EXPECT_DOUBLE_EQ(bb.MinX, 0.0); + EXPECT_DOUBLE_EQ(bb.MinY, 0.0); + EXPECT_DOUBLE_EQ(bb.MinZ, 0.0); + EXPECT_DOUBLE_EQ(bb.MaxX, 1.0); + EXPECT_DOUBLE_EQ(bb.MaxY, 4.0); + EXPECT_DOUBLE_EQ(bb.MaxZ, 3.0); } TEST_F(FeaturePartFuseTest, testAlmostTouching) { // Arrange - _fuse->Base.setValue(_box1obj); - _fuse->Tool.setValue(_box5obj); + _fuse->Base.setValue(_boxes[0]); + _fuse->Tool.setValue(_boxes[4]); // Act _fuse->execute(); Part::TopoShape ts = _fuse->Shape.getValue(); double volume = PartTestHelpers::getVolume(ts.getShape()); - EXPECT_FLOAT_EQ(volume, 12.0); + Base::BoundBox3d bb = ts.getBoundBox(); + + // Assert + EXPECT_FLOAT_EQ(volume, 12.0); // Use FLOAT to limit precision to 1E07 rather than 1E15 + // double check using bounds: + EXPECT_DOUBLE_EQ(bb.MinX, 0.0); + EXPECT_DOUBLE_EQ(bb.MinY, 0.0); + EXPECT_DOUBLE_EQ(bb.MinZ, 0.0); + EXPECT_DOUBLE_EQ(bb.MaxX, 1.0); + EXPECT_FLOAT_EQ(bb.MaxY, 4.0); // Use FLOAT to limit precision to 1E07 rather than 1E15 + EXPECT_DOUBLE_EQ(bb.MaxZ, 3.0); } TEST_F(FeaturePartFuseTest, testBarelyIntersecting) { // Arrange - _fuse->Base.setValue(_box1obj); - _fuse->Tool.setValue(_box6obj); + _fuse->Base.setValue(_boxes[0]); + _fuse->Tool.setValue(_boxes[5]); // Act _fuse->execute(); Part::TopoShape ts = _fuse->Shape.getValue(); double volume = PartTestHelpers::getVolume(ts.getShape()); - double target = 12 - Base::Precision::Confusion() * 3 * 1000; + double target = 12 - Base::Precision::Confusion() * 3 * 1000; // Reduce precision to 1e04 over 3 dimensions + Base::BoundBox3d bb = ts.getBoundBox(); + + // Assert + // Using FLOAT, not DOUBLE here so test library comparison is of reasonable precision 1e07 rather than 1e15 + // See https://google.github.io/googletest/reference/assertions.html#floating-point EXPECT_FLOAT_EQ(volume, target); + // double check using bounds: + EXPECT_DOUBLE_EQ(bb.MinX, 0.0); + EXPECT_DOUBLE_EQ(bb.MinY, 0.0); + EXPECT_DOUBLE_EQ(bb.MinZ, 0.0); + EXPECT_DOUBLE_EQ(bb.MaxX, 1.0); + EXPECT_DOUBLE_EQ(bb.MaxY, 3.9999); + EXPECT_DOUBLE_EQ(bb.MaxZ, 3.0); } TEST_F(FeaturePartFuseTest, testMustExecute) { - // Act - short mE = _fuse->mustExecute(); - // Assert - EXPECT_FALSE(mE); - _fuse->Base.setValue(_box1obj); - // Assert - mE = _fuse->mustExecute(); - EXPECT_FALSE(mE); - // Act - _fuse->Tool.setValue(_box2obj); - // Assert - mE = _fuse->mustExecute(); - EXPECT_TRUE(mE); + // Assert initially we don't need to execute + EXPECT_FALSE(_fuse->mustExecute()); + // Act to change one property + _fuse->Base.setValue(_boxes[0]); + // Assert we still can't execute + EXPECT_FALSE(_fuse->mustExecute()); + // Act to complete the properties we need + _fuse->Tool.setValue(_boxes[1]); + // Assert that we now must execute + EXPECT_TRUE(_fuse->mustExecute()); + // Act to execute _doc->recompute(); - mE = _fuse->mustExecute(); - EXPECT_FALSE(mE); + // Assert we don't need to execute anymore + EXPECT_FALSE(_fuse->mustExecute()); } TEST_F(FeaturePartFuseTest, testGetProviderName) @@ -127,19 +176,22 @@ TEST_F(FeaturePartFuseTest, testGetProviderName) TEST_F(FeaturePartFuseTest, testRefine) { // Arrange - _fuse->Base.setValue(_box1obj); - _fuse->Tool.setValue(_box2obj); + _fuse->Base.setValue(_boxes[0]); + _fuse->Tool.setValue(_boxes[1]); // Act _fuse->execute(); Part::TopoShape ts = _fuse->Shape.getValue(); - // what's the wire or face count here? - std::vector subs = ts.getSubTopoShapes(TopAbs_FACE); // WIRE + std::vector subs = ts.getSubTopoShapes(TopAbs_FACE); // TopAbs_WIRE alternate approach + // Assert two boxes, plus redundant faces at the joint. EXPECT_EQ(subs.size(), 14); - // Assert + // Act _fuse->Refine.setValue(true); _fuse->execute(); ts = _fuse->Shape.getValue(); - subs = ts.getSubTopoShapes(TopAbs_FACE); // WIRE + subs = ts.getSubTopoShapes(TopAbs_FACE); + // Assert we now just have one big box EXPECT_EQ(subs.size(), 6); } + +// See FeaturePartCommon.cpp for a history test. It would be exactly the same and redundant here. \ No newline at end of file diff --git a/tests/src/Mod/Part/App/PartTestHelpers.cpp b/tests/src/Mod/Part/App/PartTestHelpers.cpp index 11e6b17999..26d4532649 100644 --- a/tests/src/Mod/Part/App/PartTestHelpers.cpp +++ b/tests/src/Mod/Part/App/PartTestHelpers.cpp @@ -11,37 +11,50 @@ double getVolume(TopoDS_Shape shape) return prop.Mass(); } -void PartTestHelperClass::createTestFile() +void PartTestHelperClass::createTestDoc() { - _docName = App::GetApplication().getUniqueDocumentName("test"); - _doc = App::GetApplication().newDocument(_docName.c_str(), "testUser"); - _box1obj = static_cast(_doc->addObject("Part::Box")); - _box2obj = static_cast(_doc->addObject("Part::Box")); - _box3obj = static_cast(_doc->addObject("Part::Box")); - _box4obj = static_cast(_doc->addObject("Part::Box")); - _box5obj = static_cast(_doc->addObject("Part::Box")); - _box6obj = static_cast(_doc->addObject("Part::Box")); - for (auto _box : {_box1obj, _box2obj, _box3obj, _box4obj, _box5obj, _box6obj}) { - _box->Length.setValue(1); - _box->Width.setValue(2); - _box->Height.setValue(3); - } - _box1obj->Placement.setValue( - Base::Placement(Base::Vector3d(), Base::Rotation(), Base::Vector3d())); - _box2obj->Placement.setValue( - Base::Placement(Base::Vector3d(0, 1, 0), Base::Rotation(), Base::Vector3d())); - _box3obj->Placement.setValue( - Base::Placement(Base::Vector3d(0, 3, 0), Base::Rotation(), Base::Vector3d())); - _box4obj->Placement.setValue( - Base::Placement(Base::Vector3d(0, 2, 0), Base::Rotation(), Base::Vector3d())); - _box5obj->Placement.setValue( - Base::Placement(Base::Vector3d(0, 2 + Base::Precision::Confusion(), 0), - Base::Rotation(), - Base::Vector3d())); - _box6obj->Placement.setValue( - Base::Placement(Base::Vector3d(0, 2 - Base::Precision::Confusion() * 1000, 0), - Base::Rotation(), - Base::Vector3d())); + _docName = App::GetApplication().getUniqueDocumentName("test"); + _doc = App::GetApplication().newDocument(_docName.c_str(), "testUser"); + std::array box_origins = { + Base::Vector3d(), // First box at 0,0,0 + Base::Vector3d(0, 1, 0), // Overlap with first box + Base::Vector3d(0, 3, 0), // Don't Overlap with first box + Base::Vector3d(0, 2, 0), // Touch the first box + Base::Vector3d(0, 2 + Base::Precision::Confusion(), 0), // Just Outside of touching + // For just inside of touching, go enough that precision rounding doesn't make us overlap. + Base::Vector3d(0, 2 - Base::Precision::Confusion() * 1000, 0) + }; + + // for (auto& [box, origin] : zip(_boxes, box_origins) ) { + // for ( int i : range(0,_boxes.size())) { + for ( unsigned i=0; i < _boxes.size(); i++ ) { + auto box = _boxes[i] = static_cast(_doc->addObject("Part::Box")); + box->Length.setValue(1); + box->Width.setValue(2); + box->Height.setValue(3); + box->Placement.setValue(Base::Placement(box_origins[i], Base::Rotation(), Base::Vector3d() ) ); + } } -} // namespace PartTestHelpers +} + +// https://google.github.io/googletest/advanced.html#teaching-googletest-how-to-print-your-values +namespace Part +{ +void PrintTo(ShapeHistory sh, std::ostream* os) +{ + const char* types[] = + {"Compound", "CompSolid", "Solid", "Shell", "Face", "Wire", "Edge", "Vertex", "Shape"}; + *os << "History for " << types[sh.type] << " is "; + for (const auto& it : sh.shapeMap) { + int old_shape_index = it.first; + *os << " " << old_shape_index << ": "; + if (!it.second.empty()) { + for (auto it2 : it.second) { + *os << it2 << " "; + } + } + } + *os << std::endl; +} +} // namespace Part diff --git a/tests/src/Mod/Part/App/PartTestHelpers.h b/tests/src/Mod/Part/App/PartTestHelpers.h index 1b6ffa1d8e..15ed44da69 100644 --- a/tests/src/Mod/Part/App/PartTestHelpers.h +++ b/tests/src/Mod/Part/App/PartTestHelpers.h @@ -16,9 +16,8 @@ class PartTestHelperClass public: App::Document* _doc; std::string _docName; - Part::Box *_box1obj, *_box2obj, *_box3obj, *_box4obj, *_box5obj, *_box6obj; - - void createTestFile(); + std::array _boxes; + void createTestDoc(); }; } // namespace PartTestHelpers From abf7fb079179ece2d8edd5701c3d199e0c0583dd Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 23 Dec 2023 10:55:15 +0000 Subject: [PATCH 07/16] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/src/Mod/Part/App/FeaturePartCommon.cpp | 14 ++++--- tests/src/Mod/Part/App/FeaturePartCut.cpp | 10 +++-- tests/src/Mod/Part/App/FeaturePartFuse.cpp | 13 +++--- tests/src/Mod/Part/App/PartTestHelpers.cpp | 42 ++++++++++---------- tests/src/Mod/Part/App/PartTestHelpers.h | 2 +- 5 files changed, 44 insertions(+), 37 deletions(-) diff --git a/tests/src/Mod/Part/App/FeaturePartCommon.cpp b/tests/src/Mod/Part/App/FeaturePartCommon.cpp index d379df6b5c..673a697a3d 100644 --- a/tests/src/Mod/Part/App/FeaturePartCommon.cpp +++ b/tests/src/Mod/Part/App/FeaturePartCommon.cpp @@ -112,13 +112,15 @@ TEST_F(FeaturePartCommonTest, testBarelyIntersecting) _common->execute(); Part::TopoShape ts = _common->Shape.getValue(); double volume = PartTestHelpers::getVolume(ts.getShape()); - double target = Base::Precision::Confusion() * 3 * 1000; // Reduce precision to 1e04 over 3 dimensions + double target = + Base::Precision::Confusion() * 3 * 1000; // Reduce precision to 1e04 over 3 dimensions Base::BoundBox3d bb = ts.getBoundBox(); // Assert - // Using FLOAT, not DOUBLE here so test library comparison is of reasonable precision 1e07 rather than 1e15 - // See https://google.github.io/googletest/reference/assertions.html#floating-point - EXPECT_FLOAT_EQ(volume, target); // Should be approximately 0.00029999999999996696 + // Using FLOAT, not DOUBLE here so test library comparison is of reasonable precision 1e07 + // rather than 1e15 See + // https://google.github.io/googletest/reference/assertions.html#floating-point + EXPECT_FLOAT_EQ(volume, target); // Should be approximately 0.00029999999999996696 // double check using bounds: EXPECT_DOUBLE_EQ(bb.MinX, 0.0); EXPECT_DOUBLE_EQ(bb.MinY, 1.9999); @@ -164,9 +166,9 @@ TEST_F(FeaturePartCommonTest, testHistory) using MapList = std::map>; using List = std::vector; MapList compare1 = - {{0, List {0}}, {1, List {5}}, {2, List () }, {3, List {2}}, {4, List {3}}, {5, List {1}}}; + {{0, List {0}}, {1, List {5}}, {2, List()}, {3, List {2}}, {4, List {3}}, {5, List {1}}}; MapList compare2 = - {{0, List {0}}, {1, List {5}}, {2, List {4}}, {3, List () }, {4, List {3}}, {5, List {1}}}; + {{0, List {0}}, {1, List {5}}, {2, List {4}}, {3, List()}, {4, List {3}}, {5, List {1}}}; // Act and Assert no histories yet std::vector hist = _common->History.getValues(); diff --git a/tests/src/Mod/Part/App/FeaturePartCut.cpp b/tests/src/Mod/Part/App/FeaturePartCut.cpp index 798785c0da..f512c69f53 100644 --- a/tests/src/Mod/Part/App/FeaturePartCut.cpp +++ b/tests/src/Mod/Part/App/FeaturePartCut.cpp @@ -129,12 +129,14 @@ TEST_F(FeaturePartCutTest, testBarelyIntersecting) _cut->execute(); Part::TopoShape ts = _cut->Shape.getValue(); double volume = PartTestHelpers::getVolume(ts.getShape()); - double target = 6 - Base::Precision::Confusion() * 3 * 1000; // Reduce precision to 1e04 over 3 dimensions + double target = + 6 - Base::Precision::Confusion() * 3 * 1000; // Reduce precision to 1e04 over 3 dimensions Base::BoundBox3d bb = ts.getBoundBox(); // Assert - // Using FLOAT, not DOUBLE here so test library comparison is of reasonable precision 1e07 rather than 1e15 - // See https://google.github.io/googletest/reference/assertions.html#floating-point + // Using FLOAT, not DOUBLE here so test library comparison is of reasonable precision 1e07 + // rather than 1e15 See + // https://google.github.io/googletest/reference/assertions.html#floating-point EXPECT_FLOAT_EQ(volume, target); // double check using bounds: EXPECT_DOUBLE_EQ(bb.MinX, 0.0); @@ -172,4 +174,4 @@ TEST_F(FeaturePartCutTest, testGetProviderName) EXPECT_STREQ(name, "PartGui::ViewProviderBoolean"); } -// See FeaturePartCommon.cpp for a history test. It would be exactly the same and redundant here. \ No newline at end of file +// See FeaturePartCommon.cpp for a history test. It would be exactly the same and redundant here. diff --git a/tests/src/Mod/Part/App/FeaturePartFuse.cpp b/tests/src/Mod/Part/App/FeaturePartFuse.cpp index 304e02f9a4..a9db9b4b8b 100644 --- a/tests/src/Mod/Part/App/FeaturePartFuse.cpp +++ b/tests/src/Mod/Part/App/FeaturePartFuse.cpp @@ -130,12 +130,14 @@ TEST_F(FeaturePartFuseTest, testBarelyIntersecting) _fuse->execute(); Part::TopoShape ts = _fuse->Shape.getValue(); double volume = PartTestHelpers::getVolume(ts.getShape()); - double target = 12 - Base::Precision::Confusion() * 3 * 1000; // Reduce precision to 1e04 over 3 dimensions + double target = + 12 - Base::Precision::Confusion() * 3 * 1000; // Reduce precision to 1e04 over 3 dimensions Base::BoundBox3d bb = ts.getBoundBox(); // Assert - // Using FLOAT, not DOUBLE here so test library comparison is of reasonable precision 1e07 rather than 1e15 - // See https://google.github.io/googletest/reference/assertions.html#floating-point + // Using FLOAT, not DOUBLE here so test library comparison is of reasonable precision 1e07 + // rather than 1e15 See + // https://google.github.io/googletest/reference/assertions.html#floating-point EXPECT_FLOAT_EQ(volume, target); // double check using bounds: EXPECT_DOUBLE_EQ(bb.MinX, 0.0); @@ -182,7 +184,8 @@ TEST_F(FeaturePartFuseTest, testRefine) // Act _fuse->execute(); Part::TopoShape ts = _fuse->Shape.getValue(); - std::vector subs = ts.getSubTopoShapes(TopAbs_FACE); // TopAbs_WIRE alternate approach + std::vector subs = + ts.getSubTopoShapes(TopAbs_FACE); // TopAbs_WIRE alternate approach // Assert two boxes, plus redundant faces at the joint. EXPECT_EQ(subs.size(), 14); // Act @@ -194,4 +197,4 @@ TEST_F(FeaturePartFuseTest, testRefine) EXPECT_EQ(subs.size(), 6); } -// See FeaturePartCommon.cpp for a history test. It would be exactly the same and redundant here. \ No newline at end of file +// See FeaturePartCommon.cpp for a history test. It would be exactly the same and redundant here. diff --git a/tests/src/Mod/Part/App/PartTestHelpers.cpp b/tests/src/Mod/Part/App/PartTestHelpers.cpp index 26d4532649..ab8d8f60ec 100644 --- a/tests/src/Mod/Part/App/PartTestHelpers.cpp +++ b/tests/src/Mod/Part/App/PartTestHelpers.cpp @@ -13,30 +13,30 @@ double getVolume(TopoDS_Shape shape) void PartTestHelperClass::createTestDoc() { - _docName = App::GetApplication().getUniqueDocumentName("test"); - _doc = App::GetApplication().newDocument(_docName.c_str(), "testUser"); - std::array box_origins = { - Base::Vector3d(), // First box at 0,0,0 - Base::Vector3d(0, 1, 0), // Overlap with first box - Base::Vector3d(0, 3, 0), // Don't Overlap with first box - Base::Vector3d(0, 2, 0), // Touch the first box - Base::Vector3d(0, 2 + Base::Precision::Confusion(), 0), // Just Outside of touching - // For just inside of touching, go enough that precision rounding doesn't make us overlap. - Base::Vector3d(0, 2 - Base::Precision::Confusion() * 1000, 0) - }; + _docName = App::GetApplication().getUniqueDocumentName("test"); + _doc = App::GetApplication().newDocument(_docName.c_str(), "testUser"); + std::array box_origins = { + Base::Vector3d(), // First box at 0,0,0 + Base::Vector3d(0, 1, 0), // Overlap with first box + Base::Vector3d(0, 3, 0), // Don't Overlap with first box + Base::Vector3d(0, 2, 0), // Touch the first box + Base::Vector3d(0, 2 + Base::Precision::Confusion(), 0), // Just Outside of touching + // For just inside of touching, go enough that precision rounding doesn't make us overlap. + Base::Vector3d(0, 2 - Base::Precision::Confusion() * 1000, 0)}; - // for (auto& [box, origin] : zip(_boxes, box_origins) ) { - // for ( int i : range(0,_boxes.size())) { - for ( unsigned i=0; i < _boxes.size(); i++ ) { - auto box = _boxes[i] = static_cast(_doc->addObject("Part::Box")); - box->Length.setValue(1); - box->Width.setValue(2); - box->Height.setValue(3); - box->Placement.setValue(Base::Placement(box_origins[i], Base::Rotation(), Base::Vector3d() ) ); - } + // for (auto& [box, origin] : zip(_boxes, box_origins) ) { + // for ( int i : range(0,_boxes.size())) { + for (unsigned i = 0; i < _boxes.size(); i++) { + auto box = _boxes[i] = static_cast(_doc->addObject("Part::Box")); + box->Length.setValue(1); + box->Width.setValue(2); + box->Height.setValue(3); + box->Placement.setValue( + Base::Placement(box_origins[i], Base::Rotation(), Base::Vector3d())); + } } -} +} // namespace PartTestHelpers // https://google.github.io/googletest/advanced.html#teaching-googletest-how-to-print-your-values namespace Part diff --git a/tests/src/Mod/Part/App/PartTestHelpers.h b/tests/src/Mod/Part/App/PartTestHelpers.h index 15ed44da69..0adbea84de 100644 --- a/tests/src/Mod/Part/App/PartTestHelpers.h +++ b/tests/src/Mod/Part/App/PartTestHelpers.h @@ -16,7 +16,7 @@ class PartTestHelperClass public: App::Document* _doc; std::string _docName; - std::array _boxes; + std::array _boxes; void createTestDoc(); }; From b8ac7f833e1fb4d4e1b6155ad225e147f2a1ce84 Mon Sep 17 00:00:00 2001 From: bgbsww Date: Sat, 23 Dec 2023 06:54:43 -0500 Subject: [PATCH 08/16] Be clearer about minimal distance magic numbers --- tests/src/Mod/Part/App/FeaturePartCommon.cpp | 5 ++--- tests/src/Mod/Part/App/FeaturePartCut.cpp | 5 ++--- tests/src/Mod/Part/App/FeaturePartFuse.cpp | 5 ++--- tests/src/Mod/Part/App/PartTestHelpers.cpp | 2 +- tests/src/Mod/Part/App/PartTestHelpers.h | 2 ++ 5 files changed, 9 insertions(+), 10 deletions(-) diff --git a/tests/src/Mod/Part/App/FeaturePartCommon.cpp b/tests/src/Mod/Part/App/FeaturePartCommon.cpp index 673a697a3d..d8098d03ed 100644 --- a/tests/src/Mod/Part/App/FeaturePartCommon.cpp +++ b/tests/src/Mod/Part/App/FeaturePartCommon.cpp @@ -112,8 +112,7 @@ TEST_F(FeaturePartCommonTest, testBarelyIntersecting) _common->execute(); Part::TopoShape ts = _common->Shape.getValue(); double volume = PartTestHelpers::getVolume(ts.getShape()); - double target = - Base::Precision::Confusion() * 3 * 1000; // Reduce precision to 1e04 over 3 dimensions + double target = PartTestHelpers::minimalDistance * 3; // 3 dimensions in a Volume Base::BoundBox3d bb = ts.getBoundBox(); // Assert @@ -123,7 +122,7 @@ TEST_F(FeaturePartCommonTest, testBarelyIntersecting) EXPECT_FLOAT_EQ(volume, target); // Should be approximately 0.00029999999999996696 // double check using bounds: EXPECT_DOUBLE_EQ(bb.MinX, 0.0); - EXPECT_DOUBLE_EQ(bb.MinY, 1.9999); + EXPECT_DOUBLE_EQ(bb.MinY, 2.0 - PartTestHelpers::minimalDistance); EXPECT_DOUBLE_EQ(bb.MinZ, 0.0); EXPECT_DOUBLE_EQ(bb.MaxX, 1.0); EXPECT_DOUBLE_EQ(bb.MaxY, 2.0); diff --git a/tests/src/Mod/Part/App/FeaturePartCut.cpp b/tests/src/Mod/Part/App/FeaturePartCut.cpp index f512c69f53..48d273bbfe 100644 --- a/tests/src/Mod/Part/App/FeaturePartCut.cpp +++ b/tests/src/Mod/Part/App/FeaturePartCut.cpp @@ -129,8 +129,7 @@ TEST_F(FeaturePartCutTest, testBarelyIntersecting) _cut->execute(); Part::TopoShape ts = _cut->Shape.getValue(); double volume = PartTestHelpers::getVolume(ts.getShape()); - double target = - 6 - Base::Precision::Confusion() * 3 * 1000; // Reduce precision to 1e04 over 3 dimensions + double target = 6 - PartTestHelpers::minimalDistance * 3; // 3 dimensions in a Volume Base::BoundBox3d bb = ts.getBoundBox(); // Assert @@ -143,7 +142,7 @@ TEST_F(FeaturePartCutTest, testBarelyIntersecting) EXPECT_DOUBLE_EQ(bb.MinY, 0.0); EXPECT_DOUBLE_EQ(bb.MinZ, 0.0); EXPECT_DOUBLE_EQ(bb.MaxX, 1.0); - EXPECT_DOUBLE_EQ(bb.MaxY, 1.9999); + EXPECT_DOUBLE_EQ(bb.MaxY, 2.0 - PartTestHelpers::minimalDistance); EXPECT_DOUBLE_EQ(bb.MaxZ, 3.0); } diff --git a/tests/src/Mod/Part/App/FeaturePartFuse.cpp b/tests/src/Mod/Part/App/FeaturePartFuse.cpp index a9db9b4b8b..432dc9f58a 100644 --- a/tests/src/Mod/Part/App/FeaturePartFuse.cpp +++ b/tests/src/Mod/Part/App/FeaturePartFuse.cpp @@ -130,8 +130,7 @@ TEST_F(FeaturePartFuseTest, testBarelyIntersecting) _fuse->execute(); Part::TopoShape ts = _fuse->Shape.getValue(); double volume = PartTestHelpers::getVolume(ts.getShape()); - double target = - 12 - Base::Precision::Confusion() * 3 * 1000; // Reduce precision to 1e04 over 3 dimensions + double target = 12 - PartTestHelpers::minimalDistance * 3; // 3 dimensions in a Volume Base::BoundBox3d bb = ts.getBoundBox(); // Assert @@ -144,7 +143,7 @@ TEST_F(FeaturePartFuseTest, testBarelyIntersecting) EXPECT_DOUBLE_EQ(bb.MinY, 0.0); EXPECT_DOUBLE_EQ(bb.MinZ, 0.0); EXPECT_DOUBLE_EQ(bb.MaxX, 1.0); - EXPECT_DOUBLE_EQ(bb.MaxY, 3.9999); + EXPECT_DOUBLE_EQ(bb.MaxY, 4.0 - PartTestHelpers::minimalDistance); EXPECT_DOUBLE_EQ(bb.MaxZ, 3.0); } diff --git a/tests/src/Mod/Part/App/PartTestHelpers.cpp b/tests/src/Mod/Part/App/PartTestHelpers.cpp index ab8d8f60ec..cbaa02e3d4 100644 --- a/tests/src/Mod/Part/App/PartTestHelpers.cpp +++ b/tests/src/Mod/Part/App/PartTestHelpers.cpp @@ -22,7 +22,7 @@ void PartTestHelperClass::createTestDoc() Base::Vector3d(0, 2, 0), // Touch the first box Base::Vector3d(0, 2 + Base::Precision::Confusion(), 0), // Just Outside of touching // For just inside of touching, go enough that precision rounding doesn't make us overlap. - Base::Vector3d(0, 2 - Base::Precision::Confusion() * 1000, 0)}; + Base::Vector3d(0, 2 - minimalDistance, 0)}; // for (auto& [box, origin] : zip(_boxes, box_origins) ) { // for ( int i : range(0,_boxes.size())) { diff --git a/tests/src/Mod/Part/App/PartTestHelpers.h b/tests/src/Mod/Part/App/PartTestHelpers.h index 0adbea84de..cc2be6e1c6 100644 --- a/tests/src/Mod/Part/App/PartTestHelpers.h +++ b/tests/src/Mod/Part/App/PartTestHelpers.h @@ -20,4 +20,6 @@ public: void createTestDoc(); }; +const double minimalDistance = Base::Precision::Confusion() * 1000; + } // namespace PartTestHelpers From 551ba26828b4906115d914ff9cf09aadb2fd3be7 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 23 Dec 2023 11:55:27 +0000 Subject: [PATCH 09/16] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/src/Mod/Part/App/FeaturePartCommon.cpp | 2 +- tests/src/Mod/Part/App/FeaturePartCut.cpp | 2 +- tests/src/Mod/Part/App/FeaturePartFuse.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/src/Mod/Part/App/FeaturePartCommon.cpp b/tests/src/Mod/Part/App/FeaturePartCommon.cpp index d8098d03ed..ef460523ff 100644 --- a/tests/src/Mod/Part/App/FeaturePartCommon.cpp +++ b/tests/src/Mod/Part/App/FeaturePartCommon.cpp @@ -112,7 +112,7 @@ TEST_F(FeaturePartCommonTest, testBarelyIntersecting) _common->execute(); Part::TopoShape ts = _common->Shape.getValue(); double volume = PartTestHelpers::getVolume(ts.getShape()); - double target = PartTestHelpers::minimalDistance * 3; // 3 dimensions in a Volume + double target = PartTestHelpers::minimalDistance * 3; // 3 dimensions in a Volume Base::BoundBox3d bb = ts.getBoundBox(); // Assert diff --git a/tests/src/Mod/Part/App/FeaturePartCut.cpp b/tests/src/Mod/Part/App/FeaturePartCut.cpp index 48d273bbfe..3b12aede87 100644 --- a/tests/src/Mod/Part/App/FeaturePartCut.cpp +++ b/tests/src/Mod/Part/App/FeaturePartCut.cpp @@ -129,7 +129,7 @@ TEST_F(FeaturePartCutTest, testBarelyIntersecting) _cut->execute(); Part::TopoShape ts = _cut->Shape.getValue(); double volume = PartTestHelpers::getVolume(ts.getShape()); - double target = 6 - PartTestHelpers::minimalDistance * 3; // 3 dimensions in a Volume + double target = 6 - PartTestHelpers::minimalDistance * 3; // 3 dimensions in a Volume Base::BoundBox3d bb = ts.getBoundBox(); // Assert diff --git a/tests/src/Mod/Part/App/FeaturePartFuse.cpp b/tests/src/Mod/Part/App/FeaturePartFuse.cpp index 432dc9f58a..b8df7c61c9 100644 --- a/tests/src/Mod/Part/App/FeaturePartFuse.cpp +++ b/tests/src/Mod/Part/App/FeaturePartFuse.cpp @@ -130,7 +130,7 @@ TEST_F(FeaturePartFuseTest, testBarelyIntersecting) _fuse->execute(); Part::TopoShape ts = _fuse->Shape.getValue(); double volume = PartTestHelpers::getVolume(ts.getShape()); - double target = 12 - PartTestHelpers::minimalDistance * 3; // 3 dimensions in a Volume + double target = 12 - PartTestHelpers::minimalDistance * 3; // 3 dimensions in a Volume Base::BoundBox3d bb = ts.getBoundBox(); // Assert From c6794a8714b600ad65b36649fbd65648b6528d47 Mon Sep 17 00:00:00 2001 From: bgbsww Date: Sat, 23 Dec 2023 07:28:51 -0500 Subject: [PATCH 10/16] Attempt to mollify lint --- tests/src/Mod/Part/App/FeatureFillet.cpp | 162 +++++++++++++++++++ tests/src/Mod/Part/App/FeaturePartCommon.cpp | 10 +- tests/src/Mod/Part/App/FeaturePartCut.cpp | 6 +- tests/src/Mod/Part/App/FeaturePartFuse.cpp | 6 +- 4 files changed, 173 insertions(+), 11 deletions(-) create mode 100644 tests/src/Mod/Part/App/FeatureFillet.cpp diff --git a/tests/src/Mod/Part/App/FeatureFillet.cpp b/tests/src/Mod/Part/App/FeatureFillet.cpp new file mode 100644 index 0000000000..61289d4e7b --- /dev/null +++ b/tests/src/Mod/Part/App/FeatureFillet.cpp @@ -0,0 +1,162 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later + +#include "gtest/gtest.h" + +#include + +#include "PartTestHelpers.h" + +std::vector _getFilletEdges(std::vector edges = {1,2}, double startRadius = 0.3, double endRadius = 0.3) { + std::vector filletElements; + for ( auto e : edges ) { + Part::FilletElement fe = {e, startRadius, endRadius}; + filletElements.push_back(fe); + } + return filletElements; +} + + +class FeatureFilletTest: public ::testing::Test, public PartTestHelpers::PartTestHelperClass +{ +protected: + static void SetUpTestSuite() + { + tests::initApplication(); + } + + void SetUp() override + { + createTestFile(); + _box1obj->Length.setValue(4); + _box1obj->Width.setValue(5); + _box1obj->Height.setValue(6); + _box1obj->Placement.setValue( + Base::Placement(Base::Vector3d(), Base::Rotation(), Base::Vector3d())); + _box2obj->Placement.setValue( + Base::Placement(Base::Vector3d(0, 1, 6), Base::Rotation(), Base::Vector3d())); + _box2obj->Length.setValue(1); + _box2obj->Width.setValue(2); + _box2obj->Height.setValue(3); + _fused = static_cast(_doc->addObject("Part::Fuse")); + _fused->Base.setValue(_box1obj); + _fused->Tool.setValue(_box2obj); + _fused->execute(); + _fillet = static_cast(_doc->addObject("Part::Fillet")); + } + + void TearDown() override + {} + + Part::Fuse *_fused; + Part::Fillet* _fillet; +}; + +TEST_F(FeatureFilletTest, testInner) +{ + // Arrange + _fillet->Base.setValue(_fused); + Part::TopoShape rf = _fused->Shape.getValue(); + std::vector get = rf.getElementTypes(); + ASSERT_EQ(get.size(),3); + EXPECT_STREQ(get[0],"Face"); + EXPECT_STREQ(get[1],"Edge"); + EXPECT_STREQ(get[2],"Vertex"); + unsigned long sec = rf.countSubElements("Edge"); + EXPECT_EQ(sec,25); + _fused->Refine.setValue(true); + _fused->execute(); + rf = _fused->Shape.getValue(); + sec = rf.countSubElements("Edge"); + EXPECT_EQ(sec,24); + + _fillet->Edges.setValues(_getFilletEdges()); + + // Act + double volume; + + volume = PartTestHelpers::getVolume(_fused->Shape.getValue()); + EXPECT_DOUBLE_EQ(volume,126.0); + volume = PartTestHelpers::getVolume(_fillet->Shape.getValue()); + EXPECT_DOUBLE_EQ(volume,0.0); + _fillet->execute(); + volume = PartTestHelpers::getVolume(_fillet->Shape.getValue()); + EXPECT_DOUBLE_EQ(volume,125.80944686460914); +} + +TEST_F(FeatureFilletTest, testOuter) +{ + // Arrange + _fillet->Base.setValue(_fused); + _fillet->Edges.setValues(_getFilletEdges({3,4,5,6,7,8,9,10})); + + // Act + _fillet->execute(); + Part::TopoShape ts = _fillet->Shape.getValue(); +} + +// Hmmmm... FeaturePartCommon with insufficent parameters says MustExecute false, +// but FeatureFillet says MustExecute true ... Neither of these should really +// happen, though. + +TEST_F(FeatureFilletTest, testMustExecute) +{ + // Act + // short mE = _fillet->mustExecute(); + // // Assert + // EXPECT_FALSE(mE); + // _fillet->Base.setValue(_box1obj); + // // Assert + // mE = _fillet->mustExecute(); + // EXPECT_FALSE(mE); + // // Act + // // _fillet->Edges.setValue(_box2obj); + // // Assert + // mE = _fillet->mustExecute(); + // EXPECT_TRUE(mE); + // _doc->recompute(); + // mE = _fillet->mustExecute(); + // EXPECT_FALSE(mE); +} + +TEST_F(FeatureFilletTest, testGetProviderName) +{ + // Act + _fillet->execute(); + const char* name = _fillet->getViewProviderName(); + // Assert + EXPECT_STREQ(name, "PartGui::ViewProviderFillet"); +} + + +// TEST_F(FeatureFilletTest, testHistory) +// { +// // Arrange +// _fillet->Base.setValue(_box1obj); +// _fillet->Tool.setValue(_box2obj); + +// // Act and Assert +// std::vector hist = _fillet->History.getValues(); +// EXPECT_EQ(hist.size(), 0); + +// // This creates the histories classically generated by FreeCAD for comparison +// using MapList = std::map>; +// using List = std::vector; +// MapList compare1 = +// {{0, List {0}}, {1, List {5}}, {2, List()}, {3, List {2}}, {4, List {3}}, {5, List {1}}}; +// MapList compare2 = +// {{0, List {0}}, {1, List {5}}, {2, List {4}}, {3, List()}, {4, List {3}}, {5, List {1}}}; + +// _fillet->execute(); +// hist = _fillet->History.getValues(); +// EXPECT_EQ(hist.size(), 2); +// EXPECT_EQ(hist[0].shapeMap, compare1); +// EXPECT_EQ(hist[1].shapeMap, compare2); +// _fillet->Base.setValue(_box2obj); +// _fillet->Tool.setValue(_box1obj); +// _fillet->execute(); +// hist = _fillet->History.getValues(); +// // std::cout << testing::PrintToString(hist[0]) << testing::PrintToString(hist[1]); +// EXPECT_EQ(hist.size(), 2); +// EXPECT_EQ(hist[1].shapeMap, compare1); +// EXPECT_EQ(hist[0].shapeMap, compare2); +// } diff --git a/tests/src/Mod/Part/App/FeaturePartCommon.cpp b/tests/src/Mod/Part/App/FeaturePartCommon.cpp index ef460523ff..6023eabfed 100644 --- a/tests/src/Mod/Part/App/FeaturePartCommon.cpp +++ b/tests/src/Mod/Part/App/FeaturePartCommon.cpp @@ -19,13 +19,13 @@ protected: void SetUp() override { createTestDoc(); - _common = static_cast(_doc->addObject("Part::Common")); + _common = dynamic_cast(_doc->addObject("Part::Common")); } void TearDown() override {} - Part::Common* _common; + Part::Common* _common; // NOLINT Can't be private in a test framework }; TEST_F(FeaturePartCommonTest, testIntersecting) @@ -106,7 +106,7 @@ TEST_F(FeaturePartCommonTest, testBarelyIntersecting) { // Arrange _common->Base.setValue(_boxes[0]); - _common->Tool.setValue(_boxes[5]); + _common->Tool.setValue(_boxes[5]); // NOLINT magic number // Act _common->execute(); @@ -165,9 +165,9 @@ TEST_F(FeaturePartCommonTest, testHistory) using MapList = std::map>; using List = std::vector; MapList compare1 = - {{0, List {0}}, {1, List {5}}, {2, List()}, {3, List {2}}, {4, List {3}}, {5, List {1}}}; + {{0, List {0}}, {1, List {5}}, {2, List()}, {3, List {2}}, {4, List {3}}, {5, List {1}}}; // NOLINT magic number MapList compare2 = - {{0, List {0}}, {1, List {5}}, {2, List {4}}, {3, List()}, {4, List {3}}, {5, List {1}}}; + {{0, List {0}}, {1, List {5}}, {2, List {4}}, {3, List()}, {4, List {3}}, {5, List {1}}}; // NOLINT magic number // Act and Assert no histories yet std::vector hist = _common->History.getValues(); diff --git a/tests/src/Mod/Part/App/FeaturePartCut.cpp b/tests/src/Mod/Part/App/FeaturePartCut.cpp index 3b12aede87..29276e4566 100644 --- a/tests/src/Mod/Part/App/FeaturePartCut.cpp +++ b/tests/src/Mod/Part/App/FeaturePartCut.cpp @@ -18,13 +18,13 @@ protected: void SetUp() override { createTestDoc(); - _cut = static_cast(_doc->addObject("Part::Cut")); + _cut = dynamic_cast(_doc->addObject("Part::Cut")); } void TearDown() override {} - Part::Cut* _cut; + Part::Cut* _cut; // NOLINT Can't be private in a test framework }; TEST_F(FeaturePartCutTest, testIntersecting) @@ -123,7 +123,7 @@ TEST_F(FeaturePartCutTest, testBarelyIntersecting) { // Arrange _cut->Base.setValue(_boxes[0]); - _cut->Tool.setValue(_boxes[5]); + _cut->Tool.setValue(_boxes[5]); // NOLINT magic number // Act _cut->execute(); diff --git a/tests/src/Mod/Part/App/FeaturePartFuse.cpp b/tests/src/Mod/Part/App/FeaturePartFuse.cpp index b8df7c61c9..bcfdb0bf36 100644 --- a/tests/src/Mod/Part/App/FeaturePartFuse.cpp +++ b/tests/src/Mod/Part/App/FeaturePartFuse.cpp @@ -19,13 +19,13 @@ protected: void SetUp() override { createTestDoc(); - _fuse = static_cast(_doc->addObject("Part::Fuse")); + _fuse = dynamic_cast(_doc->addObject("Part::Fuse")); } void TearDown() override {} - Part::Fuse* _fuse; + Part::Fuse* _fuse; // NOLINT Can't be private in a test framework }; TEST_F(FeaturePartFuseTest, testIntersecting) @@ -124,7 +124,7 @@ TEST_F(FeaturePartFuseTest, testBarelyIntersecting) { // Arrange _fuse->Base.setValue(_boxes[0]); - _fuse->Tool.setValue(_boxes[5]); + _fuse->Tool.setValue(_boxes[5]); // NOLINT magic number // Act _fuse->execute(); From c0b0f186388cb48a5a717ff9e08af4491a513dc8 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 23 Dec 2023 12:29:32 +0000 Subject: [PATCH 11/16] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/src/Mod/Part/App/FeatureFillet.cpp | 38 ++++++++++---------- tests/src/Mod/Part/App/FeaturePartCommon.cpp | 16 ++++++--- tests/src/Mod/Part/App/FeaturePartCut.cpp | 2 +- tests/src/Mod/Part/App/FeaturePartFuse.cpp | 2 +- 4 files changed, 34 insertions(+), 24 deletions(-) diff --git a/tests/src/Mod/Part/App/FeatureFillet.cpp b/tests/src/Mod/Part/App/FeatureFillet.cpp index 61289d4e7b..3d23e36cc3 100644 --- a/tests/src/Mod/Part/App/FeatureFillet.cpp +++ b/tests/src/Mod/Part/App/FeatureFillet.cpp @@ -6,9 +6,11 @@ #include "PartTestHelpers.h" -std::vector _getFilletEdges(std::vector edges = {1,2}, double startRadius = 0.3, double endRadius = 0.3) { +std::vector +_getFilletEdges(std::vector edges = {1, 2}, double startRadius = 0.3, double endRadius = 0.3) +{ std::vector filletElements; - for ( auto e : edges ) { + for (auto e : edges) { Part::FilletElement fe = {e, startRadius, endRadius}; filletElements.push_back(fe); } @@ -47,7 +49,7 @@ protected: void TearDown() override {} - Part::Fuse *_fused; + Part::Fuse* _fused; Part::Fillet* _fillet; }; @@ -55,39 +57,39 @@ TEST_F(FeatureFilletTest, testInner) { // Arrange _fillet->Base.setValue(_fused); - Part::TopoShape rf = _fused->Shape.getValue(); + Part::TopoShape rf = _fused->Shape.getValue(); std::vector get = rf.getElementTypes(); - ASSERT_EQ(get.size(),3); - EXPECT_STREQ(get[0],"Face"); - EXPECT_STREQ(get[1],"Edge"); - EXPECT_STREQ(get[2],"Vertex"); + ASSERT_EQ(get.size(), 3); + EXPECT_STREQ(get[0], "Face"); + EXPECT_STREQ(get[1], "Edge"); + EXPECT_STREQ(get[2], "Vertex"); unsigned long sec = rf.countSubElements("Edge"); - EXPECT_EQ(sec,25); + EXPECT_EQ(sec, 25); _fused->Refine.setValue(true); _fused->execute(); rf = _fused->Shape.getValue(); sec = rf.countSubElements("Edge"); - EXPECT_EQ(sec,24); + EXPECT_EQ(sec, 24); _fillet->Edges.setValues(_getFilletEdges()); // Act double volume; - - volume = PartTestHelpers::getVolume(_fused->Shape.getValue()); - EXPECT_DOUBLE_EQ(volume,126.0); - volume = PartTestHelpers::getVolume(_fillet->Shape.getValue()); - EXPECT_DOUBLE_EQ(volume,0.0); + + volume = PartTestHelpers::getVolume(_fused->Shape.getValue()); + EXPECT_DOUBLE_EQ(volume, 126.0); + volume = PartTestHelpers::getVolume(_fillet->Shape.getValue()); + EXPECT_DOUBLE_EQ(volume, 0.0); _fillet->execute(); - volume = PartTestHelpers::getVolume(_fillet->Shape.getValue()); - EXPECT_DOUBLE_EQ(volume,125.80944686460914); + volume = PartTestHelpers::getVolume(_fillet->Shape.getValue()); + EXPECT_DOUBLE_EQ(volume, 125.80944686460914); } TEST_F(FeatureFilletTest, testOuter) { // Arrange _fillet->Base.setValue(_fused); - _fillet->Edges.setValues(_getFilletEdges({3,4,5,6,7,8,9,10})); + _fillet->Edges.setValues(_getFilletEdges({3, 4, 5, 6, 7, 8, 9, 10})); // Act _fillet->execute(); diff --git a/tests/src/Mod/Part/App/FeaturePartCommon.cpp b/tests/src/Mod/Part/App/FeaturePartCommon.cpp index 6023eabfed..953f2f0dcf 100644 --- a/tests/src/Mod/Part/App/FeaturePartCommon.cpp +++ b/tests/src/Mod/Part/App/FeaturePartCommon.cpp @@ -164,10 +164,18 @@ TEST_F(FeaturePartCommonTest, testHistory) // Manually create the histories classically generated by FreeCAD for comparison using MapList = std::map>; using List = std::vector; - MapList compare1 = - {{0, List {0}}, {1, List {5}}, {2, List()}, {3, List {2}}, {4, List {3}}, {5, List {1}}}; // NOLINT magic number - MapList compare2 = - {{0, List {0}}, {1, List {5}}, {2, List {4}}, {3, List()}, {4, List {3}}, {5, List {1}}}; // NOLINT magic number + MapList compare1 = {{0, List {0}}, + {1, List {5}}, + {2, List()}, + {3, List {2}}, + {4, List {3}}, + {5, List {1}}}; // NOLINT magic number + MapList compare2 = {{0, List {0}}, + {1, List {5}}, + {2, List {4}}, + {3, List()}, + {4, List {3}}, + {5, List {1}}}; // NOLINT magic number // Act and Assert no histories yet std::vector hist = _common->History.getValues(); diff --git a/tests/src/Mod/Part/App/FeaturePartCut.cpp b/tests/src/Mod/Part/App/FeaturePartCut.cpp index 29276e4566..7699a70af2 100644 --- a/tests/src/Mod/Part/App/FeaturePartCut.cpp +++ b/tests/src/Mod/Part/App/FeaturePartCut.cpp @@ -24,7 +24,7 @@ protected: void TearDown() override {} - Part::Cut* _cut; // NOLINT Can't be private in a test framework + Part::Cut* _cut; // NOLINT Can't be private in a test framework }; TEST_F(FeaturePartCutTest, testIntersecting) diff --git a/tests/src/Mod/Part/App/FeaturePartFuse.cpp b/tests/src/Mod/Part/App/FeaturePartFuse.cpp index bcfdb0bf36..33ae5e5bec 100644 --- a/tests/src/Mod/Part/App/FeaturePartFuse.cpp +++ b/tests/src/Mod/Part/App/FeaturePartFuse.cpp @@ -124,7 +124,7 @@ TEST_F(FeaturePartFuseTest, testBarelyIntersecting) { // Arrange _fuse->Base.setValue(_boxes[0]); - _fuse->Tool.setValue(_boxes[5]); // NOLINT magic number + _fuse->Tool.setValue(_boxes[5]); // NOLINT magic number // Act _fuse->execute(); From df04428c6b799d1ede832613701bf45ec2d2713f Mon Sep 17 00:00:00 2001 From: bgbsww Date: Sat, 23 Dec 2023 08:06:16 -0500 Subject: [PATCH 12/16] Remove mistaken file --- tests/src/Mod/Part/App/FeatureFillet.cpp | 164 ----------------------- 1 file changed, 164 deletions(-) delete mode 100644 tests/src/Mod/Part/App/FeatureFillet.cpp diff --git a/tests/src/Mod/Part/App/FeatureFillet.cpp b/tests/src/Mod/Part/App/FeatureFillet.cpp deleted file mode 100644 index 3d23e36cc3..0000000000 --- a/tests/src/Mod/Part/App/FeatureFillet.cpp +++ /dev/null @@ -1,164 +0,0 @@ -// SPDX-License-Identifier: LGPL-2.1-or-later - -#include "gtest/gtest.h" - -#include - -#include "PartTestHelpers.h" - -std::vector -_getFilletEdges(std::vector edges = {1, 2}, double startRadius = 0.3, double endRadius = 0.3) -{ - std::vector filletElements; - for (auto e : edges) { - Part::FilletElement fe = {e, startRadius, endRadius}; - filletElements.push_back(fe); - } - return filletElements; -} - - -class FeatureFilletTest: public ::testing::Test, public PartTestHelpers::PartTestHelperClass -{ -protected: - static void SetUpTestSuite() - { - tests::initApplication(); - } - - void SetUp() override - { - createTestFile(); - _box1obj->Length.setValue(4); - _box1obj->Width.setValue(5); - _box1obj->Height.setValue(6); - _box1obj->Placement.setValue( - Base::Placement(Base::Vector3d(), Base::Rotation(), Base::Vector3d())); - _box2obj->Placement.setValue( - Base::Placement(Base::Vector3d(0, 1, 6), Base::Rotation(), Base::Vector3d())); - _box2obj->Length.setValue(1); - _box2obj->Width.setValue(2); - _box2obj->Height.setValue(3); - _fused = static_cast(_doc->addObject("Part::Fuse")); - _fused->Base.setValue(_box1obj); - _fused->Tool.setValue(_box2obj); - _fused->execute(); - _fillet = static_cast(_doc->addObject("Part::Fillet")); - } - - void TearDown() override - {} - - Part::Fuse* _fused; - Part::Fillet* _fillet; -}; - -TEST_F(FeatureFilletTest, testInner) -{ - // Arrange - _fillet->Base.setValue(_fused); - Part::TopoShape rf = _fused->Shape.getValue(); - std::vector get = rf.getElementTypes(); - ASSERT_EQ(get.size(), 3); - EXPECT_STREQ(get[0], "Face"); - EXPECT_STREQ(get[1], "Edge"); - EXPECT_STREQ(get[2], "Vertex"); - unsigned long sec = rf.countSubElements("Edge"); - EXPECT_EQ(sec, 25); - _fused->Refine.setValue(true); - _fused->execute(); - rf = _fused->Shape.getValue(); - sec = rf.countSubElements("Edge"); - EXPECT_EQ(sec, 24); - - _fillet->Edges.setValues(_getFilletEdges()); - - // Act - double volume; - - volume = PartTestHelpers::getVolume(_fused->Shape.getValue()); - EXPECT_DOUBLE_EQ(volume, 126.0); - volume = PartTestHelpers::getVolume(_fillet->Shape.getValue()); - EXPECT_DOUBLE_EQ(volume, 0.0); - _fillet->execute(); - volume = PartTestHelpers::getVolume(_fillet->Shape.getValue()); - EXPECT_DOUBLE_EQ(volume, 125.80944686460914); -} - -TEST_F(FeatureFilletTest, testOuter) -{ - // Arrange - _fillet->Base.setValue(_fused); - _fillet->Edges.setValues(_getFilletEdges({3, 4, 5, 6, 7, 8, 9, 10})); - - // Act - _fillet->execute(); - Part::TopoShape ts = _fillet->Shape.getValue(); -} - -// Hmmmm... FeaturePartCommon with insufficent parameters says MustExecute false, -// but FeatureFillet says MustExecute true ... Neither of these should really -// happen, though. - -TEST_F(FeatureFilletTest, testMustExecute) -{ - // Act - // short mE = _fillet->mustExecute(); - // // Assert - // EXPECT_FALSE(mE); - // _fillet->Base.setValue(_box1obj); - // // Assert - // mE = _fillet->mustExecute(); - // EXPECT_FALSE(mE); - // // Act - // // _fillet->Edges.setValue(_box2obj); - // // Assert - // mE = _fillet->mustExecute(); - // EXPECT_TRUE(mE); - // _doc->recompute(); - // mE = _fillet->mustExecute(); - // EXPECT_FALSE(mE); -} - -TEST_F(FeatureFilletTest, testGetProviderName) -{ - // Act - _fillet->execute(); - const char* name = _fillet->getViewProviderName(); - // Assert - EXPECT_STREQ(name, "PartGui::ViewProviderFillet"); -} - - -// TEST_F(FeatureFilletTest, testHistory) -// { -// // Arrange -// _fillet->Base.setValue(_box1obj); -// _fillet->Tool.setValue(_box2obj); - -// // Act and Assert -// std::vector hist = _fillet->History.getValues(); -// EXPECT_EQ(hist.size(), 0); - -// // This creates the histories classically generated by FreeCAD for comparison -// using MapList = std::map>; -// using List = std::vector; -// MapList compare1 = -// {{0, List {0}}, {1, List {5}}, {2, List()}, {3, List {2}}, {4, List {3}}, {5, List {1}}}; -// MapList compare2 = -// {{0, List {0}}, {1, List {5}}, {2, List {4}}, {3, List()}, {4, List {3}}, {5, List {1}}}; - -// _fillet->execute(); -// hist = _fillet->History.getValues(); -// EXPECT_EQ(hist.size(), 2); -// EXPECT_EQ(hist[0].shapeMap, compare1); -// EXPECT_EQ(hist[1].shapeMap, compare2); -// _fillet->Base.setValue(_box2obj); -// _fillet->Tool.setValue(_box1obj); -// _fillet->execute(); -// hist = _fillet->History.getValues(); -// // std::cout << testing::PrintToString(hist[0]) << testing::PrintToString(hist[1]); -// EXPECT_EQ(hist.size(), 2); -// EXPECT_EQ(hist[1].shapeMap, compare1); -// EXPECT_EQ(hist[0].shapeMap, compare2); -// } From 66f5f243d8fe2efb3cdcce87180fc09403807f18 Mon Sep 17 00:00:00 2001 From: bgbsww Date: Sat, 23 Dec 2023 08:20:34 -0500 Subject: [PATCH 13/16] Missed cleanup --- tests/src/Mod/Part/App/PartTestHelpers.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/src/Mod/Part/App/PartTestHelpers.cpp b/tests/src/Mod/Part/App/PartTestHelpers.cpp index cbaa02e3d4..bd2ac35ec7 100644 --- a/tests/src/Mod/Part/App/PartTestHelpers.cpp +++ b/tests/src/Mod/Part/App/PartTestHelpers.cpp @@ -21,11 +21,9 @@ void PartTestHelperClass::createTestDoc() Base::Vector3d(0, 3, 0), // Don't Overlap with first box Base::Vector3d(0, 2, 0), // Touch the first box Base::Vector3d(0, 2 + Base::Precision::Confusion(), 0), // Just Outside of touching - // For just inside of touching, go enough that precision rounding doesn't make us overlap. + // For the Just Inside Of Touching case, go enough that we exceed precision rounding Base::Vector3d(0, 2 - minimalDistance, 0)}; - // for (auto& [box, origin] : zip(_boxes, box_origins) ) { - // for ( int i : range(0,_boxes.size())) { for (unsigned i = 0; i < _boxes.size(); i++) { auto box = _boxes[i] = static_cast(_doc->addObject("Part::Box")); box->Length.setValue(1); From 35b853deb5415d81266380312988c07eda2c1133 Mon Sep 17 00:00:00 2001 From: bgbsww Date: Sun, 24 Dec 2023 17:34:19 -0500 Subject: [PATCH 14/16] Remote experimental PrintTo that doesn't work. --- tests/src/Mod/Part/App/PartTestHelpers.cpp | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/tests/src/Mod/Part/App/PartTestHelpers.cpp b/tests/src/Mod/Part/App/PartTestHelpers.cpp index bd2ac35ec7..59e63685b4 100644 --- a/tests/src/Mod/Part/App/PartTestHelpers.cpp +++ b/tests/src/Mod/Part/App/PartTestHelpers.cpp @@ -35,24 +35,3 @@ void PartTestHelperClass::createTestDoc() } } // namespace PartTestHelpers - -// https://google.github.io/googletest/advanced.html#teaching-googletest-how-to-print-your-values -namespace Part -{ -void PrintTo(ShapeHistory sh, std::ostream* os) -{ - const char* types[] = - {"Compound", "CompSolid", "Solid", "Shell", "Face", "Wire", "Edge", "Vertex", "Shape"}; - *os << "History for " << types[sh.type] << " is "; - for (const auto& it : sh.shapeMap) { - int old_shape_index = it.first; - *os << " " << old_shape_index << ": "; - if (!it.second.empty()) { - for (auto it2 : it.second) { - *os << it2 << " "; - } - } - } - *os << std::endl; -} -} // namespace Part From 00a9b3261eb6affd78922f77eb419fa3b6001e55 Mon Sep 17 00:00:00 2001 From: bgbsww Date: Mon, 25 Dec 2023 17:44:06 -0500 Subject: [PATCH 15/16] More delinting --- tests/src/Mod/Part/App/FeaturePartCommon.cpp | 6 +++--- tests/src/Mod/Part/App/FeaturePartCut.cpp | 4 ++-- tests/src/Mod/Part/App/FeaturePartFuse.cpp | 4 ++-- tests/src/Mod/Part/App/PartTestHelpers.cpp | 6 +++--- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/src/Mod/Part/App/FeaturePartCommon.cpp b/tests/src/Mod/Part/App/FeaturePartCommon.cpp index 953f2f0dcf..be062749bb 100644 --- a/tests/src/Mod/Part/App/FeaturePartCommon.cpp +++ b/tests/src/Mod/Part/App/FeaturePartCommon.cpp @@ -25,7 +25,7 @@ protected: void TearDown() override {} - Part::Common* _common; // NOLINT Can't be private in a test framework + Part::Common* _common = nullptr; // NOLINT Can't be private in a test framework }; TEST_F(FeaturePartCommonTest, testIntersecting) @@ -165,13 +165,13 @@ TEST_F(FeaturePartCommonTest, testHistory) using MapList = std::map>; using List = std::vector; MapList compare1 = {{0, List {0}}, - {1, List {5}}, + {1, List {5}}, // NOLINT magic number {2, List()}, {3, List {2}}, {4, List {3}}, {5, List {1}}}; // NOLINT magic number MapList compare2 = {{0, List {0}}, - {1, List {5}}, + {1, List {5}}, // NOLINT magic number {2, List {4}}, {3, List()}, {4, List {3}}, diff --git a/tests/src/Mod/Part/App/FeaturePartCut.cpp b/tests/src/Mod/Part/App/FeaturePartCut.cpp index 7699a70af2..b5148d68ce 100644 --- a/tests/src/Mod/Part/App/FeaturePartCut.cpp +++ b/tests/src/Mod/Part/App/FeaturePartCut.cpp @@ -24,7 +24,7 @@ protected: void TearDown() override {} - Part::Cut* _cut; // NOLINT Can't be private in a test framework + Part::Cut* _cut = nullptr; // NOLINT Can't be private in a test framework }; TEST_F(FeaturePartCutTest, testIntersecting) @@ -129,7 +129,7 @@ TEST_F(FeaturePartCutTest, testBarelyIntersecting) _cut->execute(); Part::TopoShape ts = _cut->Shape.getValue(); double volume = PartTestHelpers::getVolume(ts.getShape()); - double target = 6 - PartTestHelpers::minimalDistance * 3; // 3 dimensions in a Volume + double target = 6 - PartTestHelpers::minimalDistance * 3; // NOLINT 3 dimensions in a Volume Base::BoundBox3d bb = ts.getBoundBox(); // Assert diff --git a/tests/src/Mod/Part/App/FeaturePartFuse.cpp b/tests/src/Mod/Part/App/FeaturePartFuse.cpp index 33ae5e5bec..9ea4b11392 100644 --- a/tests/src/Mod/Part/App/FeaturePartFuse.cpp +++ b/tests/src/Mod/Part/App/FeaturePartFuse.cpp @@ -25,7 +25,7 @@ protected: void TearDown() override {} - Part::Fuse* _fuse; // NOLINT Can't be private in a test framework + Part::Fuse* _fuse = nullptr; // NOLINT Can't be private in a test framework }; TEST_F(FeaturePartFuseTest, testIntersecting) @@ -130,7 +130,7 @@ TEST_F(FeaturePartFuseTest, testBarelyIntersecting) _fuse->execute(); Part::TopoShape ts = _fuse->Shape.getValue(); double volume = PartTestHelpers::getVolume(ts.getShape()); - double target = 12 - PartTestHelpers::minimalDistance * 3; // 3 dimensions in a Volume + double target = 12 - PartTestHelpers::minimalDistance * 3; // NOLINT 3 dimensions in a Volume Base::BoundBox3d bb = ts.getBoundBox(); // Assert diff --git a/tests/src/Mod/Part/App/PartTestHelpers.cpp b/tests/src/Mod/Part/App/PartTestHelpers.cpp index 59e63685b4..5c6d59bfd8 100644 --- a/tests/src/Mod/Part/App/PartTestHelpers.cpp +++ b/tests/src/Mod/Part/App/PartTestHelpers.cpp @@ -4,7 +4,7 @@ namespace PartTestHelpers { -double getVolume(TopoDS_Shape shape) +double getVolume(const TopoDS_Shape shape) { GProp_GProps prop; BRepGProp::VolumeProperties(shape, prop); @@ -15,7 +15,7 @@ void PartTestHelperClass::createTestDoc() { _docName = App::GetApplication().getUniqueDocumentName("test"); _doc = App::GetApplication().newDocument(_docName.c_str(), "testUser"); - std::array box_origins = { + std::array box_origins = { // NOLINT magic number Base::Vector3d(), // First box at 0,0,0 Base::Vector3d(0, 1, 0), // Overlap with first box Base::Vector3d(0, 3, 0), // Don't Overlap with first box @@ -24,7 +24,7 @@ void PartTestHelperClass::createTestDoc() // For the Just Inside Of Touching case, go enough that we exceed precision rounding Base::Vector3d(0, 2 - minimalDistance, 0)}; - for (unsigned i = 0; i < _boxes.size(); i++) { + for (int i = 0; i < _boxes.size(); i++) { auto box = _boxes[i] = static_cast(_doc->addObject("Part::Box")); box->Length.setValue(1); box->Width.setValue(2); From 9192a30a93719a309426717b8ea21e1cecf02b50 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 25 Dec 2023 22:44:47 +0000 Subject: [PATCH 16/16] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/src/Mod/Part/App/PartTestHelpers.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/src/Mod/Part/App/PartTestHelpers.cpp b/tests/src/Mod/Part/App/PartTestHelpers.cpp index 5c6d59bfd8..cdcfa44e95 100644 --- a/tests/src/Mod/Part/App/PartTestHelpers.cpp +++ b/tests/src/Mod/Part/App/PartTestHelpers.cpp @@ -15,7 +15,8 @@ void PartTestHelperClass::createTestDoc() { _docName = App::GetApplication().getUniqueDocumentName("test"); _doc = App::GetApplication().newDocument(_docName.c_str(), "testUser"); - std::array box_origins = { // NOLINT magic number + std::array box_origins = { + // NOLINT magic number Base::Vector3d(), // First box at 0,0,0 Base::Vector3d(0, 1, 0), // Overlap with first box Base::Vector3d(0, 3, 0), // Don't Overlap with first box