Cleanups per pesc0 review notes; general code tightening

This commit is contained in:
bgbsww
2023-12-23 05:47:39 -05:00
parent 906826c1c8
commit f81ce9d2e1
5 changed files with 277 additions and 182 deletions

View File

@@ -16,10 +16,9 @@ protected:
tests::initApplication();
}
void SetUp() override
{
createTestFile();
createTestDoc();
_fuse = static_cast<Part::Fuse*>(_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<Part::TopoShape> subs = ts.getSubTopoShapes(TopAbs_FACE); // WIRE
std::vector<Part::TopoShape> 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.