Skip to content

Commit

Permalink
LinkFeatures_TEST: check GetGravity in LoadWorld
Browse files Browse the repository at this point in the history
Requires moving definition of AssertVectorApprox

Signed-off-by: Steven Peters <scpeters@openrobotics.org>
  • Loading branch information
scpeters committed Jul 14, 2021
1 parent 315424c commit ef1012d
Showing 1 changed file with 25 additions and 20 deletions.
45 changes: 25 additions & 20 deletions dartsim/src/LinkFeatures_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,26 +74,6 @@ class LinkFeaturesFixture : public ::testing::Test
protected: TestEnginePtr engine;
};

TestWorldPtr LoadWorld(
const TestEnginePtr &_engine,
const std::string &_sdfFile,
const Eigen::Vector3d &_gravity = Eigen::Vector3d{0, 0, -9.8})
{
sdf::Root root;
const sdf::Errors errors = root.Load(_sdfFile);
EXPECT_TRUE(errors.empty()) << errors;
const sdf::World *sdfWorld = root.WorldByIndex(0);
EXPECT_NE(nullptr, sdfWorld);

auto graphErrors = sdfWorld->ValidateGraphs();
EXPECT_EQ(0u, graphErrors.size()) << graphErrors;

TestWorldPtr world = _engine->ConstructWorld(*sdfWorld);
EXPECT_NE(nullptr, world);
world->SetGravity(_gravity);
return world;
}

// A predicate-formatter for asserting that two vectors are approximately equal.
class AssertVectorApprox
{
Expand All @@ -117,6 +97,31 @@ class AssertVectorApprox
private: double tol;
};

TestWorldPtr LoadWorld(
const TestEnginePtr &_engine,
const std::string &_sdfFile,
const Eigen::Vector3d &_gravity = Eigen::Vector3d{0, 0, -9.8})
{
sdf::Root root;
const sdf::Errors errors = root.Load(_sdfFile);
EXPECT_TRUE(errors.empty()) << errors;
const sdf::World *sdfWorld = root.WorldByIndex(0);
EXPECT_NE(nullptr, sdfWorld);

auto graphErrors = sdfWorld->ValidateGraphs();
EXPECT_EQ(0u, graphErrors.size()) << graphErrors;

TestWorldPtr world = _engine->ConstructWorld(*sdfWorld);
EXPECT_NE(nullptr, world);
world->SetGravity(_gravity);

AssertVectorApprox vectorPredicate(1e-10);
EXPECT_PRED_FORMAT2(vectorPredicate, _gravity,
world->GetGravity());

return world;
}

// Test setting force and torque.
TEST_F(LinkFeaturesFixture, LinkForceTorque)
{
Expand Down

0 comments on commit ef1012d

Please sign in to comment.