Skip to content

Commit

Permalink
modify tests
Browse files Browse the repository at this point in the history
Signed-off-by: Ashton Larkin <[email protected]>
  • Loading branch information
adlarkin committed Mar 12, 2021
1 parent b611545 commit a9b33c9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 23 deletions.
26 changes: 15 additions & 11 deletions dartsim/src/SimulationFeatures_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ std::unordered_set<TestWorldPtr> LoadWorlds(
/// \param[in] _firstTime Whether this is the very first time this world is
/// being stepped in (true) or not (false)
/// \param[in] _numSteps The number of steps to take in _world
void StepWorld(const TestWorldPtr &_world, bool _firstTime,
/// \return true if the forward step output was checked, false otherwise
bool StepWorld(const TestWorldPtr &_world, bool _firstTime,
const std::size_t _numSteps = 1)
{
ignition::physics::ForwardStep::Input input;
Expand All @@ -121,10 +122,7 @@ void StepWorld(const TestWorldPtr &_world, bool _firstTime,
}
}

if (_firstTime)
EXPECT_TRUE(checkedOutput);
else
EXPECT_FALSE(checkedOutput);
return checkedOutput;
}

class SimulationFeatures_TEST
Expand All @@ -144,7 +142,8 @@ TEST_P(SimulationFeatures_TEST, Falling)

for (const auto &world : worlds)
{
StepWorld(world, true, 1000);
auto checkedOutput =StepWorld(world, true, 1000);
EXPECT_TRUE(checkedOutput);

auto link = world->GetModel(0)->GetLink(0);
auto pos = link->FrameDataRelativeToWorld().pose.translation();
Expand Down Expand Up @@ -218,7 +217,8 @@ TEST_P(SimulationFeatures_TEST, CollideBitmasks)
auto filteredBox = world->GetModel("box_filtered");
auto collidingBox = world->GetModel("box_colliding");

StepWorld(world, true);
auto checkedOutput = StepWorld(world, true);
EXPECT_TRUE(checkedOutput);
auto contacts = world->GetContactsFromLastStep();
// Only one box (box_colliding) should collide
EXPECT_EQ(4u, contacts.size());
Expand All @@ -230,15 +230,17 @@ TEST_P(SimulationFeatures_TEST, CollideBitmasks)
// Also test the getter
EXPECT_EQ(0xF0, collidingShape->GetCollisionFilterMask());
// Step and make sure there is no collisions
StepWorld(world, false);
checkedOutput = StepWorld(world, false);
EXPECT_FALSE(checkedOutput);
contacts = world->GetContactsFromLastStep();
EXPECT_EQ(0u, contacts.size());

// Now remove both filter masks (no collision will be filtered)
// Equivalent to set to 0xFF
collidingShape->RemoveCollisionFilterMask();
filteredShape->RemoveCollisionFilterMask();
StepWorld(world, false);
checkedOutput = StepWorld(world, false);
EXPECT_FALSE(checkedOutput);
// Expect both objects to collide
contacts = world->GetContactsFromLastStep();
EXPECT_EQ(8u, contacts.size());
Expand All @@ -263,10 +265,12 @@ TEST_P(SimulationFeatures_TEST, RetrieveContacts)
// The first step already has contacts, but the contact force due to the
// impact does not match the steady-state force generated by the
// body's weight.
StepWorld(world, true);
auto checkedOutput = StepWorld(world, true);
EXPECT_TRUE(checkedOutput);

// After a second step, the contact force reaches steady-state
StepWorld(world, false);
checkedOutput = StepWorld(world, false);
EXPECT_FALSE(checkedOutput);

auto contacts = world->GetContactsFromLastStep();
EXPECT_EQ(4u, contacts.size());
Expand Down
29 changes: 17 additions & 12 deletions tpe/plugin/src/SimulationFeatures_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ std::unordered_set<TestWorldPtr> LoadWorlds(
/// \param[in] _firstTime Whether this is the very first time this world is
/// being stepped in (true) or not (false)
/// \param[in] _numSteps The number of steps to take in _world
void StepWorld(const TestWorldPtr &_world, bool _firstTime,
/// \return true if the forward step output was checked, false otherwise
bool StepWorld(const TestWorldPtr &_world, bool _firstTime,
const std::size_t _numSteps = 1)
{
ignition::physics::ForwardStep::Input input;
Expand All @@ -119,10 +120,7 @@ void StepWorld(const TestWorldPtr &_world, bool _firstTime,
}
}

if (_firstTime)
EXPECT_TRUE(checkedOutput);
else
EXPECT_FALSE(checkedOutput);
return checkedOutput;
}

class SimulationFeatures_TEST
Expand All @@ -142,7 +140,8 @@ TEST_P(SimulationFeatures_TEST, StepWorld)

for (const auto &world : worlds)
{
StepWorld(world, true, 1000);
auto checkedOutput = StepWorld(world, true, 1000);
EXPECT_TRUE(checkedOutput);

auto model = world->GetModel(0);
ASSERT_NE(nullptr, model);
Expand Down Expand Up @@ -292,7 +291,8 @@ TEST_P(SimulationFeatures_TEST, CollideBitmasks)
auto filteredBox = world->GetModel("box_filtered");
auto collidingBox = world->GetModel("box_colliding");

StepWorld(world, true);
auto checkedOutput = StepWorld(world, true);
EXPECT_TRUE(checkedOutput);
auto contacts = world->GetContactsFromLastStep();
// Only box_colliding should collide with box_base
EXPECT_EQ(1u, contacts.size());
Expand All @@ -304,15 +304,17 @@ TEST_P(SimulationFeatures_TEST, CollideBitmasks)
// Also test the getter
EXPECT_EQ(0xF0, collidingShape->GetCollisionFilterMask());
// Step and make sure there are no collisions
StepWorld(world, false);
checkedOutput = StepWorld(world, false);
EXPECT_FALSE(checkedOutput);
contacts = world->GetContactsFromLastStep();
EXPECT_EQ(0u, contacts.size());

// Now remove both filter masks (no collisions will be filtered)
// Equivalent to 0xFF
collidingShape->RemoveCollisionFilterMask();
filteredShape->RemoveCollisionFilterMask();
StepWorld(world, false);
checkedOutput = StepWorld(world, false);
EXPECT_FALSE(checkedOutput);
// Expect box_filtered and box_colliding to collide with box_base
contacts = world->GetContactsFromLastStep();
EXPECT_EQ(2u, contacts.size());
Expand Down Expand Up @@ -340,7 +342,8 @@ TEST_P(SimulationFeatures_TEST, RetrieveContacts)
auto box = world->GetModel("box");

// step and get contacts
StepWorld(world, true);
auto checkedOutput = StepWorld(world, true);
EXPECT_TRUE(checkedOutput);
auto contacts = world->GetContactsFromLastStep();

// large box in the middle should be intersecting with sphere and cylinder
Expand Down Expand Up @@ -389,7 +392,8 @@ TEST_P(SimulationFeatures_TEST, RetrieveContacts)
ignition::math::Pose3d(0, 100, 0.5, 0, 0, 0)));

// step and get contacts
StepWorld(world, false);
checkedOutput = StepWorld(world, false);
EXPECT_FALSE(checkedOutput);
contacts = world->GetContactsFromLastStep();

// large box in the middle should be intersecting with cylinder
Expand Down Expand Up @@ -424,7 +428,8 @@ TEST_P(SimulationFeatures_TEST, RetrieveContacts)
ignition::math::Pose3d(0, -100, 0.5, 0, 0, 0)));

// step and get contacts
StepWorld(world, false);
checkedOutput = StepWorld(world, false);
EXPECT_FALSE(checkedOutput);
contacts = world->GetContactsFromLastStep();

// no entities should be colliding
Expand Down

0 comments on commit a9b33c9

Please sign in to comment.