12
12
13
13
from control .xferfcn import _clean_part
14
14
15
+
15
16
class TestXferFcnInput (unittest .TestCase ):
16
- """These are tests for functionality of cleaning and validating
17
- XferFucnInput."""
17
+ """These are tests for functionality of cleaning and validating XferFcnInput."""
18
18
19
19
# Tests for raising exceptions.
20
- def testBadInputType (self ):
20
+ def test_clean_part_bad_input_type (self ):
21
21
"""Give the part cleaner invalid input type."""
22
22
23
23
self .assertRaises (TypeError ,_clean_part , [[0. ,1. ], [2. ,3. ]])
24
24
25
- def testBadInputType2 (self ):
25
+ def test_clean_part_bad_input_type2 (self ):
26
26
"""Give the part cleaner another invalid input type."""
27
27
self .assertRaises (TypeError ,_clean_part , [1 ,"a" ])
28
28
29
- def testScalar (self ):
29
+ def test_clean_part_scalar (self ):
30
30
"""Test single scalar value."""
31
31
num = 1
32
32
num_ = _clean_part (num )
@@ -35,7 +35,7 @@ def testScalar(self):
35
35
assert np .all ([isinstance (part ,list )for part in num_ ])
36
36
np .testing .assert_array_equal (num_ [0 ][0 ],array ([1.0 ],dtype = float ))
37
37
38
- def testListScalar (self ):
38
+ def test_clean_part_list_scalar (self ):
39
39
"""Test single scalar value in list."""
40
40
num = [1 ]
41
41
num_ = _clean_part (num )
@@ -44,7 +44,7 @@ def testListScalar(self):
44
44
assert np .all ([isinstance (part ,list )for part in num_ ])
45
45
np .testing .assert_array_equal (num_ [0 ][0 ],array ([1.0 ],dtype = float ))
46
46
47
- def testTupleScalar (self ):
47
+ def test_clean_part_tuple_scalar (self ):
48
48
"""Test single scalar value in tuple."""
49
49
num = (1 )
50
50
num_ = _clean_part (num )
@@ -53,7 +53,7 @@ def testTupleScalar(self):
53
53
assert np .all ([isinstance (part ,list )for part in num_ ])
54
54
np .testing .assert_array_equal (num_ [0 ][0 ],array ([1.0 ],dtype = float ))
55
55
56
- def testList (self ):
56
+ def test_clean_part_list (self ):
57
57
"""Test multiple values in a list."""
58
58
num = [1 ,2 ]
59
59
num_ = _clean_part (num )
@@ -62,7 +62,7 @@ def testList(self):
62
62
assert np .all ([isinstance (part ,list )for part in num_ ])
63
63
np .testing .assert_array_equal (num_ [0 ][0 ],array ([1.0 ,2.0 ],dtype = float ))
64
64
65
- def testTuple (self ):
65
+ def test_clean_part_tuple (self ):
66
66
"""Test multiple values in tuple."""
67
67
num = (1 ,2 )
68
68
num_ = _clean_part (num )
@@ -71,7 +71,7 @@ def testTuple(self):
71
71
assert np .all ([isinstance (part ,list )for part in num_ ])
72
72
np .testing .assert_array_equal (num_ [0 ][0 ],array ([1.0 ,2.0 ],dtype = float ))
73
73
74
- def testAllScalarTypes (self ):
74
+ def test_clean_part_all_scalar_types (self ):
75
75
"""Test single scalar value for all valid data types."""
76
76
for dtype in [int ,int8 ,int16 ,int32 ,int64 ,float ,float16 ,float32 ,float64 ,float128 ]:
77
77
num = dtype (1 )
@@ -81,7 +81,7 @@ def testAllScalarTypes(self):
81
81
assert np .all ([isinstance (part ,list )for part in num_ ])
82
82
np .testing .assert_array_equal (num_ [0 ][0 ],array ([1.0 ],dtype = float ))
83
83
84
- def testNpArray (self ):
84
+ def test_clean_part_np_array (self ):
85
85
"""Test multiple values in numpy array."""
86
86
num = np .array ([1 ,2 ])
87
87
num_ = _clean_part (num )
@@ -90,7 +90,7 @@ def testNpArray(self):
90
90
assert np .all ([isinstance (part ,list )for part in num_ ])
91
91
np .testing .assert_array_equal (num_ [0 ][0 ],array ([1.0 ,2.0 ],dtype = float ))
92
92
93
- def testAllNumpyArrayTypes (self ):
93
+ def test_clean_part_all_np_array_types (self ):
94
94
"""Test scalar value in numpy array of ndim=0 for all data types."""
95
95
for dtype in [int ,int8 ,int16 ,int32 ,int64 ,float ,float16 ,float32 ,float64 ,float128 ]:
96
96
num = np .array (1 ,dtype = dtype )
@@ -100,7 +100,7 @@ def testAllNumpyArrayTypes(self):
100
100
assert np .all ([isinstance (part ,list )for part in num_ ])
101
101
np .testing .assert_array_equal (num_ [0 ][0 ],array ([1.0 ],dtype = float ))
102
102
103
- def testAllNumpyArrayTypes2 (self ):
103
+ def test_clean_part_all_np_array_types2 (self ):
104
104
"""Test numpy array for all types."""
105
105
for dtype in [int ,int8 ,int16 ,int32 ,int64 ,float ,float16 ,float32 ,float64 ,float128 ]:
106
106
num = np .array ([1 ,2 ],dtype = dtype )
@@ -110,7 +110,7 @@ def testAllNumpyArrayTypes2(self):
110
110
assert np .all ([isinstance (part ,list )for part in num_ ])
111
111
np .testing .assert_array_equal (num_ [0 ][0 ],array ([1.0 ,2.0 ],dtype = float ))
112
112
113
- def testListAllTypes (self ):
113
+ def test_clean_part_list_all_types (self ):
114
114
"""Test list of a single value for all data types."""
115
115
for dtype in [int ,int8 ,int16 ,int32 ,int64 ,float ,float16 ,float32 ,float64 ,float128 ]:
116
116
num = [dtype (1 )]
@@ -119,7 +119,7 @@ def testListAllTypes(self):
119
119
assert np .all ([isinstance (part ,list )for part in num_ ])
120
120
np .testing .assert_array_equal (num_ [0 ][0 ],array ([1.0 ],dtype = float ))
121
121
122
- def testListAllTypes2 (self ):
122
+ def test_clean_part_list_all_types2 (self ):
123
123
"""List of list of numbers of all data types."""
124
124
for dtype in [int ,int8 ,int16 ,int32 ,int64 ,float ,float16 ,float32 ,float64 ,float128 ]:
125
125
num = [dtype (1 ),dtype (2 )]
@@ -128,7 +128,7 @@ def testListAllTypes2(self):
128
128
assert np .all ([isinstance (part ,list )for part in num_ ])
129
129
np .testing .assert_array_equal (num_ [0 ][0 ],array ([1.0 ,2.0 ],dtype = float ))
130
130
131
- def testTupleAllTypes (self ):
131
+ def test_clean_part_tuple_all_types (self ):
132
132
"""Test tuple of a single value for all data types."""
133
133
for dtype in [int ,int8 ,int16 ,int32 ,int64 ,float ,float16 ,float32 ,float64 ,float128 ]:
134
134
num = (dtype (1 ),)
@@ -137,7 +137,7 @@ def testTupleAllTypes(self):
137
137
assert np .all ([isinstance (part ,list )for part in num_ ])
138
138
np .testing .assert_array_equal (num_ [0 ][0 ],array ([1.0 ],dtype = float ))
139
139
140
- def testTupleAllTypes2 (self ):
140
+ def test_clean_part_tuple_all_types2 (self ):
141
141
"""Test tuple of a single value for all data types."""
142
142
for dtype in [int ,int8 ,int16 ,int32 ,int64 ,float ,float16 ,float32 ,float64 ,float128 ]:
143
143
num = (dtype (1 ),dtype (2 ))
@@ -146,43 +146,43 @@ def testTupleAllTypes2(self):
146
146
assert np .all ([isinstance (part ,list )for part in num_ ])
147
147
np .testing .assert_array_equal (num_ [0 ][0 ],array ([1 ,2 ],dtype = float ))
148
148
149
- def testListListListInt (self ):
149
+ def test_clean_part_list_list_list_int (self ):
150
150
""" Test an int in a list of a list of a list."""
151
151
num = [[[1 ]]]
152
152
num_ = _clean_part (num )
153
153
assert isinstance (num_ ,list )
154
154
assert np .all ([isinstance (part ,list )for part in num_ ])
155
155
np .testing .assert_array_equal (num_ [0 ][0 ],array ([1.0 ],dtype = float ))
156
156
157
- def testListListListFloat (self ):
157
+ def test_clean_part_list_list_list_float (self ):
158
158
""" Test a float in a list of a list of a list."""
159
159
num = [[[1.0 ]]]
160
160
num_ = _clean_part (num )
161
161
assert isinstance (num_ ,list )
162
162
assert np .all ([isinstance (part ,list )for part in num_ ])
163
163
np .testing .assert_array_equal (num_ [0 ][0 ],array ([1.0 ],dtype = float ))
164
164
165
- def testListListListInts (self ):
165
+ def test_clean_part_list_list_list_ints (self ):
166
166
"""Test 2 lists of ints in a list in a list."""
167
- num = [[[1 ,1 ],[2 ,2 ]]]
167
+ num = [[[1 ,1 ], [2 ,2 ]]]
168
168
num_ = _clean_part (num )
169
169
170
170
assert isinstance (num_ ,list )
171
171
assert np .all ([isinstance (part ,list )for part in num_ ])
172
172
np .testing .assert_array_equal (num_ [0 ][0 ],array ([1.0 ,1.0 ],dtype = float ))
173
173
np .testing .assert_array_equal (num_ [0 ][1 ],array ([2.0 ,2.0 ],dtype = float ))
174
174
175
- def testListListListFloats (self ):
175
+ def test_clean_part_list_list_list_floats (self ):
176
176
"""Test 2 lists of ints in a list in a list."""
177
- num = [[[1.0 ,1.0 ],[2.0 ,2.0 ]]]
177
+ num = [[[1.0 ,1.0 ], [2.0 ,2.0 ]]]
178
178
num_ = _clean_part (num )
179
179
180
180
assert isinstance (num_ ,list )
181
181
assert np .all ([isinstance (part ,list )for part in num_ ])
182
182
np .testing .assert_array_equal (num_ [0 ][0 ],array ([1.0 ,1.0 ],dtype = float ))
183
183
np .testing .assert_array_equal (num_ [0 ][1 ],array ([2.0 ,2.0 ],dtype = float ))
184
184
185
- def testListListArray (self ):
185
+ def test_clean_part_list_list_array (self ):
186
186
"""List of list of numpy arrays for all valid types."""
187
187
for dtype in int ,int8 ,int16 ,int32 ,int64 ,float ,float16 ,float32 ,float64 ,float128 :
188
188
num = [[array ([1 ,1 ],dtype = dtype ),array ([2 ,2 ],dtype = dtype )]]
@@ -193,7 +193,7 @@ def testListListArray(self):
193
193
np .testing .assert_array_equal (num_ [0 ][0 ],array ([1.0 ,1.0 ],dtype = float ))
194
194
np .testing .assert_array_equal (num_ [0 ][1 ],array ([2.0 ,2.0 ],dtype = float ))
195
195
196
- def testTupleListArray (self ):
196
+ def test_clean_part_tuple_list_array (self ):
197
197
"""Tuple of list of numpy arrays for all valid types."""
198
198
for dtype in int ,int8 ,int16 ,int32 ,int64 ,float ,float16 ,float32 ,float64 ,float128 :
199
199
num = ([array ([1 ,1 ],dtype = dtype ),array ([2 ,2 ],dtype = dtype )],)
@@ -204,7 +204,7 @@ def testTupleListArray(self):
204
204
np .testing .assert_array_equal (num_ [0 ][0 ],array ([1.0 ,1.0 ],dtype = float ))
205
205
np .testing .assert_array_equal (num_ [0 ][1 ],array ([2.0 ,2.0 ],dtype = float ))
206
206
207
- def testListTupleArray (self ):
207
+ def test_clean_part_list_tuple_array (self ):
208
208
"""List of tuple of numpy array for all valid types."""
209
209
for dtype in int ,int8 ,int16 ,int32 ,int64 ,float ,float16 ,float32 ,float64 ,float128 :
210
210
num = [(array ([1 ,1 ],dtype = dtype ),array ([2 ,2 ],dtype = dtype ))]
@@ -215,7 +215,7 @@ def testListTupleArray(self):
215
215
np .testing .assert_array_equal (num_ [0 ][0 ],array ([1.0 ,1.0 ],dtype = float ))
216
216
np .testing .assert_array_equal (num_ [0 ][1 ],array ([2.0 ,2.0 ],dtype = float ))
217
217
218
- def testTupleTuplesArrays (self ):
218
+ def test_clean_part_tuple_tuples_arrays (self ):
219
219
"""Tuple of tuples of numpy arrays for all valid types."""
220
220
for dtype in int ,int8 ,int16 ,int32 ,int64 ,float ,float16 ,float32 ,float64 ,float128 :
221
221
num = ((array ([1 ,1 ],dtype = dtype ),array ([2 ,2 ],dtype = dtype )),
@@ -227,23 +227,23 @@ def testTupleTuplesArrays(self):
227
227
np .testing .assert_array_equal (num_ [0 ][0 ],array ([1.0 ,1.0 ],dtype = float ))
228
228
np .testing .assert_array_equal (num_ [0 ][1 ],array ([2.0 ,2.0 ],dtype = float ))
229
229
230
- def testListTuplesArrays (self ):
230
+ def test_clean_part_list_tuples_arrays (self ):
231
231
"""List of tuples of numpy arrays for all valid types."""
232
232
for dtype in int ,int8 ,int16 ,int32 ,int64 ,float ,float16 ,float32 ,float64 ,float128 :
233
- num = [(array ([1 ,1 ],dtype = dtype ),array ([2 ,2 ],dtype = dtype )),
234
- (array ([3 ,4 ],dtype = dtype ),array ([4 ,4 ],dtype = dtype ))]
233
+ num = [(array ([1 ,1 ],dtype = dtype ),array ([2 ,2 ],dtype = dtype )),
234
+ (array ([3 ,4 ],dtype = dtype ),array ([4 ,4 ],dtype = dtype ))]
235
235
num_ = _clean_part (num )
236
236
237
237
assert isinstance (num_ ,list )
238
238
assert np .all ([isinstance (part ,list )for part in num_ ])
239
239
np .testing .assert_array_equal (num_ [0 ][0 ],array ([1.0 ,1.0 ],dtype = float ))
240
240
np .testing .assert_array_equal (num_ [0 ][1 ],array ([2.0 ,2.0 ],dtype = float ))
241
241
242
- def testListListArrays (self ):
242
+ def test_clean_part_list_list_arrays (self ):
243
243
"""List of list of numpy arrays for all valid types."""
244
244
for dtype in int ,int8 ,int16 ,int32 ,int64 ,float ,float16 ,float32 ,float64 ,float128 :
245
- num = [[array ([1 ,1 ],dtype = dtype ),array ([2 ,2 ],dtype = dtype )],
246
- [array ([3 ,3 ],dtype = dtype ),array ([4 ,4 ],dtype = dtype )]]
245
+ num = [[array ([1 ,1 ],dtype = dtype ),array ([2 ,2 ],dtype = dtype )],
246
+ [array ([3 ,3 ],dtype = dtype ),array ([4 ,4 ],dtype = dtype )]]
247
247
num_ = _clean_part (num )
248
248
249
249
assert len (num_ )== 2
@@ -254,8 +254,10 @@ def testListListArrays(self):
254
254
np .testing .assert_array_equal (num_ [1 ][0 ],array ([3.0 ,3.0 ],dtype = float ))
255
255
np .testing .assert_array_equal (num_ [1 ][1 ],array ([4.0 ,4.0 ],dtype = float ))
256
256
257
+
257
258
def suite ():
258
259
return unittest .TestLoader ().loadTestsFromTestCase (TestXferFcnInput )
259
260
261
+
260
262
if __name__ == "__main__" :
261
263
unittest .main ()