6
6
import numpy as np
7
7
import pytest
8
8
9
- from control import (StateSpace , TransferFunction , bode , common_timebase ,
10
- evalfr , feedback , forced_response , impulse_response ,
11
- isctime , isdtime , rss , sample_system , step_response ,
12
- timebase )
9
+ from control import StateSpace , TransferFunction , feedback , step_response , \
10
+ isdtime , timebase , isctime , sample_system , bode , impulse_response , \
11
+ evalfr , timebaseEqual , forced_response , rss
13
12
14
13
15
14
class TestDiscrete :
@@ -52,21 +51,13 @@ class Tsys:
52
51
53
52
return T
54
53
55
- def testCompatibleTimebases (self , tsys ):
56
- """test that compatible timebases don't throw errors and vice versa"""
57
- common_timebase (tsys .siso_ss1 .dt , tsys .siso_tf1 .dt )
58
- common_timebase (tsys .siso_ss1 .dt , tsys .siso_ss1c .dt )
59
- common_timebase (tsys .siso_ss1d .dt , tsys .siso_ss1 .dt )
60
- common_timebase (tsys .siso_ss1 .dt , tsys .siso_ss1d .dt )
61
- common_timebase (tsys .siso_ss1 .dt , tsys .siso_ss1d .dt )
62
- common_timebase (tsys .siso_ss1d .dt , tsys .siso_ss3d .dt )
63
- common_timebase (tsys .siso_ss3d .dt , tsys .siso_ss1d .dt )
64
- with pytest .raises (ValueError ):
65
- # cont + discrete
66
- common_timebase (tsys .siso_ss1d .dt , tsys .siso_ss1c .dt )
67
- with pytest .raises (ValueError ):
68
- # incompatible discrete
69
- common_timebase (tsys .siso_ss1d .dt , tsys .siso_ss2d .dt )
54
+ def testTimebaseEqual (self , tsys ):
55
+ """Test for equal timebases and not so equal ones"""
56
+ assert timebaseEqual (tsys .siso_ss1 , tsys .siso_tf1 )
57
+ assert timebaseEqual (tsys .siso_ss1 , tsys .siso_ss1c )
58
+ assert not timebaseEqual (tsys .siso_ss1d , tsys .siso_ss1c )
59
+ assert not timebaseEqual (tsys .siso_ss1d , tsys .siso_ss2d )
60
+ assert not timebaseEqual (tsys .siso_ss1d , tsys .siso_ss3d )
70
61
71
62
def testSystemInitialization (self , tsys ):
72
63
# Check to make sure systems are discrete time with proper variables
@@ -84,18 +75,6 @@ def testSystemInitialization(self, tsys):
84
75
assert tsys .siso_tf2d .dt == 0.2
85
76
assert tsys .siso_tf3d .dt is True
86
77
87
- # keyword argument check
88
- # dynamic systems
89
- assert TransferFunction (1 , [1 , 1 ], dt = 0.1 ).dt == 0.1
90
- assert TransferFunction (1 , [1 , 1 ], 0.1 ).dt == 0.1
91
- assert StateSpace (1 ,1 ,1 ,1 , dt = 0.1 ).dt == 0.1
92
- assert StateSpace (1 ,1 ,1 ,1 , 0.1 ).dt == 0.1
93
- # static gain system, dt argument should still override default dt
94
- assert TransferFunction (1 , [1 ,], dt = 0.1 ).dt == 0.1
95
- assert TransferFunction (1 , [1 ,], 0.1 ).dt == 0.1
96
- assert StateSpace (0 ,0 ,1 ,1 , dt = 0.1 ).dt == 0.1
97
- assert StateSpace (0 ,0 ,1 ,1 , 0.1 ).dt == 0.1
98
-
99
78
def testCopyConstructor (self , tsys ):
100
79
for sys in (tsys .siso_ss1 , tsys .siso_ss1c , tsys .siso_ss1d ):
101
80
newsys = StateSpace (sys )
@@ -135,7 +114,6 @@ def test_timebase_conversions(self, tsys):
135
114
assert timebase (tf1 * tf2 ) == timebase (tf2 )
136
115
assert timebase (tf1 * tf3 ) == timebase (tf3 )
137
116
assert timebase (tf1 * tf4 ) == timebase (tf4 )
138
- assert timebase (tf3 * tf4 ) == timebase (tf4 )
139
117
assert timebase (tf2 * tf1 ) == timebase (tf2 )
140
118
assert timebase (tf3 * tf1 ) == timebase (tf3 )
141
119
assert timebase (tf4 * tf1 ) == timebase (tf4 )
@@ -150,36 +128,33 @@ def test_timebase_conversions(self, tsys):
150
128
151
129
# Make sure discrete time without sampling is converted correctly
152
130
assert timebase (tf3 * tf3 ) == timebase (tf3 )
153
- assert timebase (tf3 * tf4 ) == timebase (tf4 )
154
131
assert timebase (tf3 + tf3 ) == timebase (tf3 )
155
- assert timebase (tf3 + tf4 ) == timebase (tf4 )
156
132
assert timebase (feedback (tf3 , tf3 )) == timebase (tf3 )
157
- assert timebase (feedback (tf3 , tf4 )) == timebase (tf4 )
158
133
159
134
# Make sure all other combinations are errors
160
- with pytest .raises (ValueError , match = "incompatible timebases " ):
135
+ with pytest .raises (ValueError , match = "different sampling times " ):
161
136
tf2 * tf3
162
- with pytest .raises (ValueError , match = "incompatible timebases " ):
137
+ with pytest .raises (ValueError , match = "different sampling times " ):
163
138
tf3 * tf2
164
- with pytest .raises (ValueError , match = "incompatible timebases " ):
139
+ with pytest .raises (ValueError , match = "different sampling times " ):
165
140
tf2 * tf4
166
- with pytest .raises (ValueError , match = "incompatible timebases " ):
141
+ with pytest .raises (ValueError , match = "different sampling times " ):
167
142
tf4 * tf2
168
- with pytest .raises (ValueError , match = "incompatible timebases " ):
143
+ with pytest .raises (ValueError , match = "different sampling times " ):
169
144
tf2 + tf3
170
- with pytest .raises (ValueError , match = "incompatible timebases " ):
145
+ with pytest .raises (ValueError , match = "different sampling times " ):
171
146
tf3 + tf2
172
- with pytest .raises (ValueError , match = "incompatible timebases " ):
147
+ with pytest .raises (ValueError , match = "different sampling times " ):
173
148
tf2 + tf4
174
- with pytest .raises (ValueError , match = "incompatible timebases " ):
149
+ with pytest .raises (ValueError , match = "different sampling times " ):
175
150
tf4 + tf2
176
- with pytest .raises (ValueError , match = "incompatible timebases " ):
151
+ with pytest .raises (ValueError , match = "different sampling times " ):
177
152
feedback (tf2 , tf3 )
178
- with pytest .raises (ValueError , match = "incompatible timebases " ):
153
+ with pytest .raises (ValueError , match = "different sampling times " ):
179
154
feedback (tf3 , tf2 )
180
- with pytest .raises (ValueError , match = "incompatible timebases " ):
155
+ with pytest .raises (ValueError , match = "different sampling times " ):
181
156
feedback (tf2 , tf4 )
182
- with pytest .raises (ValueError , match = "incompatible timebases " ):
157
+ with pytest .raises (ValueError , match = "different sampling times " ):
183
158
feedback (tf4 , tf2 )
184
159
185
160
def testisdtime (self , tsys ):
@@ -237,7 +212,6 @@ def testAddition(self, tsys):
237
212
sys = tsys .siso_ss1c + tsys .siso_ss1c
238
213
sys = tsys .siso_ss1d + tsys .siso_ss1d
239
214
sys = tsys .siso_ss3d + tsys .siso_ss3d
240
- sys = tsys .siso_ss1d + tsys .siso_ss3d
241
215
242
216
with pytest .raises (ValueError ):
243
217
StateSpace .__add__ (tsys .mimo_ss1c , tsys .mimo_ss1d )
@@ -254,7 +228,6 @@ def testAddition(self, tsys):
254
228
sys = tsys .siso_tf1c + tsys .siso_tf1c
255
229
sys = tsys .siso_tf1d + tsys .siso_tf1d
256
230
sys = tsys .siso_tf2d + tsys .siso_tf2d
257
- sys = tsys .siso_tf1d + tsys .siso_tf3d
258
231
259
232
with pytest .raises (ValueError ):
260
233
TransferFunction .__add__ (tsys .siso_tf1c , tsys .siso_tf1d )
@@ -279,7 +252,6 @@ def testMultiplication(self, tsys):
279
252
sys = tsys .siso_ss1d * tsys .siso_ss1
280
253
sys = tsys .siso_ss1c * tsys .siso_ss1c
281
254
sys = tsys .siso_ss1d * tsys .siso_ss1d
282
- sys = tsys .siso_ss1d * tsys .siso_ss3d
283
255
284
256
with pytest .raises (ValueError ):
285
257
StateSpace .__mul__ (tsys .mimo_ss1c , tsys .mimo_ss1d )
@@ -295,7 +267,6 @@ def testMultiplication(self, tsys):
295
267
sys = tsys .siso_tf1d * tsys .siso_tf1
296
268
sys = tsys .siso_tf1c * tsys .siso_tf1c
297
269
sys = tsys .siso_tf1d * tsys .siso_tf1d
298
- sys = tsys .siso_tf1d * tsys .siso_tf3d
299
270
300
271
with pytest .raises (ValueError ):
301
272
TransferFunction .__mul__ (tsys .siso_tf1c , tsys .siso_tf1d )
@@ -322,7 +293,6 @@ def testFeedback(self, tsys):
322
293
sys = feedback (tsys .siso_ss1d , tsys .siso_ss1 )
323
294
sys = feedback (tsys .siso_ss1c , tsys .siso_ss1c )
324
295
sys = feedback (tsys .siso_ss1d , tsys .siso_ss1d )
325
- sys = feedback (tsys .siso_ss1d , tsys .siso_ss3d )
326
296
327
297
with pytest .raises (ValueError ):
328
298
feedback (tsys .mimo_ss1c , tsys .mimo_ss1d )
@@ -338,7 +308,6 @@ def testFeedback(self, tsys):
338
308
sys = feedback (tsys .siso_tf1d , tsys .siso_tf1 )
339
309
sys = feedback (tsys .siso_tf1c , tsys .siso_tf1c )
340
310
sys = feedback (tsys .siso_tf1d , tsys .siso_tf1d )
341
- sys = feedback (tsys .siso_tf1d , tsys .siso_tf3d )
342
311
343
312
with pytest .raises (ValueError ):
344
313
feedback (tsys .siso_tf1c , tsys .siso_tf1d )
0 commit comments