import unittest
from modelverse_state.main import ModelverseState

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

    def test_read_edge_node(self):
        b = self.mvs.create_node()
        assert b != None

        s, t = self.mvs.read_edge(b)
        assert s == None
        assert t == None

    def test_read_edge_no_exists(self):
        s, t = self.mvs.read_edge(-1)
        assert s == None
        assert t == None

    def test_read_edge_nodevalue(self):
        b = self.mvs.create_nodevalue(1)
        assert b != None

        s, t = self.mvs.read_edge(b)
        assert s == None
        assert t == None

    def test_read_edge_normal(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

        s, t = self.mvs.read_edge(c)
        assert s == a
        assert t == b

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

        s, t = self.mvs.read_edge(c)
        assert s == a
        assert t == b

        s, t = self.mvs.read_edge(d)
        assert s == a
        assert t == b

        s, t = self.mvs.read_edge(e)
        assert s == c
        assert t == d

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

        s, t = self.mvs.read_edge(c)
        assert s == a
        assert t == b

        s, t = self.mvs.read_edge(d)
        assert s == c
        assert t == b

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

        s, t = self.mvs.read_edge(c)
        assert s == a
        assert t == b

        s, t = self.mvs.read_edge(d)
        assert s == b
        assert t == c

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

        s, t = self.mvs.read_edge(c)
        assert s == a
        assert t == b

    def test_read_edge_nodevalue_to_nodevalue(self):
        a = self.mvs.create_nodevalue(1)
        b = self.mvs.create_nodevalue(1)
        c = self.mvs.create_edge(a, b)
        assert a != None
        assert b != None
        assert c != None

        s, t = self.mvs.read_edge(c)
        assert s == a
        assert t == b
