1
-
2
1
import unittest
3
2
import numpy .testing as nt
4
3
import numpy as np
@@ -55,8 +54,8 @@ def test_velocity(self):
55
54
56
55
s = str (a )
57
56
self .assertIsInstance (s , str )
58
- self .assertEqual (s .count (' \n ' ), 0 )
59
- self .assertTrue (s .startswith (' SpatialVelocity' ))
57
+ self .assertEqual (s .count (" \n " ), 0 )
58
+ self .assertTrue (s .startswith (" SpatialVelocity" ))
60
59
61
60
r = np .random .rand (6 , 10 )
62
61
a = SpatialVelocity (r )
@@ -70,11 +69,11 @@ def test_velocity(self):
70
69
self .assertIsInstance (b , SpatialVector )
71
70
self .assertIsInstance (b , SpatialM6 )
72
71
self .assertEqual (len (b ), 1 )
73
- self .assertTrue (all (b .A == r [:,3 ]))
72
+ self .assertTrue (all (b .A == r [:, 3 ]))
74
73
75
74
s = str (a )
76
75
self .assertIsInstance (s , str )
77
- self .assertEqual (s .count (' \n ' ), 9 )
76
+ self .assertEqual (s .count (" \n " ), 9 )
78
77
79
78
def test_acceleration (self ):
80
79
a = SpatialAcceleration ([1 , 2 , 3 , 4 , 5 , 6 ])
@@ -93,8 +92,8 @@ def test_acceleration(self):
93
92
94
93
s = str (a )
95
94
self .assertIsInstance (s , str )
96
- self .assertEqual (s .count (' \n ' ), 0 )
97
- self .assertTrue (s .startswith (' SpatialAcceleration' ))
95
+ self .assertEqual (s .count (" \n " ), 0 )
96
+ self .assertTrue (s .startswith (" SpatialAcceleration" ))
98
97
99
98
r = np .random .rand (6 , 10 )
100
99
a = SpatialAcceleration (r )
@@ -108,14 +107,12 @@ def test_acceleration(self):
108
107
self .assertIsInstance (b , SpatialVector )
109
108
self .assertIsInstance (b , SpatialM6 )
110
109
self .assertEqual (len (b ), 1 )
111
- self .assertTrue (all (b .A == r [:,3 ]))
110
+ self .assertTrue (all (b .A == r [:, 3 ]))
112
111
113
112
s = str (a )
114
113
self .assertIsInstance (s , str )
115
114
116
-
117
115
def test_force (self ):
118
-
119
116
a = SpatialForce ([1 , 2 , 3 , 4 , 5 , 6 ])
120
117
self .assertIsInstance (a , SpatialForce )
121
118
self .assertIsInstance (a , SpatialVector )
@@ -132,8 +129,8 @@ def test_force(self):
132
129
133
130
s = str (a )
134
131
self .assertIsInstance (s , str )
135
- self .assertEqual (s .count (' \n ' ), 0 )
136
- self .assertTrue (s .startswith (' SpatialForce' ))
132
+ self .assertEqual (s .count (" \n " ), 0 )
133
+ self .assertTrue (s .startswith (" SpatialForce" ))
137
134
138
135
r = np .random .rand (6 , 10 )
139
136
a = SpatialForce (r )
@@ -153,7 +150,6 @@ def test_force(self):
153
150
self .assertIsInstance (s , str )
154
151
155
152
def test_momentum (self ):
156
-
157
153
a = SpatialMomentum ([1 , 2 , 3 , 4 , 5 , 6 ])
158
154
self .assertIsInstance (a , SpatialMomentum )
159
155
self .assertIsInstance (a , SpatialVector )
@@ -170,8 +166,8 @@ def test_momentum(self):
170
166
171
167
s = str (a )
172
168
self .assertIsInstance (s , str )
173
- self .assertEqual (s .count (' \n ' ), 0 )
174
- self .assertTrue (s .startswith (' SpatialMomentum' ))
169
+ self .assertEqual (s .count (" \n " ), 0 )
170
+ self .assertTrue (s .startswith (" SpatialMomentum" ))
175
171
176
172
r = np .random .rand (6 , 10 )
177
173
a = SpatialMomentum (r )
@@ -190,9 +186,7 @@ def test_momentum(self):
190
186
s = str (a )
191
187
self .assertIsInstance (s , str )
192
188
193
-
194
189
def test_arith (self ):
195
-
196
190
# just test SpatialVelocity since all types derive from same superclass
197
191
198
192
r1 = np .r_ [1 , 2 , 3 , 4 , 5 , 6 ]
@@ -206,8 +200,26 @@ def test_arith(self):
206
200
207
201
def test_inertia (self ):
208
202
# constructor
203
+ i0 = SpatialInertia ()
204
+ nt .assert_equal (i0 .A , np .zeros ((6 , 6 )))
205
+
206
+ i1 = SpatialInertia (np .eye (6 , 6 ))
207
+ nt .assert_equal (i1 .A , np .eye (6 , 6 ))
208
+
209
+ i2 = SpatialInertia (m = 1 , r = (1 , 2 , 3 ))
210
+ nt .assert_almost_equal (i2 .A , i2 .A .T )
211
+
212
+ i3 = SpatialInertia (m = 1 , r = (1 , 2 , 3 ), I = np .ones ((3 , 3 )))
213
+ nt .assert_almost_equal (i3 .A , i3 .A .T )
214
+
209
215
# addition
210
- pass
216
+ m_a , m_b = 1.1 , 2.2
217
+ r = (1 , 2 , 3 )
218
+ i4a , i4b = SpatialInertia (m = m_a , r = r ), SpatialInertia (m = m_b , r = r )
219
+ nt .assert_almost_equal ((i4a + i4b ).A , SpatialInertia (m = m_a + m_b , r = r ).A )
220
+
221
+ # isvalid - note this method is very barebone, to be improved
222
+ self .assertTrue (SpatialInertia ().isvalid (np .ones ((6 , 6 )), check = False ))
211
223
212
224
def test_products (self ):
213
225
# v x v = a *, v x F6 = a
@@ -218,6 +230,5 @@ def test_products(self):
218
230
219
231
220
232
# ---------------------------------------------------------------------------------------#
221
- if __name__ == '__main__' :
222
-
223
- unittest .main ()
233
+ if __name__ == "__main__" :
234
+ unittest .main ()
0 commit comments