Skip to content

Commit 3cea5c5

Browse files
committed
Add __mul__, __rmul__, __truediv__, and __rtruediv__ tests
1 parent 7aaf355 commit 3cea5c5

1 file changed

Lines changed: 207 additions & 0 deletions

File tree

control/tests/xferfcn_test.py

Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,213 @@ def test_pow(self):
390390
with pytest.raises(ValueError):
391391
TransferFunction.__pow__(sys1, 0.5)
392392

393+
@pytest.mark.parametrize(
394+
"left, right, expected",
395+
[
396+
(
397+
TransferFunction([2], [1, 0]),
398+
TransferFunction(
399+
[
400+
[[2], [1]],
401+
[[-1], [4]],
402+
],
403+
[
404+
[[10, 1], [20, 1]],
405+
[[20, 1], [30, 1]],
406+
],
407+
),
408+
TransferFunction(
409+
[
410+
[[4], [2]],
411+
[[-2], [8]],
412+
],
413+
[
414+
[[10, 1, 0], [20, 1, 0]],
415+
[[20, 1, 0], [30, 1, 0]],
416+
],
417+
),
418+
),
419+
(
420+
TransferFunction(
421+
[
422+
[[2], [1]],
423+
[[-1], [4]],
424+
],
425+
[
426+
[[10, 1], [20, 1]],
427+
[[20, 1], [30, 1]],
428+
],
429+
),
430+
TransferFunction([2], [1, 0]),
431+
TransferFunction(
432+
[
433+
[[4], [2]],
434+
[[-2], [8]],
435+
],
436+
[
437+
[[10, 1, 0], [20, 1, 0]],
438+
[[20, 1, 0], [30, 1, 0]],
439+
],
440+
),
441+
),
442+
(
443+
TransferFunction([2], [1, 0]),
444+
np.eye(3),
445+
TransferFunction(
446+
[
447+
[[2], [0], [0]],
448+
[[0], [2], [0]],
449+
[[0], [0], [2]],
450+
],
451+
[
452+
[[1, 0], [1], [1]],
453+
[[1], [1, 0], [1]],
454+
[[1], [1], [1, 0]],
455+
],
456+
),
457+
),
458+
]
459+
)
460+
def test_mul_mimo_siso(self, left, right, expected):
461+
"""Test multiplication of a MIMO and a SISO system."""
462+
result = left.__mul__(right)
463+
assert _tf_close_coeff(expected.minreal(), result.minreal())
464+
465+
@pytest.mark.parametrize(
466+
"left, right, expected",
467+
[
468+
(
469+
TransferFunction([2], [1, 0]),
470+
TransferFunction(
471+
[
472+
[[2], [1]],
473+
[[-1], [4]],
474+
],
475+
[
476+
[[10, 1], [20, 1]],
477+
[[20, 1], [30, 1]],
478+
],
479+
),
480+
TransferFunction(
481+
[
482+
[[4], [2]],
483+
[[-2], [8]],
484+
],
485+
[
486+
[[10, 1, 0], [20, 1, 0]],
487+
[[20, 1, 0], [30, 1, 0]],
488+
],
489+
),
490+
),
491+
(
492+
TransferFunction(
493+
[
494+
[[2], [1]],
495+
[[-1], [4]],
496+
],
497+
[
498+
[[10, 1], [20, 1]],
499+
[[20, 1], [30, 1]],
500+
],
501+
),
502+
TransferFunction([2], [1, 0]),
503+
TransferFunction(
504+
[
505+
[[4], [2]],
506+
[[-2], [8]],
507+
],
508+
[
509+
[[10, 1, 0], [20, 1, 0]],
510+
[[20, 1, 0], [30, 1, 0]],
511+
],
512+
),
513+
),
514+
(
515+
np.eye(3),
516+
TransferFunction([2], [1, 0]),
517+
TransferFunction(
518+
[
519+
[[2], [0], [0]],
520+
[[0], [2], [0]],
521+
[[0], [0], [2]],
522+
],
523+
[
524+
[[1, 0], [1], [1]],
525+
[[1], [1, 0], [1]],
526+
[[1], [1], [1, 0]],
527+
],
528+
),
529+
),
530+
]
531+
)
532+
def test_rmul_mimo_siso(self, left, right, expected):
533+
"""Test right multiplication of a MIMO and a SISO system."""
534+
result = right.__rmul__(left)
535+
assert _tf_close_coeff(expected.minreal(), result.minreal())
536+
537+
@pytest.mark.parametrize(
538+
"left, right, expected",
539+
[
540+
(
541+
TransferFunction(
542+
[
543+
[[1], [0], [0]],
544+
[[0], [2], [0]],
545+
[[0], [0], [3]],
546+
],
547+
[
548+
[[1], [1], [1]],
549+
[[1], [1], [1]],
550+
[[1], [1], [1]],
551+
],
552+
),
553+
TransferFunction([-2], [1, 0]),
554+
TransferFunction(
555+
[
556+
[[1, 0], [0], [0]],
557+
[[0], [2, 0], [0]],
558+
[[0], [0], [3, 0]],
559+
],
560+
[
561+
[[-2], [1], [1]],
562+
[[1], [-2], [1]],
563+
[[1], [1], [-2]],
564+
],
565+
),
566+
),
567+
]
568+
)
569+
def test_truediv_mimo_siso(self, left, right, expected):
570+
"""Test true division of a MIMO and a SISO system."""
571+
result = left.__truediv__(right)
572+
assert _tf_close_coeff(expected.minreal(), result.minreal())
573+
574+
@pytest.mark.parametrize(
575+
"left, right, expected",
576+
[
577+
(
578+
np.eye(3),
579+
TransferFunction([2], [1, 0]),
580+
TransferFunction(
581+
[
582+
[[1, 0], [0], [0]],
583+
[[0], [1, 0], [0]],
584+
[[0], [0], [1, 0]],
585+
],
586+
[
587+
[[2], [1], [1]],
588+
[[1], [2], [1]],
589+
[[1], [1], [2]],
590+
],
591+
),
592+
),
593+
]
594+
)
595+
def test_rtruediv_mimo_siso(self, left, right, expected):
596+
"""Test right true division of a MIMO and a SISO system."""
597+
result = right.__rtruediv__(left)
598+
assert _tf_close_coeff(expected.minreal(), result.minreal())
599+
393600
@pytest.mark.parametrize("named", [False, True])
394601
def test_slice(self, named):
395602
sys = TransferFunction(

0 commit comments

Comments
 (0)