From bc599cf0f655053b50f322ae6c79f5f58191f743 Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson <rasmus@rasmus.local> Date: Sun, 26 Apr 2020 15:33:36 +0200 Subject: [PATCH] Removed unnecessary comments and newlines. --- b_asic/signal_flow_graph.py | 8 ------ test/test_sfg.py | 52 ++----------------------------------- 2 files changed, 2 insertions(+), 58 deletions(-) diff --git a/b_asic/signal_flow_graph.py b/b_asic/signal_flow_graph.py index 2bce1e0c..0eeefb19 100644 --- a/b_asic/signal_flow_graph.py +++ b/b_asic/signal_flow_graph.py @@ -237,7 +237,6 @@ class SFG(AbstractOperation): def replace_sfg_with_inner_components(self) -> bool: """ Replace this SFG with its component operations if itself is a component of another SFG. This SFG becomes unconnected to the SFG it is a component off. Returns True if succesful, False otherwise. """ - if len(self.inputs) != len(self.input_operations): raise IndexError(f"Number of inputs does not match the number of input_operations in SFG.") if len(self.outputs) != len(self.output_operations): @@ -246,23 +245,16 @@ class SFG(AbstractOperation): try: # For each input_signal, connect it to the corresponding operation for port, input_operation in zip(self.inputs, self.input_operations): - # Disconnect the previous signal to the destination dest = input_operation.output(0).signals[0].destination dest.clear() - # Connect the signal to the new destination port.signals[0].set_destination(dest) - # For each output_signal, connect it to the corresponding operation for port, output_operation in zip(self.outputs, self.output_operations): - # Disconnect the previous signal to the source src = output_operation.input(0).signals[0].source src.clear() - # Connect the signal to the new source port.signals[0].set_source(src) - return True except IndexError: - # This SFG is not a component of another SFG return False @property diff --git a/test/test_sfg.py b/test/test_sfg.py index 26bf3211..6a495365 100644 --- a/test/test_sfg.py +++ b/test/test_sfg.py @@ -255,11 +255,10 @@ class TestReplaceComponents: else: assert False -class TestReplaceSelfSoloComp: +class TestReplaceSfgWithInnerComponentsSoloComp: def test_replace_sfg_with_inner_components_mac(self): """ Replace a MAC with inner components in an SFG """ - inp1 = Input("INP1") inp2 = Input("INP2") inp3 = Input("INP3") @@ -287,54 +286,34 @@ class TestReplaceSelfSoloComp: out2.input(0).connect(mac_sfg.outputs[0], "S10") test_sfg = SFG(inputs = [inp4, inp5], outputs = [out2]) - assert test_sfg.evaluate(1,2) == 9 - mac_sfg.replace_sfg_with_inner_components() - assert test_sfg.evaluate(1,2) == 9 - assert test_sfg.replace_sfg_with_inner_components() == False def test_replace_sfg_with_inner_components_operation_tree(self, operation_tree): """ Replaces an SFG with only a operation_tree component with its inner components """ - sfg1 = SFG(outputs = [Output(operation_tree)]) - out1 = Output(None, "OUT1") - out1.input(0).connect(sfg1.outputs[0], "S1") - test_sfg = SFG(outputs = [out1]) - assert test_sfg.evaluate_output(0, []) == 5 - sfg1.replace_sfg_with_inner_components() - assert test_sfg.evaluate_output(0, []) == 5 - assert test_sfg.replace_sfg_with_inner_components() == False def test_replace_sfg_with_inner_components_large_operation_tree(self, large_operation_tree): """ Replaces an SFG with only a large_operation_tree component with its inner components """ - sfg1 = SFG(outputs = [Output(large_operation_tree)]) - out1 = Output(None, "OUT1") - out1.input(0).connect(sfg1.outputs[0], "S1") - test_sfg = SFG(outputs = [out1]) - assert test_sfg.evaluate_output(0, []) == 14 - sfg1.replace_sfg_with_inner_components() - assert test_sfg.evaluate_output(0, []) == 14 - assert test_sfg.replace_sfg_with_inner_components() == False -class TestReplaceSelfMultipleComp: +class TestReplaceSfgWithInnerComponentsMultipleComp: def test_replace_sfg_with_inner_components_operation_tree(self, operation_tree): """ Replaces a operation_tree in an SFG with other components """ @@ -349,20 +328,14 @@ class TestReplaceSelfMultipleComp: add1.input(0).connect(inp1, "S1") add1.input(1).connect(inp2, "S2") - add2.input(0).connect(add1, "S3") add2.input(1).connect(sfg1.outputs[0], "S4") - out1.input(0).connect(add2, "S5") test_sfg = SFG(inputs = [inp1, inp2], outputs = [out1]) - assert test_sfg.evaluate(1, 2) == 8 - sfg1.replace_sfg_with_inner_components() - assert test_sfg.evaluate(1, 2) == 8 - assert test_sfg.replace_sfg_with_inner_components() == False def test_replace_sfg_with_inner_components_large_operation_tree(self, large_operation_tree): @@ -372,63 +345,49 @@ class TestReplaceSelfMultipleComp: inp1 = Input("INP1") inp2 = Input("INP2") out1 = Output(None, "OUT1") - add1 = Addition(None, None, "ADD1") add2 = Addition(None, None, "ADD2") add1.input(0).connect(inp1, "S1") add1.input(1).connect(inp2, "S2") - add2.input(0).connect(add1, "S3") add2.input(1).connect(sfg1.outputs[0], "S4") - out1.input(0).connect(add2, "S5") test_sfg = SFG(inputs = [inp1, inp2], outputs = [out1]) - assert test_sfg.evaluate(1, 2) == 17 - sfg1.replace_sfg_with_inner_components() - assert test_sfg.evaluate(1, 2) == 17 - assert test_sfg.replace_sfg_with_inner_components() == False def create_sfg(self, op_tree): """ Create a simple SFG with either operation_tree or large_operation_tree """ - sfg1 = SFG(outputs = [Output(op_tree)]) inp1 = Input("INP1") inp2 = Input("INP2") out1 = Output(None, "OUT1") - add1 = Addition(None, None, "ADD1") add2 = Addition(None, None, "ADD2") add1.input(0).connect(inp1, "S1") add1.input(1).connect(inp2, "S2") - add2.input(0).connect(add1, "S3") add2.input(1).connect(sfg1.outputs[0], "S4") - out1.input(0).connect(add2, "S5") return SFG(inputs = [inp1, inp2], outputs = [out1]) def test_replace_sfg_with_inner_components_many_op(self, large_operation_tree): """ Replaces an sfg component in a larger SFG with several component operations """ - inp1 = Input("INP1") inp2 = Input("INP2") inp3 = Input("INP3") inp4 = Input("INP4") out1 = Output(None, "OUT1") - add1 = Addition(None, None, "ADD1") sub1 = Subtraction(None, None, "SUB1") - add1.input(0).connect(inp1, "S1") add1.input(1).connect(inp2, "S2") @@ -436,19 +395,12 @@ class TestReplaceSelfMultipleComp: sfg1.input(0).connect(add1, "S3") sfg1.input(1).connect(inp3, "S4") - sub1.input(0).connect(sfg1.outputs[0], "S5") - sub1.input(1).connect(inp4, "S6") - out1.input(0).connect(sub1, "S7") test_sfg = SFG(inputs = [inp1, inp2, inp3, inp4], outputs = [out1]) - assert test_sfg.evaluate(1, 2, 3, 4) == 16 - sfg1.replace_sfg_with_inner_components() - assert test_sfg.evaluate(1, 2, 3, 4) == 16 - assert test_sfg.replace_sfg_with_inner_components() == False \ No newline at end of file -- GitLab