11#!/usr/bin/env python
22
3+ """TestConvert.py
4+
5+ Test state space and transfer function conversion.
6+
7+ Currently, this unit test script is not complete. Ideally, it would convert
8+ several random state spaces back and forth between state space and transfer
9+ function representations, and assert that the conversion outputs are correct.
10+ As they currently stand, the td04ad and tb04ad functions appear to be buggy from
11+ time to time. Therefore, this script can be used to diagnose the errors.
12+
13+ """
14+
315import numpy as np
416import matlab
517import unittest
@@ -11,26 +23,40 @@ def setUp(self):
1123 """Set up testing parameters."""
1224
1325 # Number of times to run each of the randomized tests.
14- self .numTests = 10
26+ self .numTests = 1
1527 # Maximum number of states to test + 1
16- self .maxStates = 5
28+ self .maxStates = 3
1729 # Maximum number of inputs and outputs to test + 1
18- self .maxIO = 5
30+ self .maxIO = 3
31+ # Set to True to print systems to the output.
32+ self .debug = False
33+
34+ def printSys (self , sys , ind ):
35+ """Print system to the standard output."""
36+
37+ if self .debug :
38+ print "sys%i:\n " % ind
39+ print sys
1940
2041 def testConvert (self ):
2142 """Test state space to transfer function conversion."""
43+
44+ print __doc__
2245
2346 for states in range (1 , self .maxStates ):
2447 for inputs in range (1 , self .maxIO ):
2548 for outputs in range (1 , self .maxIO ):
26- sys = matlab .rss (states , inputs , outputs )
27- print "sys1:\n " , sys
28- sys2 = matlab .tf (sys )
29- print "sys2:\n " , sys2
30- #sys3 = matlab.ss(sys2)
31- #print "sys3:\n", sys3
32- #sys4 = matlab.tf(sys3)
33- #print "sys4:\n", sys4
49+ sys1 = matlab .rss (states , inputs , outputs )
50+ self .printSys (sys1 , 1 )
51+
52+ sys2 = matlab .tf (sys1 )
53+ self .printSys (sys2 , 2 )
54+
55+ sys3 = matlab .ss (sys2 )
56+ self .printSys (sys3 , 3 )
57+
58+ sys4 = matlab .tf (sys3 )
59+ self .printSys (sys4 , 4 )
3460
3561if __name__ == "__main__" :
3662 unittest .main ()
0 commit comments