from os.path import isfile

import pytest

from b_asic import SFG, Output, load_structure, save_structure


class TestSaveStructures:

    def test_save_sfg(self, large_operation_tree):
        sfg = SFG(outputs=[Output(large_operation_tree)])
        path = save_structure(sfg)
        
        assert path is not None
        assert isfile(path)

    def test_load_sfg(self, large_operation_tree):
        sfg = SFG(outputs=[Output(large_operation_tree)])
        path = save_structure(sfg)
        _sfg = load_structure(path)
        
        assert isinstance(_sfg, SFG)
        assert sfg.evaluate() == _sfg.evaluate()