1# Copyright 2024 The Android Open Source Project
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"""Tests for imu_processing_utils."""
15
16import numpy as np
17import unittest
18
19import imu_processing_utils
20
21
22class ImuProcessingUtilsTest(unittest.TestCase):
23  """Unit tests for this module."""
24
25  def test_calc_rv_drift(self):
26    """Unit test for rotation vector drift calculation method."""
27    # Create test vectors
28    a = [-1, 0, 1, -2]
29    b = [-179, 180, 179, -180, -178]
30    c = [179, 180, -179, -180, 178]
31    d = [179.0, 180.0, -179.0, -180.0, 178.0]
32
33    a_drift = [0, 1, 2, -1]
34    b_drift = [0, -1, -2, -1, 1]
35    c_drift = [0, 1, 2, 1, -1]
36    d_drift = [0.0, 1.0, 2.0, 1.0, -1.0]
37
38    # Check drift
39    self.assertEqual(imu_processing_utils.calc_rv_drift(a), a_drift,
40                     'a_drift is incorrect')
41    self.assertEqual(imu_processing_utils.calc_rv_drift(b), b_drift,
42                     'b_drift is incorrect')
43    self.assertEqual(imu_processing_utils.calc_rv_drift(c), c_drift,
44                     'c_drift is incorrect')
45    self.assertTrue(np.allclose(imu_processing_utils.calc_rv_drift(d), d_drift),
46                    'd_drift is incorrect')
47
48
49if __name__ == '__main__':
50  unittest.main()
51