import unittest
from modelverse_state.main import ModelverseState

from modelverse_state import status

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

    def test_read_dict_keys_no_exists(self):
        l, r = self.mvs.read_dict_keys(100000)
        self.assertEquals(l, None)
        self.assertEquals(r, status.FAIL_RDICTKEYS_UNKNOWN)

    def test_read_dict_keys_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_keys(a)
        self.assertEquals(r, status.SUCCESS)
        self.assertEquals(set(l), set([c]))

    def test_read_dict_keys_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_keys(a)
        self.assertEquals(r, status.SUCCESS)
        self.assertEquals(set(l), set([c, h]))
