test_math.py
Go to the documentation of this file.
1 #!/usr/env python
2 
3 import unittest, sys, os
4 sys.path.insert(0, os.path.abspath(".."))
5 from gnsstk.test_utils import args, assertSequenceAlmostEqual, run_unit_tests, vec_to_list
6 
7 import gnsstk
8 
9 
10 class TestTriple(unittest.TestCase):
11 
12  def test_constructor(self):
13  a = gnsstk.Triple(1, 2, 3)
14  self.assertSequenceEqual([1, 2, 3], vec_to_list(a))
15 
16  def test_to_vector(self):
17  a = gnsstk.Triple(2, 4, 6)
18 
19  a_vector = a.toVector()
20  self.assertSequenceEqual([2, 4, 6], vec_to_list(a_vector))
21 
22  a_std_vector = a.toStdVector()
23  self.assertSequenceEqual([2, 4, 6], vec_to_list(a_std_vector))
24 
25  def test_products(self):
26  a = gnsstk.Triple(1.5, 2.3, 3.6)
27  b = gnsstk.Triple(3.4, 6.8, 4.5)
28 
29  dot_product = a.dot(b)
30  self.assertAlmostEqual(36.94, dot_product)
31 
32  cross_product = a.cross(b)
33  assertSequenceAlmostEqual(self, [-14.13, 5.49, 2.38], vec_to_list(cross_product))
34 
35  def test_magnitude(self):
36  a = gnsstk.Triple(1.5, 2.3, 3.6)
37  self.assertAlmostEqual(4.52769256, a.mag())
38 
40  a = gnsstk.Triple(1.5, 2.3, 3.6)
41  b = gnsstk.Triple(3.4, 6.8, 4.5)
42 
43  self.assertAlmostEqual(0.92349278, a.cosVector(b))
44  self.assertAlmostEqual(4.96689037, a.slantRange(b))
45  self.assertAlmostEqual(46.97353420, a.elvAngle(b))
46  self.assertAlmostEqual(165.18222367, a.azAngle(b))
47 
48  def test_rotation(self):
49  a = gnsstk.Triple(22.5, -56, 30)
50 
51  # 35 deg about the x-axis
52  a = a.R1(35)
53  assertSequenceAlmostEqual(self, [22.5, -28.66522138, 56.69484176], vec_to_list(a))
54 
55  # 24 deg about the y-axis
56  a = a.R2(24)
57  assertSequenceAlmostEqual(self, [-2.50509682, -28.66522138, 60.94488963], vec_to_list(a))
58 
59  # -89 deg about the z-axis
60  a = a.R3(-89)
61  assertSequenceAlmostEqual(self, [28.61713556, -3.00499237, 60.94488963], vec_to_list(a))
62 
64  a = gnsstk.Triple(2.3, 4.5, 3.6)
65  b = gnsstk.Triple(-9.0, 34.4, 23.2)
66 
67  c = a - b
68  assertSequenceAlmostEqual(self, [11.3, -29.9, -19.6], vec_to_list(c))
69 
70  c = c + b
71  assertSequenceAlmostEqual(self, [2.3, 4.5, 3.6], vec_to_list(c))
72 
73  # The `==` is element wise comparison
74  self.assertFalse(gnsstk.Triple(1, 2, 3) == gnsstk.Triple(3, 2, 1))
75  self.assertTrue(gnsstk.Triple(1, 2, 3) == gnsstk.Triple(1, 2, 3))
76 
77  def test_scale(self):
78  a = gnsstk.Triple(2.3, 4.5, 3.6)
79  a = a.scale(4.5)
80 
81  assertSequenceAlmostEqual(self, [10.35, 20.25, 16.2], vec_to_list(a))
82 
83  def test_size(self):
84  a = gnsstk.Triple(2.3, 4.5, 3.6)
85 
86  # Triple should always be size 3
87  self.assertEqual(3, a.size())
88  self.assertEqual(3, len(a))
89 
90 
91 if __name__ == "__main__":
93 
tests.test_math.TestTriple.test_products
def test_products(self)
Definition: test_math.py:25
tests.test_math.TestTriple
Definition: test_math.py:10
tests.test_math.TestTriple.test_rotation
def test_rotation(self)
Definition: test_math.py:48
tests.test_math.TestTriple.test_scale
def test_scale(self)
Definition: test_math.py:77
gnsstk::Triple
Definition: Triple.hpp:68
test_utils.vec_to_list
def vec_to_list(s)
Definition: test_utils.py:88
test_utils.assertSequenceAlmostEqual
def assertSequenceAlmostEqual(test_case, l1, l2, **kwargs)
Definition: test_utils.py:76
tests.test_math.TestTriple.test_elementwise_ops
def test_elementwise_ops(self)
Definition: test_math.py:63
tests.test_math.TestTriple.test_magnitude
def test_magnitude(self)
Definition: test_math.py:35
tests.test_math.TestTriple.test_size
def test_size(self)
Definition: test_math.py:83
tests.test_math.TestTriple.test_two_vector_computations
def test_two_vector_computations(self)
Definition: test_math.py:39
tests.test_math.TestTriple.test_to_vector
def test_to_vector(self)
Definition: test_math.py:16
test_utils.run_unit_tests
def run_unit_tests()
Definition: test_utils.py:51
tests.test_math.TestTriple.test_constructor
def test_constructor(self)
Definition: test_math.py:12


gnsstk
Author(s):
autogenerated on Wed Oct 25 2023 02:40:41