Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed naming issues for Skeletons in World and created regression tests #331

Merged
merged 1 commit into from
Feb 12, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions dart/simulation/World.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,8 @@ std::string World::addSkeleton(dynamics::Skeleton* _skeleton)
}

mSkeletons.push_back(_skeleton);
mNameMgrForSkeletons.issueNewNameAndAdd(_skeleton->getName(), _skeleton);
_skeleton->setName(mNameMgrForSkeletons.issueNewNameAndAdd(
_skeleton->getName(), _skeleton));
_skeleton->init(mTimeStep, mGravity);
mIndices.push_back(mIndices.back() + _skeleton->getNumDofs());
mConstraintSolver->addSkeleton(_skeleton);
Expand Down Expand Up @@ -270,7 +271,6 @@ void World::removeSkeleton(dynamics::Skeleton* _skeleton)
mIndices.pop_back();

// Remove _skeleton from constraint handler.
// mConstraintHandler->removeSkeleton(_skeleton);
mConstraintSolver->removeSkeleton(_skeleton);

// Remove _skeleton in mSkeletons and delete it.
Expand All @@ -280,6 +280,9 @@ void World::removeSkeleton(dynamics::Skeleton* _skeleton)
// Update recording
mRecording->updateNumGenCoords(mSkeletons);

// Remove from NameManager
mNameMgrForSkeletons.removeName(_skeleton->getName());

delete _skeleton;
}

Expand Down
25 changes: 25 additions & 0 deletions unittests/testWorld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,31 +101,56 @@ TEST(WORLD, ADDING_AND_REMOVING_SKELETONS)
for (int i = 0; i < nSteps; ++i)
world->step();

std::string s1name = skeleton1->getName();
std::string s2name = skeleton2->getName();
EXPECT_TRUE(skeleton1 == world->getSkeleton(s1name));
EXPECT_TRUE(skeleton2 == world->getSkeleton(s2name));

// Remove skeleton2
world->removeSkeleton(skeleton2);
EXPECT_TRUE(world->getNumSkeletons() == 1);
for (int i = 0; i < nSteps; ++i)
world->step();

EXPECT_TRUE(skeleton1 == world->getSkeleton(s1name));
EXPECT_FALSE(skeleton2 == world->getSkeleton(s2name));
EXPECT_TRUE(world->getSkeleton(s2name) == NULL);

// Add skeleton3, skeleton4
world->addSkeleton(skeleton3);
world->addSkeleton(skeleton4);
EXPECT_TRUE(world->getNumSkeletons() == 3);
for (int i = 0; i < nSteps; ++i)
world->step();

std::string s3name = skeleton3->getName();
std::string s4name = skeleton4->getName();

EXPECT_TRUE(s3name == s2name);
EXPECT_TRUE(skeleton3 == world->getSkeleton(s3name));
EXPECT_TRUE(skeleton4 == world->getSkeleton(s4name));

// Remove skeleton1
world->removeSkeleton(skeleton1);
EXPECT_TRUE(world->getNumSkeletons() == 2);
for (int i = 0; i < nSteps; ++i)
world->step();

EXPECT_FALSE(skeleton1 == world->getSkeleton(s1name));
EXPECT_TRUE(world->getSkeleton(s1name) == NULL);

// Remove all the skeletons
world->removeAllSkeletons();
EXPECT_EQ(world->getNumSkeletons(), 0);
for (int i = 0; i < nSteps; ++i)
world->step();

EXPECT_FALSE(skeleton3 == world->getSkeleton(s3name));
EXPECT_TRUE(world->getSkeleton(s3name) == NULL);

EXPECT_FALSE(skeleton4 == world->getSkeleton(s4name));
EXPECT_TRUE(world->getSkeleton(s4name) == NULL);

delete world;
}

Expand Down