Add a test for fusestatic

PiperOrigin-RevId: 519112654
Change-Id: Ic15f9d572c281efb0e0b23b2f99e11a880275851
This commit is contained in:
Nimrod Gileadi
2023-03-24 04:47:22 -07:00
committed by Copybara-Service
parent 15ec12b296
commit 5322291d38
2 changed files with 50 additions and 2 deletions
+1 -1
View File
@@ -13,7 +13,7 @@
# limitations under the License.
mujoco_test(user_model_test)
target_link_libraries(user_model_test fixture gmock)
target_link_libraries(user_model_test fixture gmock absl::str_format)
mujoco_test(user_objects_test)
target_link_libraries(user_objects_test fixture gmock)
+49 -1
View File
@@ -14,11 +14,11 @@
// Tests for user/user_model.cc.
#include <cstddef>
#include <string>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <absl/strings/str_format.h>
#include <mujoco/mjmodel.h>
#include <mujoco/mujoco.h>
#include "test/fixture.h"
@@ -26,7 +26,9 @@
namespace mujoco {
namespace {
using ::testing::DoubleNear;
using ::testing::ElementsAre;
using ::testing::NotNull;
using UserDataTest = MujocoTest;
static std::vector<mjtNum> GetRow(const mjtNum* array, int ncolumn, int row) {
@@ -188,5 +190,51 @@ TEST_F(UserDataTest, AutoNUserSensor) {
mj_deleteModel(m);
}
// ------------- test fusestatic -----------------------------------------------
using FuseStaticTest = MujocoTest;
TEST_F(FuseStaticTest, FuseStaticEquivalent) {
static constexpr char xml_template[] = R"(
<mujoco>
<compiler fusestatic="%s"/>
<worldbody>
<body>
<joint axis="1 0 0"/>
<geom size="0.5" pos="1 0 0"/>
<body>
<geom size="0.5" pos="0 1 0"/>
</body>
</body>
</worldbody>
</mujoco>
)";
std::string fuse = absl::StrFormat(xml_template, "true");
std::string no_fuse = absl::StrFormat(xml_template, "false");
mjModel* m_fuse = LoadModelFromString(fuse.c_str());
mjModel* m_no_fuse = LoadModelFromString(no_fuse.c_str());
ASSERT_THAT(m_fuse, NotNull());
ASSERT_THAT(m_no_fuse, NotNull());
EXPECT_EQ(m_fuse->nbody, 2) << "Expecting a world body and one other body";
EXPECT_EQ(m_no_fuse->nbody, 3) << "Expecting a world body and two others";
mjData* d_fuse = mj_makeData(m_fuse);
mjData* d_no_fuse = mj_makeData(m_no_fuse);
mj_step(m_fuse, d_fuse);
mj_step(m_no_fuse, d_no_fuse);
EXPECT_THAT(d_fuse->qvel[0], DoubleNear(d_no_fuse->qvel[0], 1e-17))
<< "Velocity should be the same after 1 step";
EXPECT_NE(d_fuse->qvel[0], 0);
mj_deleteData(d_fuse);
mj_deleteData(d_no_fuse);
mj_deleteModel(m_fuse);
mj_deleteModel(m_no_fuse);
}
} // namespace
} // namespace mujoco