Cleanups per pesc0 review notes; general code tightening

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

View File

@@ -15,106 +15,152 @@ protected:
tests::initApplication();
}
void SetUp() override
{
createTestFile();
createTestDoc();
_cut = static_cast<Part::Cut*>(_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.