11
11
def qcompare (x , y ):
12
12
if isinstance (x , Quaternion ):
13
13
x = x .vec
14
+ elif isinstance (x , SMPose ):
15
+ x = x .A
14
16
if isinstance (y , Quaternion ):
15
17
y = y .vec
18
+ elif isinstance (y , SMPose ):
19
+ y = y .A
16
20
nt .assert_array_almost_equal (x , y )
17
21
18
22
# straight port of the MATLAB unit tests
@@ -120,13 +124,23 @@ def test_concat(self):
120
124
self .assertIsInstance (uu , UnitQuaternion )
121
125
self .assertEqual (len (uu ), 4 )
122
126
123
- def test_convert_string (self ):
124
- # char
127
+ def test_string (self ):
125
128
126
129
u = UnitQuaternion ()
127
130
128
131
s = str (u )
129
132
self .assertIsInstance (s , str )
133
+ self .assertTrue (s .endswith (' >>' ))
134
+ self .assertEqual (s .count ('\n ' ), 0 )
135
+
136
+ q = UnitQuaternion .Rx ([0.3 , 0.4 , 0.5 ])
137
+ s = str (q )
138
+ self .assertIsInstance (s , str )
139
+ self .assertEqual (s .count ('\n ' ), 2 )
140
+
141
+ def test_properties (self ):
142
+
143
+ u = UnitQuaternion ()
130
144
131
145
# s,v
132
146
nt .assert_array_almost_equal (UnitQuaternion ([1 , 0 , 0 , 0 ]).s , 1 )
@@ -142,17 +156,20 @@ def test_convert_string(self):
142
156
nt .assert_array_almost_equal (UnitQuaternion ([0 , 0 , 0 , 1 ]).v , [0 , 0 , 1 ])
143
157
144
158
# R,T
145
- nt .assert_array_almost_equal (u .R , eye (3 ))
159
+ nt .assert_array_almost_equal (u .R , np . eye (3 ))
146
160
147
161
nt .assert_array_almost_equal (UnitQuaternion (rotx (pi / 2 )).R , rotx (pi / 2 ))
148
162
nt .assert_array_almost_equal (UnitQuaternion (roty (- pi / 2 )).R , roty (- pi / 2 ))
149
163
nt .assert_array_almost_equal (UnitQuaternion (rotz (pi )).R , rotz (pi ))
150
164
151
- nt .assert_array_almost_equal (UnitQuaternion (rotx (pi / 2 )).T , trotx (pi / 2 ))
152
- nt .assert_array_almost_equal (UnitQuaternion (roty (- pi / 2 )).T , troty (- pi / 2 ))
153
- nt .assert_array_almost_equal (UnitQuaternion (rotz (pi )).T , trotz (pi ))
165
+ qcompare (UnitQuaternion (rotx (pi / 2 )).SO3 (), SO3 .Rx (pi / 2 ))
166
+ qcompare (UnitQuaternion (roty (- pi / 2 )).SO3 (), SO3 .Ry (- pi / 2 ))
167
+ qcompare (UnitQuaternion (rotz (pi )).SO3 (), SO3 .Rz (pi ))
168
+
169
+ qcompare (UnitQuaternion (rotx (pi / 2 )).SE3 (), SE3 .Rx (pi / 2 ))
170
+ qcompare (UnitQuaternion (roty (- pi / 2 )).SE3 (), SE3 .Ry (- pi / 2 ))
171
+ qcompare (UnitQuaternion (rotz (pi )).SE3 (), SE3 .Rz (pi ))
154
172
155
- nt .assert_array_almost_equal (UnitQuaternion .q2r (u .vec ), eye (3 , 3 ))
156
173
157
174
def test_staticconstructors (self ):
158
175
# rotation primitives
@@ -609,6 +626,21 @@ def test_constructor(self):
609
626
# tc.verifyError( @() Quaternion(2), 'SMTB:Quaternion:badarg')
610
627
# tc.verifyError( @() Quaternion([1, 2, 3]), 'SMTB:Quaternion:badarg')
611
628
629
+ def test_string (self ):
630
+
631
+ u = Quaternion ()
632
+
633
+ s = str (u )
634
+ self .assertIsInstance (s , str )
635
+ self .assertTrue (s .endswith (' >' ))
636
+ self .assertEqual (s .count ('\n ' ), 0 )
637
+ self .assertEqual (len (s ), 41 )
638
+
639
+ q = Quaternion ([u , u , u ])
640
+ s = str (q )
641
+ self .assertIsInstance (s , str )
642
+ self .assertEqual (s .count ('\n ' ), 2 )
643
+
612
644
def test_properties (self ):
613
645
614
646
q = Quaternion ([1 , 2 , 3 , 4 ])
@@ -627,29 +659,7 @@ def log_test_exp(self):
627
659
#nt.assert_array_almost_equal(log(exp(q1)), q1)
628
660
#nt.assert_array_almost_equal(log(exp(q2)), q2)
629
661
630
- def test_char (self ):
631
662
632
- # char
633
- q = Quaternion ()
634
-
635
- s = str (q )
636
- self .assertTrue (isinstance (s , str ))
637
- self .assertEqual (len (s ), 42 )
638
-
639
- s = str (Quaternion ([q , q , q ]))
640
- self .assertEqual (len (s ), 126 )
641
- self .assertEqual (s .count ('\n ' ), 3 )
642
-
643
- # symbolic display
644
- # syms s x y z real
645
- # q = Quaternion([s x y z])
646
- # s = char( q )
647
- # tc.verifyTrue( ischar(s))
648
- # nt.assert_array_almost_equal(size(s,1), 1)
649
-
650
- # s = char( [q q q] )
651
- # tc.verifyTrue( ischar(s))
652
- # nt.assert_array_almost_equal(size(s,1), 3)
653
663
654
664
def test_concat (self ):
655
665
u = Quaternion ()
0 commit comments