|
| 1 | +# Copyright 2019 The dm_control Authors. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | +# ============================================================================ |
| 15 | + |
| 16 | +"""Tests for index.""" |
| 17 | +from __future__ import absolute_import |
| 18 | +from __future__ import division |
| 19 | +from __future__ import print_function |
| 20 | + |
| 21 | +import math |
| 22 | +from absl.testing import absltest |
| 23 | +from absl.testing import parameterized |
| 24 | +from dm_control.mujoco import math as mjmath |
| 25 | +import numpy as np |
| 26 | + |
| 27 | + |
| 28 | +class MathTest(parameterized.TestCase): |
| 29 | + |
| 30 | + def testQuatProd(self): |
| 31 | + np.testing.assert_allclose( |
| 32 | + mjmath.mj_quatprod([0., 1., 0., 0.], [0., 0., 1., 0.]), |
| 33 | + [0., 0., 0., 1.]) |
| 34 | + np.testing.assert_allclose( |
| 35 | + mjmath.mj_quatprod([0., 0., 1., 0.], [0., 0., 0., 1.]), |
| 36 | + [0., 1., 0., 0.]) |
| 37 | + np.testing.assert_allclose( |
| 38 | + mjmath.mj_quatprod([0., 0., 0., 1.], [0., 1., 0., 0.]), |
| 39 | + [0., 0., 1., 0.]) |
| 40 | + |
| 41 | + def testQuat2Vel(self): |
| 42 | + np.testing.assert_allclose( |
| 43 | + mjmath.mj_quat2vel([0., 1., 0., 0.], 0.1), [math.pi / 0.1, 0., 0.]) |
| 44 | + |
| 45 | + def testQuatNeg(self): |
| 46 | + np.testing.assert_allclose( |
| 47 | + mjmath.mj_quatneg([math.sqrt(0.5), math.sqrt(0.5), 0., 0.]), |
| 48 | + [math.sqrt(0.5), -math.sqrt(0.5), 0., 0.]) |
| 49 | + |
| 50 | + def testQuatDiff(self): |
| 51 | + np.testing.assert_allclose( |
| 52 | + mjmath.mj_quatdiff([0., 1., 0., 0.], [0., 0., 1., 0.]), |
| 53 | + [0., 0., 0., -1.]) |
| 54 | + |
| 55 | + def testEuler2Quat(self): |
| 56 | + np.testing.assert_allclose( |
| 57 | + mjmath.euler2quat(0., 0., 0.), [1., 0., 0., 0.]) |
| 58 | + |
| 59 | + |
| 60 | +if __name__ == '__main__': |
| 61 | + absltest.main() |
0 commit comments