import unittest
from modelverse_state.main import ModelverseState

from modelverse_state import status

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

    def test_read_edge_node(self):
        b, r = self.mvs.create_node()
        self.assertEquals(r, status.SUCCESS)

        v, r = self.mvs.read_edge(b)
        s, t = v
        self.assertEquals(s, None)
        self.assertEquals(t, None)
        self.assertEquals(r, status.FAIL_RE_UNKNOWN)

    def test_read_edge_no_exists(self):
        v, r = self.mvs.read_edge(-1)
        s, t = v
        self.assertEquals(s, None)
        self.assertEquals(t, None)
        self.assertEquals(r, status.FAIL_RE_UNKNOWN)

    def test_read_edge_nodevalue(self):
        b, r = self.mvs.create_nodevalue(1)
        self.assertEquals(r, status.SUCCESS)

        v, r = self.mvs.read_edge(-1)
        s, t = v
        self.assertEquals(s, None)
        self.assertEquals(t, None)
        self.assertEquals(r, status.FAIL_RE_UNKNOWN)

    def test_read_edge_normal(self):
        a, r = self.mvs.create_node()
        self.assertEquals(r, status.SUCCESS)
        b, r = self.mvs.create_node()
        self.assertEquals(r, status.SUCCESS)
        c, r = self.mvs.create_edge(a, b)
        self.assertEquals(r, status.SUCCESS)

        v, r = self.mvs.read_edge(c)
        s, t = v
        self.assertEquals(s, a)
        self.assertEquals(t, b)
        self.assertEquals(r, status.SUCCESS)

    def test_read_edge_edge_to_edge(self):
        a, r = self.mvs.create_node()
        self.assertEquals(r, status.SUCCESS)
        b, r = self.mvs.create_node()
        self.assertEquals(r, status.SUCCESS)
        c, r = self.mvs.create_edge(a, b)
        self.assertEquals(r, status.SUCCESS)
        d, r = self.mvs.create_edge(a, b)
        self.assertEquals(r, status.SUCCESS)
        e, r = self.mvs.create_edge(c, d)
        self.assertEquals(r, status.SUCCESS)

        v, r = self.mvs.read_edge(c)
        s, t = v
        self.assertEquals(s, a)
        self.assertEquals(t, b)
        self.assertEquals(r, status.SUCCESS)

        v, r = self.mvs.read_edge(d)
        s, t = v
        self.assertEquals(s, a)
        self.assertEquals(t, b)
        self.assertEquals(r, status.SUCCESS)

        v, r = self.mvs.read_edge(e)
        s, t = v
        self.assertEquals(s, c)
        self.assertEquals(t, d)
        self.assertEquals(r, status.SUCCESS)

    def test_read_edge_edge_to_node(self):
        a, r = self.mvs.create_node()
        self.assertEquals(r, status.SUCCESS)
        b, r = self.mvs.create_node()
        self.assertEquals(r, status.SUCCESS)
        c, r = self.mvs.create_edge(a, b)
        self.assertEquals(r, status.SUCCESS)
        d, r = self.mvs.create_edge(c, b)
        self.assertEquals(r, status.SUCCESS)

        v, r = self.mvs.read_edge(c)
        s, t = v
        self.assertEquals(s, a)
        self.assertEquals(t, b)
        self.assertEquals(r, status.SUCCESS)

        v, r = self.mvs.read_edge(d)
        s, t = v
        self.assertEquals(s, c)
        self.assertEquals(t, b)
        self.assertEquals(r, status.SUCCESS)

    def test_read_edge_node_to_edge(self):
        a, r = self.mvs.create_node()
        self.assertEquals(r, status.SUCCESS)
        b, r = self.mvs.create_node()
        self.assertEquals(r, status.SUCCESS)
        c, r = self.mvs.create_edge(a, b)
        self.assertEquals(r, status.SUCCESS)
        d, r = self.mvs.create_edge(b, c)
        self.assertEquals(r, status.SUCCESS)

        v, r = self.mvs.read_edge(c)
        s, t = v
        self.assertEquals(s, a)
        self.assertEquals(t, b)
        self.assertEquals(r, status.SUCCESS)

        v, r = self.mvs.read_edge(d)
        s, t = v
        self.assertEquals(s, b)
        self.assertEquals(t, c)
        self.assertEquals(r, status.SUCCESS)

    def test_read_edge_node_to_nodevalue(self):
        a, r = self.mvs.create_node()
        self.assertEquals(r, status.SUCCESS)
        b, r = self.mvs.create_nodevalue(1)
        self.assertEquals(r, status.SUCCESS)
        c, r = self.mvs.create_edge(a, b)
        self.assertEquals(r, status.SUCCESS)

        v, r = self.mvs.read_edge(c)
        s, t = v
        self.assertEquals(s, a)
        self.assertEquals(t, b)
        self.assertEquals(r, status.SUCCESS)

    def test_read_edge_nodevalue_to_nodevalue(self):
        a, r = self.mvs.create_nodevalue(1)
        self.assertEquals(r, status.SUCCESS)
        b, r = self.mvs.create_nodevalue(1)
        self.assertEquals(r, status.SUCCESS)
        c, r = self.mvs.create_edge(a, b)
        self.assertEquals(r, status.SUCCESS)

        v, r = self.mvs.read_edge(c)
        s, t = v
        self.assertEquals(s, a)
        self.assertEquals(t, b)
        self.assertEquals(r, status.SUCCESS)
