Skip to content

Commit

Permalink
Fix for issue #876
Browse files Browse the repository at this point in the history
  • Loading branch information
nkoenig committed Oct 7, 2013
1 parent ce60bf6 commit 87ccca6
Showing 3 changed files with 66 additions and 0 deletions.
3 changes: 3 additions & 0 deletions gazebo/physics/World.cc
Original file line number Diff line number Diff line change
@@ -914,6 +914,9 @@ void World::Reset()
{
boost::recursive_mutex::scoped_lock(*this->worldUpdateMutex);

math::Rand::SetSeed(math::Rand::GetSeed());
this->physicsEngine->SetSeed(math::Rand::GetSeed());

this->ResetTime();
this->ResetEntities(Base::BASE);
for (std::vector<WorldPluginPtr>::iterator iter = this->plugins.begin();
62 changes: 62 additions & 0 deletions test/regression/876_random_number_generator.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright 2013 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

#include "ServerFixture.hh"
#include "gazebo/math/Rand.hh"

using namespace gazebo;

class Issue876Test : public ServerFixture
{
};


/////////////////////////////////////////////////
// \brief Test for issue #876
TEST_F(Issue876Test, Reset)
{
Load("worlds/empty.world");
physics::WorldPtr world = physics::get_world("default");
ASSERT_TRUE(world);

int sampleCount = 500;

std::vector<int> num;
for (int i = 0; i < sampleCount; ++i)
num.push_back(math::Rand::GetIntUniform(-10, 10));

for (int j = 0; j < 1000; ++j)
{
world->Reset();

std::vector<int> numReset;
for (int i = 0; i < sampleCount; ++i)
numReset.push_back(math::Rand::GetIntUniform(-10, 10));

// Using ASSERT_EQ to prevent spamming of similar errors.
for (int i = 0; i < sampleCount; ++i)
ASSERT_EQ(num[i], numReset[i]);
}
}

/////////////////////////////////////////////////
/// Main
int main(int argc, char **argv)
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
1 change: 1 addition & 0 deletions test/regression/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@ endif()

set(tests
846_typo_in_camera.cc
876_random_number_generator.cc
)

set (GZ_BUILD_TESTS_EXTRA_EXE_SRCS

0 comments on commit 87ccca6

Please sign in to comment.