8000 add tests for auto-sum and auto-split · controlPh/python-control@b787a9e · GitHub
[go: up one dir, main page]

Skip to content

Commit b787a9e

Browse files
committed
add tests for auto-sum and auto-split
1 parent 796acad commit b787a9e

File tree

2 files changed

+77
-16
lines changed
Collapse file tree

2 files changed

+77
-16
lines changed

control/nlsys.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,14 +1021,14 @@ def signal_table(self, show_names=False):
10211021
>>> C = ct.tf(10, [.1, 1], inputs='e', outputs='u', name='C')
10221022
>>> L = ct.interconnect([C, P], inputs='e', outputs='y')
10231023
>>> L.signal_table(show_names=True) # doctest: +SKIP
1024-
signal | source | destination
1025-
--------------------------------------------------------------
1026-
e | input | C
1027-
u | C | P
1028-
y | P | output
1024+
signal | source | destination
1025+
--------------------------------------------------------------------
1026+
e | input | C
1027+
u | C | P
1028+
y | P | output
10291029
"""
10301030

1031-
spacing = 26
1031+
spacing = 32
10321032
print('signal'.ljust(10) + '| source'.ljust(spacing) + '| destination')
10331033
print('-'*(10 + spacing * 2))
10341034

@@ -1053,12 +1053,12 @@ def signal_table(self, show_names=False):
10531053
for idx, sys in enumerate(self.syslist):
10541054
loc = sys.find_output(signal_label)
10551055
if loc is not None:
1056-
if not sources.endswith(', '):
1056+
if not sources.endswith(' '):
10571057
sources += ', '
10581058
sources += sys.name if show_names else 'system ' + str(idx)
10591059
loc = sys.find_input(signal_label)
10601060
if loc is not None:
1061-
if not dests.endswith(', '):
1061+
if not dests.endswith(' '):
10621062
dests += ', '
10631063
dests += sys.name if show_names else 'system ' + str(idx)
10641064
print(sources.ljust(spacing), end='')

control/tests/interconnect_test.py

Lines changed: 69 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -215,23 +215,84 @@ def test_signal_table(capsys, show_names):
215215
# break the following strings separately because the printout order varies
216216
# because signal names are stored as a set
217217
mystrings = \
218-
["signal | source | destination",
219-
"-------------------------------------------------------------"]
218+
["signal | source | destination",
219+
"------------------------------------------------------------------"]
220220
if show_names:
221221
mystrings += \
222-
["e | input | C",
223-
"u | C | P",
224-
"y | P | output"]
222+
["e | input | C",
223+
"u | C | P",
224+
"y | P | output"]
225225
else:
226226
mystrings += \
227-
["e | input | system 0",
228-
"u | system 0 | system 1",
229-
"y | system 1 | output"]
227+
["e | input | system 0",
228+
"u | system 0 | system 1",
229+
"y | system 1 | output"]
230230

231231
for str_ in mystrings:
232232
assert str_ in captured_from_method
233233
assert str_ in captured_from_function
234234

235+
# check auto-sum
236+
P1 = ct.ss(1,1,1,0, inputs='u', outputs='y', name='P1')
237+
P2 = ct.tf(10, [.1, 1], inputs='e', outputs='y', name='P2')
238+
P3 = ct.tf(10, [.1, 1], inputs='x', outputs='y', name='P3')
239+
P = ct.interconnect([P1, P2, P3], inputs=['e', 'u', 'x'], outputs='y')
240+
P.signal_table(show_names=show_names)
241+
captured_from_method = capsys.readouterr().out
242+
243+
ct.signal_table(P, show_names=show_names)
244+
captured_from_function = capsys.readouterr().out
245+
246+
mystrings = \
247+
["signal | source | destination",
248+
"-------------------------------------------------------------------"]
249+
if show_names:
250+
mystrings += \
251+
["u | input | P1",
252+
"e | input | P2",
253+
"x | input | P3",
254+
"y | P1, P2, P3 | output"]
255+
else:
256+
mystrings += \
257+
["u | input | system 0",
258+
"e | input | system 1",
259+
"x | input | system 2",
260+
"y | system 0, system 1, system 2 | output"]
261+
262+
for str_ in mystrings:
263+
assert str_ in captured_from_method
264+
assert str_ in captured_from_function
265+
266+
# check auto-split
267+
P1 = ct.ss(1,1,1,0, inputs='u', outputs='x', name='P1')
268+
P2 = ct.tf(10, [.1, 1], inputs='u', outputs='y', name='P2')
269+
P3 = ct.tf(10, [.1, 1], inputs='u', outputs='z', name='P3')
270+
P = ct.interconnect([P1, P2, P3], inputs=['u'], outputs=['x','y','z'])
271+
P.signal_table(show_names=show_names)
272+
captured_from_method = capsys.readouterr().out
273+
274+
ct.signal_table(P, show_names=show_names)
275+
captured_from_function = capsys.readouterr().out
276+
277+
mystrings = \
278+
["signal | source | destination",
279+
"-------------------------------------------------------------------"]
280+
if show_names:
281+
mystrings += \
282+
["u | input | P1, P2, P3",
283+
"x | P1 | output ",
284+
"y | P2 | output",
285+
"z | P3 | output"]
286+
else:
287+
mystrings += \
288+
["u | input | system 0, system 1, system 2",
289+
"x | system 0 | output ",
290+
"y | system 1 | output",
291+
"z | system 2 | output"]
292+
293+
for str_ in mystrings:
294+
assert str_ in captured_from_method
295+
assert str_ in captured_from_function
235296

236297
def test_interconnect_exceptions():
237298
# First make sure the docstring example works

0 commit comments

Comments
 (0)
0