| | |
| |
|
| | #include <gtest/gtest.h> |
| |
|
| | #include <src/App/InitApplication.h> |
| |
|
| | #include "PartTestHelpers.h" |
| | #include "Mod/Part/App/FeatureChamfer.h" |
| |
|
| | class FeatureChamferTest: public ::testing::Test, public PartTestHelpers::PartTestHelperClass |
| | { |
| | protected: |
| | static void SetUpTestSuite() |
| | { |
| | tests::initApplication(); |
| | } |
| |
|
| | void SetUp() override |
| | { |
| | createTestDoc(); |
| | _boxes[0]->Length.setValue(length); |
| | _boxes[0]->Width.setValue(width); |
| | _boxes[0]->Height.setValue(height); |
| | _boxes[0]->Placement.setValue( |
| | Base::Placement(Base::Vector3d(), Base::Rotation(), Base::Vector3d()) |
| | ); |
| | _boxes[1]->Placement.setValue( |
| | Base::Placement(Base::Vector3d(0, 1, height), Base::Rotation(), Base::Vector3d()) |
| | ); |
| | _boxes[1]->Length.setValue(1); |
| | _boxes[1]->Width.setValue(2); |
| | _boxes[1]->Height.setValue(3); |
| | _fused = _doc->addObject<Part::Fuse>(); |
| | _fused->Base.setValue(_boxes[0]); |
| | _fused->Tool.setValue(_boxes[1]); |
| | _fused->Refine.setValue(false); |
| | _fused->execute(); |
| | _chamfer = _doc->addObject<Part::Chamfer>(); |
| | } |
| |
|
| | void TearDown() override |
| | {} |
| |
|
| | |
| | const double length = 4.0; |
| | const double width = 5.0; |
| | const double height = 6.0; |
| | const double chamfer = 0.5; |
| | Part::Fuse* _fused = nullptr; |
| | Part::Chamfer* _chamfer = nullptr; |
| | |
| | }; |
| |
|
| | |
| | |
| | |
| |
|
| | TEST_F(FeatureChamferTest, testOther) |
| | { |
| | const double baseVolume = _boxes[0]->Length.getValue() * _boxes[0]->Width.getValue() |
| | * _boxes[0]->Height.getValue() |
| | + _boxes[1]->Length.getValue() * _boxes[1]->Width.getValue() * _boxes[1]->Height.getValue(); |
| | |
| | _chamfer->Base.setValue(_fused); |
| | Part::TopoShape ts = _fused->Shape.getValue(); |
| | unsigned long sec = ts.countSubElements("Edge"); |
| | |
| | EXPECT_EQ(sec, 25); |
| | |
| | _fused->Refine.setValue(true); |
| | _fused->execute(); |
| | ts = _fused->Shape.getValue(); |
| | sec = ts.countSubElements("Edge"); |
| | |
| | EXPECT_EQ(sec, 24); |
| | |
| | _chamfer->Edges.setValues(PartTestHelpers::_getFilletEdges({1, 2}, chamfer, chamfer)); |
| | double fusedVolume = PartTestHelpers::getVolume(_fused->Shape.getValue()); |
| | double chamferVolume = PartTestHelpers::getVolume(_chamfer->Shape.getValue()); |
| | |
| | EXPECT_DOUBLE_EQ(fusedVolume, baseVolume); |
| | EXPECT_DOUBLE_EQ(chamferVolume, 0.0); |
| | |
| | _chamfer->execute(); |
| | chamferVolume = PartTestHelpers::getVolume(_chamfer->Shape.getValue()); |
| | double cv = (_boxes[0]->Length.getValue()) * chamfer * chamfer / 2 |
| | + (_boxes[0]->Height.getValue()) * chamfer * chamfer / 2 - chamfer * chamfer * chamfer / 3; |
| | |
| | EXPECT_FLOAT_EQ(chamferVolume, baseVolume - cv); |
| | } |
| |
|
| | TEST_F(FeatureChamferTest, testMost) |
| | { |
| | |
| | _fused->Refine.setValue(true); |
| | _fused->execute(); |
| | _chamfer->Base.setValue(_fused); |
| | _chamfer->Edges.setValues( |
| | PartTestHelpers::_getFilletEdges( |
| | {3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, |
| | 15, 16, 17, 18, 19, 20, 21, 22, 23, 24}, |
| | 0.4, |
| | 0.4 |
| | ) |
| | ); |
| | |
| | _chamfer->execute(); |
| | double chamferVolume = PartTestHelpers::getVolume(_chamfer->Shape.getValue()); |
| | |
| | EXPECT_NEAR(chamferVolume, 121.46667, 1e-5); |
| | } |
| |
|
| | |
| | |
| |
|
| | TEST_F(FeatureChamferTest, testMustExecute) |
| | { |
| | |
| | EXPECT_TRUE(_chamfer->mustExecute()); |
| | |
| | _chamfer->Base.setValue(_boxes[0]); |
| | |
| | EXPECT_TRUE(_chamfer->mustExecute()); |
| | |
| | _chamfer->Edges.setValues(PartTestHelpers::_getFilletEdges({1}, chamfer, chamfer)); |
| | |
| | EXPECT_TRUE(_chamfer->mustExecute()); |
| | |
| | _doc->recompute(); |
| | |
| | EXPECT_FALSE(_chamfer->mustExecute()); |
| | } |
| |
|
| | TEST_F(FeatureChamferTest, testGetProviderName) |
| | { |
| | |
| | _chamfer->execute(); |
| | const char* name = _chamfer->getViewProviderName(); |
| | |
| | EXPECT_STREQ(name, "PartGui::ViewProviderChamfer"); |
| | } |
| |
|