MCPcopy Create free account
hub / github.com/google-deepmind/dm_control / testSameness

Method testSameness

dm_control/mjcf/element_test.py:228–274  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

226 self.assertIsNone(mujoco.worldbody.find('body', 'foo'))
227
228 def testSameness(self):
229 mujoco = element.RootElement(model='test')
230
231 body_1 = mujoco.worldbody.add('body', pos=[0, 1, 2], quat=[0, 1, 0, 1])
232 site_1 = body_1.add('site', pos=[0, 1, 2], quat=[0, 1, 0, 1])
233 geom_1 = body_1.add('geom', pos=[0, 1, 2], quat=[0, 1, 0, 1])
234
235 for elem in (body_1, site_1, geom_1):
236 self.assertIsSame(elem, elem)
237
238 # strict ordering NOT required: adding geom and site is different order
239 body_2 = mujoco.worldbody.add('body', pos=[0, 1, 2], quat=[0, 1, 0, 1])
240 geom_2 = body_2.add('geom', pos=[0, 1, 2], quat=[0, 1, 0, 1])
241 site_2 = body_2.add('site', pos=[0, 1, 2], quat=[0, 1, 0, 1])
242
243 elems_1 = (body_1, site_1, geom_1)
244 elems_2 = (body_2, site_2, geom_2)
245 for i, j in itertools.product(range(len(elems_1)), range(len(elems_2))):
246 if i == j:
247 self.assertIsSame(elems_1[i], elems_2[j])
248 else:
249 self.assertIsNotSame(elems_1[i], elems_2[j])
250
251 # on-demand child
252 body_1.add('inertial', pos=[0, 0, 0], mass=1)
253 self.assertIsNotSame(body_1, body_2)
254
255 body_2.add('inertial', pos=[0, 0, 0], mass=1)
256 self.assertIsSame(body_1, body_2)
257
258 # different number of children
259 subbody_1 = body_1.add('body', pos=[0, 0, 1])
260 self.assertIsNotSame(body_1, body_2)
261
262 # attribute mismatch
263 subbody_2 = body_2.add('body')
264 self.assertIsNotSame(subbody_1, subbody_2)
265 self.assertIsNotSame(body_1, body_2)
266
267 subbody_2.pos = [0, 0, 1]
268 self.assertIsSame(subbody_1, subbody_2)
269 self.assertIsSame(body_1, body_2)
270
271 # grandchild attribute mismatch
272 subbody_1.add('joint', type='hinge')
273 subbody_2.add('joint', type='ball')
274 self.assertIsNotSame(body_1, body_2)
275
276 def testTendonSameness(self):
277 mujoco = element.RootElement(model='test')

Callers

nothing calls this directly

Calls 3

assertIsSameMethod · 0.95
assertIsNotSameMethod · 0.95
addMethod · 0.45

Tested by

no test coverage detected