Skip to content
Snippets Groups Projects
test_print_sfg.py 1.91 KiB
Newer Older
  • Learn to ignore specific revisions
  • """
    B-ASIC test suite for printing a SFG
    """
    
    
    from b_asic.signal_flow_graph import SFG
    
    from b_asic.core_operations import Addition, Multiplication, Constant
    
    from b_asic.port import InputPort, OutputPort
    from b_asic.signal import Signal
    from b_asic.special_operations import Input, Output
    
    import pytest
    
    
    class TestPrintSfg:
        def test_print_one_addition(self):
            inp1 = Input("INP1")
            inp2 = Input("INP2")
            add1 = Addition(inp1, inp2, "ADD1")
            out1 = Output(add1, "OUT1")
            sfg = SFG(inputs=[inp1, inp2], outputs=[out1], name="sf1")
    
            assert sfg.__str__() == ("id: add1, name: ADD1, input: [s1, s2], output: [s3]\nid: in1, name: INP1, input: [], output: [s1]\nid: in2, name: INP2, input: [], output: [s2]\nid: out1, name: OUT1, input: [s3], output: []\n")
    
        def test_print_add_mul(self):
            inp1 = Input("INP1")
            inp2 = Input("INP2")
            inp3 = Input("INP3")
            add1 = Addition(inp1, inp2, "ADD1")
            mul1 = Multiplication(add1, inp3, "MUL1")
            out1 = Output(mul1, "OUT1")
            sfg = SFG(inputs=[inp1, inp2, inp3], outputs=[out1], name="mac_sfg")
    
            assert sfg.__str__() == ("id: add1, name: ADD1, input: [s1, s2], output: [s5]\nid: in1, name: INP1, input: [], output: [s1]\nid: in2, name: INP2, input: [], output: [s2]\nid: mul1, name: MUL1, input: [s5, s3], output: [s4]\nid: in3, name: INP3, input: [], output: [s3]\nid: out1, name: OUT1, input: [s4], output: []\n")
    
        def test_print_constant(self):
            inp1 = Input("INP1")
            const1 = Constant(3, "CONST")
            add1 = Addition(const1, inp1, "ADD1")
            out1 = Output(add1, "OUT1")
    
            sfg = SFG(inputs=[inp1], outputs=[out1], name="sfg")
    
            assert sfg.__str__() == ("id: add1, name: ADD1, input: [s3, s1], output: [s2]\nid: c1, name: CONST, value: 3, input: [], output: [s3]\nid: in1, name: INP1, input: [], output: [s1]\nid: out1, name: OUT1, input: [s2], output: []\n")