66import numpy as np
77import pytest
88
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
1312
1413
1514class TestDiscrete :
@@ -52,21 +51,13 @@ class Tsys:
5251
5352 return T
5453
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 )
7061
7162 def testSystemInitialization (self , tsys ):
7263 # Check to make sure systems are discrete time with proper variables
@@ -84,18 +75,6 @@ def testSystemInitialization(self, tsys):
8475 assert tsys .siso_tf2d .dt == 0.2
8576 assert tsys .siso_tf3d .dt is True
8677
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-
9978 def testCopyConstructor (self , tsys ):
10079 for sys in (tsys .siso_ss1 , tsys .siso_ss1c , tsys .siso_ss1d ):
10180 newsys = StateSpace (sys )
@@ -135,7 +114,6 @@ def test_timebase_conversions(self, tsys):
135114 assert timebase (tf1 * tf2 ) == timebase (tf2 )
136115 assert timebase (tf1 * tf3 ) == timebase (tf3 )
137116 assert timebase (tf1 * tf4 ) == timebase (tf4 )
138- assert timebase (tf3 * tf4 ) == timebase (tf4 )
139117 assert timebase (tf2 * tf1 ) == timebase (tf2 )
140118 assert timebase (tf3 * tf1 ) == timebase (tf3 )
141119 assert timebase (tf4 * tf1 ) == timebase (tf4 )
@@ -150,36 +128,33 @@ def test_timebase_conversions(self, tsys):
150128
151129 # Make sure discrete time without sampling is converted correctly
152130 assert timebase (tf3 * tf3 ) == timebase (tf3 )
153- assert timebase (tf3 * tf4 ) == timebase (tf4 )
154131 assert timebase (tf3 + tf3 ) == timebase (tf3 )
155- assert timebase (tf3 + tf4 ) == timebase (tf4 )
156132 assert timebase (feedback (tf3 , tf3 )) == timebase (tf3 )
157- assert timebase (feedback (tf3 , tf4 )) == timebase (tf4 )
158133
159134 # Make sure all other combinations are errors
160- with pytest .raises (ValueError , match = "incompatible timebases " ):
135+ with pytest .raises (ValueError , match = "different sampling times " ):
161136 tf2 * tf3
162- with pytest .raises (ValueError , match = "incompatible timebases " ):
137+ with pytest .raises (ValueError , match = "different sampling times " ):
163138 tf3 * tf2
164- with pytest .raises (ValueError , match = "incompatible timebases " ):
139+ with pytest .raises (ValueError , match = "different sampling times " ):
165140 tf2 * tf4
166- with pytest .raises (ValueError , match = "incompatible timebases " ):
141+ with pytest .raises (ValueError , match = "different sampling times " ):
167142 tf4 * tf2
168- with pytest .raises (ValueError , match = "incompatible timebases " ):
143+ with pytest .raises (ValueError , match = "different sampling times " ):
169144 tf2 + tf3
170- with pytest .raises (ValueError , match = "incompatible timebases " ):
145+ with pytest .raises (ValueError , match = "different sampling times " ):
171146 tf3 + tf2
172- with pytest .raises (ValueError , match = "incompatible timebases " ):
147+ with pytest .raises (ValueError , match = "different sampling times " ):
173148 tf2 + tf4
174- with pytest .raises (ValueError , match = "incompatible timebases " ):
149+ with pytest .raises (ValueError , match = "different sampling times " ):
175150 tf4 + tf2
176- with pytest .raises (ValueError , match = "incompatible timebases " ):
151+ with pytest .raises (ValueError , match = "different sampling times " ):
177152 feedback (tf2 , tf3 )
178- with pytest .raises (ValueError , match = "incompatible timebases " ):
153+ with pytest .raises (ValueError , match = "different sampling times " ):
179154 feedback (tf3 , tf2 )
180- with pytest .raises (ValueError , match = "incompatible timebases " ):
155+ with pytest .raises (ValueError , match = "different sampling times " ):
181156 feedback (tf2 , tf4 )
182- with pytest .raises (ValueError , match = "incompatible timebases " ):
157+ with pytest .raises (ValueError , match = "different sampling times " ):
183158 feedback (tf4 , tf2 )
184159
185160 def testisdtime (self , tsys ):
@@ -237,7 +212,6 @@ def testAddition(self, tsys):
237212 sys = tsys .siso_ss1c + tsys .siso_ss1c
238213 sys = tsys .siso_ss1d + tsys .siso_ss1d
239214 sys = tsys .siso_ss3d + tsys .siso_ss3d
240- sys = tsys .siso_ss1d + tsys .siso_ss3d
241215
242216 with pytest .raises (ValueError ):
243217 StateSpace .__add__ (tsys .mimo_ss1c , tsys .mimo_ss1d )
@@ -254,7 +228,6 @@ def testAddition(self, tsys):
254228 sys = tsys .siso_tf1c + tsys .siso_tf1c
255229 sys = tsys .siso_tf1d + tsys .siso_tf1d
256230 sys = tsys .siso_tf2d + tsys .siso_tf2d
257- sys = tsys .siso_tf1d + tsys .siso_tf3d
258231
259232 with pytest .raises (ValueError ):
260233 TransferFunction .__add__ (tsys .siso_tf1c , tsys .siso_tf1d )
@@ -279,7 +252,6 @@ def testMultiplication(self, tsys):
279252 sys = tsys .siso_ss1d * tsys .siso_ss1
280253 sys = tsys .siso_ss1c * tsys .siso_ss1c
281254 sys = tsys .siso_ss1d * tsys .siso_ss1d
282- sys = tsys .siso_ss1d * tsys .siso_ss3d
283255
284256 with pytest .raises (ValueError ):
285257 StateSpace .__mul__ (tsys .mimo_ss1c , tsys .mimo_ss1d )
@@ -295,7 +267,6 @@ def testMultiplication(self, tsys):
295267 sys = tsys .siso_tf1d * tsys .siso_tf1
296268 sys = tsys .siso_tf1c * tsys .siso_tf1c
297269 sys = tsys .siso_tf1d * tsys .siso_tf1d
298- sys = tsys .siso_tf1d * tsys .siso_tf3d
299270
300271 with pytest .raises (ValueError ):
301272 TransferFunction .__mul__ (tsys .siso_tf1c , tsys .siso_tf1d )
@@ -322,7 +293,6 @@ def testFeedback(self, tsys):
322293 sys = feedback (tsys .siso_ss1d , tsys .siso_ss1 )
323294 sys = feedback (tsys .siso_ss1c , tsys .siso_ss1c )
324295 sys = feedback (tsys .siso_ss1d , tsys .siso_ss1d )
325- sys = feedback (tsys .siso_ss1d , tsys .siso_ss3d )
326296
327297 with pytest .raises (ValueError ):
328298 feedback (tsys .mimo_ss1c , tsys .mimo_ss1d )
@@ -338,7 +308,6 @@ def testFeedback(self, tsys):
338308 sys = feedback (tsys .siso_tf1d , tsys .siso_tf1 )
339309 sys = feedback (tsys .siso_tf1c , tsys .siso_tf1c )
340310 sys = feedback (tsys .siso_tf1d , tsys .siso_tf1d )
341- sys = feedback (tsys .siso_tf1d , tsys .siso_tf3d )
342311
343312 with pytest .raises (ValueError ):
344313 feedback (tsys .siso_tf1c , tsys .siso_tf1d )
0 commit comments