import unittest
from modelverse_state.main import ModelverseState

from modelverse_state import status

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

    def test_read_dict_edge_no_exists(self):
        l, r = self.mvs.read_dict_edge(-1, "abc")
        self.assertEquals(l, None)
        self.assertEquals(r, status.FAIL_RDICTE_UNKNOWN)

    def test_read_dict_edge_not_found_node(self):
        a, r = self.mvs.create_node()
        self.assertEquals(r, status.SUCCESS)

        # Passing data is not enforced, as the data will be interpreted if necessary
        l, r = self.mvs.read_dict_edge(a, "abc")
        self.assertEquals(l, None)
        self.assertEquals(r, status.FAIL_RDICTE_NOT_FOUND)

    def test_read_dict_edge_not_found_nodevalue(self):
        a, r = self.mvs.create_nodevalue(1)
        self.assertEquals(r, status.SUCCESS)

        # Passing data is not enforced, as the data will be interpreted if necessary
        l, r = self.mvs.read_dict_edge(a, "abc")
        self.assertEquals(l, None)
        self.assertEquals(r, status.FAIL_RDICTE_NOT_FOUND)

    def test_read_dict_edge_not_found_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)

        # Passing data is not enforced, as the data will be interpreted if necessary
        l, r = self.mvs.read_dict_edge(c, "abc")
        self.assertEquals(l, None)
        self.assertEquals(r, status.FAIL_RDICTE_NOT_FOUND)

    def test_read_dict_edge_no_primitive(self):
        a, r = self.mvs.create_node()
        self.assertEquals(r, status.SUCCESS)

        # Passing data is not enforced, as the data will be interpreted if necessary
        l, r = self.mvs.read_dict_edge(a, a)
        self.assertEquals(l, None)
        self.assertEquals(r, status.FAIL_RDICTE_NOT_FOUND)

    def test_read_dict_edge_node_simple(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_nodevalue("f")
        self.assertEquals(r, status.SUCCESS)
        d, r = self.mvs.create_edge(a, b)
        self.assertEquals(r, status.SUCCESS)
        e, r = self.mvs.create_edge(d, c)
        self.assertEquals(r, status.SUCCESS)

        l, r = self.mvs.read_dict_edge(a, "f")
        self.assertEquals(r, status.SUCCESS)
        self.assertEquals(l, d)

    def test_read_dict_edge_node_multi(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_nodevalue("f")
        self.assertEquals(r, status.SUCCESS)
        d, r = self.mvs.create_edge(a, b)
        self.assertEquals(r, status.SUCCESS)
        e, r = self.mvs.create_edge(d, c)
        self.assertEquals(r, status.SUCCESS)

        g, r = self.mvs.create_node()
        self.assertEquals(r, status.SUCCESS)
        h, r = self.mvs.create_nodevalue("k")
        self.assertEquals(r, status.SUCCESS)
        i, r = self.mvs.create_edge(a, g)
        self.assertEquals(r, status.SUCCESS)
        j, r = self.mvs.create_edge(i, h)
        self.assertEquals(r, status.SUCCESS)

        l, r = self.mvs.read_dict_edge(a, "f")
        self.assertEquals(r, status.SUCCESS)
        self.assertEquals(l, d)

        l, r = self.mvs.read_dict_edge(a, "k")
        self.assertEquals(r, status.SUCCESS)
        self.assertEquals(l, i)

        l, r = self.mvs.read_dict_edge(a, "l")
        self.assertEquals(r, status.FAIL_RDICTE_NOT_FOUND)
        self.assertEquals(l, None)

    """
    def test_read_dict_edge_node_uncertain(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_nodevalue("f")
        self.assertEquals(r, status.SUCCESS)
        d, r = self.mvs.create_edge(a, b)
        self.assertEquals(r, status.SUCCESS)
        e, r = self.mvs.create_edge(d, c)
        self.assertEquals(r, status.SUCCESS)

        h, r = self.mvs.create_nodevalue("g")
        self.assertEquals(r, status.SUCCESS)
        i, r = self.mvs.create_edge(d, h)
        self.assertEquals(r, status.SUCCESS)

        l, r = self.mvs.read_dict_edge(a, "f")
        self.assertEquals(r, status.FAIL_RDICTE_UNCERTAIN)
        self.assertEquals(l, None)
    """
