import unittest
from modelverse_state.main import ModelverseState

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

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

        l = self.mvs.read_outgoing(b)
        assert l != None
        assert set(l) == set([])

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

        l = self.mvs.read_outgoing(a)
        assert l != None
        assert set(l) == set([c])

        l = self.mvs.read_outgoing(b)
        assert l != None
        assert set(l) == set([])

    def test_read_outgoing_node_multi(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(a, b)
        assert a != None
        assert b != None
        assert c != None
        assert d != None
        assert e != None

        l = self.mvs.read_outgoing(a)
        assert l != None
        assert set(l) == set([c, d, e])

        l = self.mvs.read_outgoing(b)
        assert l != None
        assert set(l) == set([])

    def test_read_outgoing_node_multi_others_unaffected(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(a, b)
        assert a != None
        assert b != None
        assert c != None
        assert d != None
        assert e != None

        f = self.mvs.create_node()
        assert f != None

        l = self.mvs.read_outgoing(a)
        assert l != None
        assert set(l) == set([c, d, e])

        l = self.mvs.read_outgoing(b)
        assert l != None
        assert set(l) == set([])

        l = self.mvs.read_outgoing(f)
        assert l != None
        assert set(l) == set([])

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

        l = self.mvs.read_outgoing(c)
        assert l != None
        assert set(l) == set([])

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

        l = self.mvs.read_outgoing(c)
        assert l != None
        assert set(l) == set([d])

        l = self.mvs.read_outgoing(d)
        assert l != None
        assert set(l) == set([])

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

        l = self.mvs.read_outgoing(c)
        assert l != None
        assert set(l) == set([d, e, f])

        l = self.mvs.read_outgoing(d)
        assert l != None
        assert set(l) == set([])

        l = self.mvs.read_outgoing(e)
        assert l != None
        assert set(l) == set([])

        l = self.mvs.read_outgoing(f)
        assert l != None
        assert set(l) == set([])

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

        l = self.mvs.read_outgoing(b)
        assert l != None
        assert set(l) == set([])

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

        l = self.mvs.read_outgoing(a)
        assert l != None
        assert set(l) == set([c])

        l = self.mvs.read_outgoing(b)
        assert l != None
        assert set(l) == set([])

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

        l = self.mvs.read_outgoing(a)
        assert l != None
        assert set(l) == set([c, d, e])

        l = self.mvs.read_outgoing(b)
        assert l != None
        assert set(l) == set([])

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

        f = self.mvs.create_nodevalue(1)
        assert f != None

        l = self.mvs.read_outgoing(a)
        assert l != None
        assert set(l) == set([c, d, e])

        l = self.mvs.read_outgoing(b)
        assert l != None
        assert set(l) == set([])

        l = self.mvs.read_outgoing(f)
        assert l != None
        assert set(l) == set([])
    
    def test_read_outgoing_node_deleted(self):
        b = self.mvs.create_node()
        assert b != None

        n = self.mvs.delete_node(b)
        assert n == None

        l = self.mvs.read_outgoing(b)
        assert l == None

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

        n = self.mvs.delete_node(b)
        assert n == None

        l = self.mvs.read_outgoing(b)
        assert l == None

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

        n = self.mvs.delete_edge(c)
        assert n == None

        l = self.mvs.read_outgoing(c)
        assert l == None
