//============================================================================== TEST(FileInfoWorld, Basic) { const size_t numFrames = 100; const std::string fileName = "testWorld.txt"; double tol = 1e-6; bool result = false; FileInfoWorld worldFile; WorldPtr world = SkelParser::readWorld( DART_DATA_PATH"/skel/test/file_info_world_test.skel"); EXPECT_TRUE(world != nullptr); Recording* recording1 = nullptr; Recording* recording2 = nullptr; // Do some simulation with recording for (size_t i = 0; i < numFrames; ++i) { world->step(); world->bake(); } recording1 = world->getRecording(); EXPECT_TRUE(recording1 != nullptr); // Save the recording to a file result = worldFile.saveFile(fileName.c_str(), world->getRecording()); EXPECT_TRUE(result); // Load the file result = worldFile.loadFile(fileName.c_str()); EXPECT_TRUE(result); recording2 = worldFile.getRecording(); EXPECT_TRUE(recording2 != nullptr); // Check number of frames EXPECT_EQ(recording1->getNumFrames(), (int)numFrames); EXPECT_EQ(recording2->getNumFrames(), (int)numFrames); // Check number of skeletons size_t numSkeletons = recording1->getNumSkeletons(); EXPECT_EQ(recording1->getNumSkeletons(), recording2->getNumSkeletons()); // Check number of dofs of the skeletons for (size_t i = 0; i < numSkeletons; ++i) EXPECT_EQ(recording1->getNumDofs(i), recording2->getNumDofs(i)); // Check generalized positions and contact info for (size_t i = 0; i < numFrames; ++i) { // Check generalized positions for (size_t j = 0; j < numSkeletons; ++j) { size_t dofs = recording1->getNumDofs(j); for (size_t k = 0; k < dofs; ++k) { EXPECT_NEAR(recording1->getGenCoord(i, j, k), recording2->getGenCoord(i, j, k), tol); } } // Check contact info tol = 1e-3; size_t numContacts = recording1->getNumContacts(i); EXPECT_EQ(recording1->getNumContacts(i), recording2->getNumContacts(i)); for (size_t j = 0; j < numContacts; ++j) { for (size_t k = 0; k < 3; ++k) { EXPECT_NEAR(recording1->getContactForce(i, j)[k], recording2->getContactForce(i, j)[k], tol); EXPECT_NEAR(recording1->getContactPoint(i, j)[k], recording2->getContactPoint(i, j)[k], tol); } } } }