import unittest
from modelverse_state.main import ModelverseState

from modelverse_state import status

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

    def test_read_dict_node_no_exists(self):
        l, r = self.mvs.read_dict_node(-1, "abc")
        self.assertEquals(l, None)
        self.assertEquals(r, status.FAIL_RDICTN_UNKNOWN)

    def test_read_dict_node_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_node(c, "abc")
        self.assertEquals(l, None)
        self.assertEquals(r, status.FAIL_RDICTN_NOT_FOUND)

    def test_read_dict_node_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_node(a, a)
        self.assertEquals(l, None)
        self.assertEquals(r, status.FAIL_RDICTN_NOT_FOUND)

    def test_read_dict_node_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_node()
        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_node(a, c)
        self.assertEquals(r, status.SUCCESS)
        self.assertEquals(l, b)

    def test_read_dict_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_node()
        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_node()
        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_node(a, c)
        self.assertEquals(r, status.SUCCESS)
        self.assertEquals(l, b)

        l, r = self.mvs.read_dict_node(a, h)
        self.assertEquals(r, status.SUCCESS)
        self.assertEquals(l, g)

    """
    def test_read_dict_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_node()
        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_node()
        self.assertEquals(r, status.SUCCESS)
        i, r = self.mvs.create_edge(d, h)
        self.assertEquals(r, status.SUCCESS)

        l, r = self.mvs.read_dict_node(a, c)
        self.assertEquals(r, status.FAIL_RDICTN_UNCERTAIN)
        self.assertEquals(l, None)

    def test_read_dict_node_multi_ambiguous(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_node()
        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)
        i, r = self.mvs.create_edge(a, g)
        self.assertEquals(r, status.SUCCESS)
        j, r = self.mvs.create_edge(i, c)
        self.assertEquals(r, status.SUCCESS)

        l, r = self.mvs.read_dict_node(a, c)
        self.assertEquals(r, status.FAIL_RDICTN_AMBIGUOUS)
        self.assertEquals(l, None)
    """
