Skip to content

Commit

Permalink
Add unit tests for each DCM to q algorithm.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mayitzin committed Sep 13, 2024
1 parent 7de7413 commit 595ab98
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions tests/test_dcm.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import ahrs

GENERATOR = np.random.default_rng(42)
THRESHOLD = 0.1
THRESHOLD = 1e-6

class TestDCM(unittest.TestCase):
def setUp(self) -> None:
Expand Down Expand Up @@ -55,11 +55,32 @@ def test_wrong_quaternion(self):
self.assertRaises(ValueError, ahrs.DCM, q=np.random.random(5))
self.assertRaises(ValueError, ahrs.DCM, q=np.random.random((5, 3)))

def test_default_method_dcm_to_q(self):
def test_dcm_to_q_default(self):
self.assertLessEqual(ahrs.utils.metrics.qad(self.q, self.R1.to_quaternion()), THRESHOLD)

def test_chiavereini_method_dcm_to_q(self):
def test_dcm_to_q_chiavereini(self):
self.assertLessEqual(ahrs.utils.metrics.qad(self.q, self.R1.to_quaternion(method='chiaverini')), THRESHOLD)

def test_dcm_to_q_hughes(self):
self.assertLessEqual(ahrs.utils.metrics.qad(self.q, self.R1.to_quaternion(method='hughes')), THRESHOLD)

def test_dcm_to_q_itzhack(self):
self.assertLessEqual(ahrs.utils.metrics.qad(self.q, self.R1.to_quaternion(method='itzhack')), THRESHOLD)

def test_dcm_to_q_itzhack_v1(self):
self.assertLessEqual(ahrs.utils.metrics.qad(self.q, self.R1.to_quaternion(method='itzhack', version=1)), THRESHOLD)

def test_dcm_to_q_itzhack_v2(self):
self.assertLessEqual(ahrs.utils.metrics.qad(self.q, self.R1.to_quaternion(method='itzhack', version=2)), THRESHOLD)

def test_dcm_to_q_itzhack_v3(self):
self.assertLessEqual(ahrs.utils.metrics.qad(self.q, self.R1.to_quaternion(method='itzhack', version=3)), THRESHOLD)

def test_dcm_to_q_sarabandi(self):
self.assertLessEqual(ahrs.utils.metrics.qad(self.q, self.R1.to_quaternion(method='sarabandi')), THRESHOLD)

def test_dcm_to_q_shepperd(self):
self.assertLessEqual(ahrs.utils.metrics.qad(self.q, self.R1.to_quaternion(method='shepperd')), THRESHOLD)

if __name__ == "__main__":
unittest.main()

0 comments on commit 595ab98

Please sign in to comment.