from networkx.readwrite import json_graph

import finesse


def test_symbolic_network():
    model = finesse.Model(
        """
    var Y 0.5
    var X Y
    var Z 10
    m m1 R=1-m1.T T=X phi=X+Z
    """
    )
    REF_GRAPH = {
        "directed": True,
        "multigraph": False,
        "graph": [],
        "nodes": [
            {"id": model.X},
            {"id": model.m1.phi},
            {"id": model.Z},
            {"id": model.m1.R},
            {"id": model.m1.L},
            {"id": model.m1.T},
            {"id": model.Y},
        ],
        "adjacency": [
            [{"id": model.m1.phi}, {"id": model.m1.T}],
            [],
            [{"id": model.m1.phi}],
            [{"id": model.m1.L}],
            [],
            [{"id": model.m1.L}, {"id": model.m1.R}],
            [{"id": model.X}],
        ],
    }
    assert json_graph.adjacency_data(model.symbolic_network) == REF_GRAPH
