Skip to content
Snippets Groups Projects

Resolve "Operation Replacement in a SFG"

Closed Kevin Scott requested to merge 17-operation-replacement-in-a-sfg into develop
5 unresolved threads
+ 40
1
import pytest
from b_asic import SFG, Signal, Input, Output, Constant, Addition, Multiplication
from b_asic import SFG, Signal, Input, Output, Constant, Addition, Subtraction, Multiplication, MAD, ConstantMultiplication, Butterfly
class TestInit:
@@ -254,3 +254,42 @@ class TestReplaceComponents:
assert True
else:
assert False
class TestReplaceOperations:
def test_replace_mul_add_with_mad(self):
in1 = Input()
in2 = Input()
in3 = Input()
mul1 = in1 * in2
add1 = mul1 + in3
out1 = Output(add1)
sfg = SFG(inputs=[in1, in2, in3], outputs=[out1])
mad1 = MAD()
_sfg = sfg.replace_operations(['add1', 'mul1'], mad1)
assert 'mad1' in _sfg._components_by_id.keys()
assert {add1, mul1} not in _sfg.operations
    • Test case requires more asserts that ensure that the resulting SFG has the connections right and that the MAD is in the right place of the SFG.

Please register or sign in to reply
assert _sfg.input(0).signals
def test_replace_neg_add_with_sub(self):
in1 = Input()
in2 = Input()
neg1 = ConstantMultiplication(-1, in1)
add1 = neg1 + in2
out1 = Output(add1)
sfg = SFG(inputs=[in1, in2], outputs=[out1])
sub1 = Subtraction()
_sfg = sfg.replace_operations(['add1', 'cmul1'], sub1)
assert 'sub1' in _sfg._components_by_id.keys()
assert {add1, neg1} not in _sfg.operations
Please register or sign in to reply
assert _sfg.input(0).signals
def test_different_input_output_count(self, operation_tree):
sfg = SFG(outputs=[Output(operation_tree)])
constmul1 = ConstantMultiplication()
with pytest.raises(AssertionError):
sfg.replace_operations(['add1'], constmul1)
Loading