import unittest
from modelverse_state.main import ModelverseState

class TestReadDict(unittest.TestCase):
    def setUp(self):
        self.mvs = ModelverseState()

    def test_read_dict_no_exists(self):
        l = self.mvs.read_dict(-1, "abc")
        assert l == None

    def test_read_dict_not_found_node(self):
        a = self.mvs.create_node()
        assert a != None

        # Passing data is not enforced, as the data will be interpreted if necessary
        l = self.mvs.read_dict(a, "abc")
        assert l == None

    def test_read_dict_not_found_nodevalue(self):
        a = self.mvs.create_nodevalue(1)
        assert a != None

        # Passing data is not enforced, as the data will be interpreted if necessary
        l = self.mvs.read_dict(a, "abc")
        assert l == None

    def test_read_dict_not_found_edge(self):
        a = self.mvs.create_node()
        b = self.mvs.create_node()
        c = self.mvs.create_edge(a, b)
        assert a != None
        assert b != None
        assert c != None

        # Passing data is not enforced, as the data will be interpreted if necessary
        l = self.mvs.read_dict(c, "abc")
        assert l == None

    def test_read_dict_no_primitive(self):
        a = self.mvs.create_node()
        assert a != None

        # Passing data is not enforced, as the data will be interpreted if necessary
        l = self.mvs.read_dict(a, a)
        assert l == None

    def test_read_dict_node_simple(self):
        a = self.mvs.create_node()
        b = self.mvs.create_node()
        c = self.mvs.create_nodevalue("f")
        d = self.mvs.create_edge(a, b)
        e = self.mvs.create_edge(d, c)
        assert a != None
        assert b != None
        assert c != None
        assert d != None
        assert e != None

        l = self.mvs.read_dict(a, "f")
        assert l == b

    def test_read_dict_node_multi(self):
        a = self.mvs.create_node()
        b = self.mvs.create_node()
        c = self.mvs.create_nodevalue("f")
        d = self.mvs.create_edge(a, b)
        e = self.mvs.create_edge(d, c)
        assert a != None
        assert b != None
        assert c != None
        assert d != None
        assert e != None

        g = self.mvs.create_node()
        h = self.mvs.create_nodevalue("k")
        i = self.mvs.create_edge(a, g)
        j = self.mvs.create_edge(i, h)
        assert g != None
        assert h != None
        assert i != None
        assert j != None

        l = self.mvs.read_dict(a, "f")
        assert l == b

        l = self.mvs.read_dict(a, "k")
        assert l == g

        l = self.mvs.read_dict(a, "l")
        assert l == None
