import unittest
from modelverse_state.main import ModelverseState

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

    def test_create_edge_invalid_source(self):
        a = -1
        b = self.mvs.create_node()
        assert b != None

        edge = self.mvs.create_edge(a, b)
        assert edge == None

    def test_create_edge_invalid_target(self):
        b = -1
        a = self.mvs.create_node()
        assert a != None

        edge = self.mvs.create_edge(a, b)
        assert edge == None

    def test_create_edge_invalid_both(self):
        a = -1
        b = -1
        edge = self.mvs.create_edge(a, b)
        assert edge == None

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

        edge = self.mvs.create_edge(a, b)
        assert edge != None
        assert edge > a
        assert edge > b

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

        edge1 = self.mvs.create_edge(a, b)
        assert edge1 != None
        assert edge1 > a
        assert edge1 > b

        edge2 = self.mvs.create_edge(a, b)
        assert edge2 != None
        assert edge2 > a
        assert edge2 > b

        assert edge1 != edge2

    def test_create_edge_many(self):
        v = set()
        for i in range(1000):
            a = self.mvs.create_node()
            assert a != None
            b = self.mvs.create_node()
            assert b != None

            edge = self.mvs.create_edge(a, b)
            assert edge != None
            assert edge > a
            assert edge > b

            v.add(edge)
        assert len(v) == 1000

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

        edge1 = self.mvs.create_edge(a, b)
        assert edge1 != None
        assert edge1 > a
        assert edge1 > b

        edge2 = self.mvs.create_edge(edge1, b)
        assert edge2 != None
        assert edge2 > edge1
        assert edge2 > b

        assert edge1 != edge2

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

        edge1 = self.mvs.create_edge(a, b)
        assert edge1 != None
        assert edge1 > a
        assert edge1 > b

        edge2 = self.mvs.create_edge(a, edge1)
        assert edge2 != None
        assert edge2 > a
        assert edge2 > edge1

        assert edge1 != edge2

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

        edge1 = self.mvs.create_edge(a, b)
        assert edge1 != None
        assert edge1 > a
        assert edge1 > b

        edge2 = self.mvs.create_edge(a, b)
        assert edge2 != None
        assert edge2 > a
        assert edge2 > b

        assert edge1 != edge2

        edge3 = self.mvs.create_edge(edge1, edge2)
        assert edge3 != None
        assert edge3 > edge1
        assert edge3 > edge2

    def test_create_edge_loop_node(self):
        a = self.mvs.create_node()
        assert a != None

        edge = self.mvs.create_edge(a, a)
        assert edge != None
        assert edge > a

    def test_create_edge_loop_edge(self):
        a = self.mvs.create_node()
        assert a != None

        edge1 = self.mvs.create_edge(a, a)
        assert edge1 != None
        assert edge1 > a

        edge2 = self.mvs.create_edge(edge1, edge1)
        assert edge2 != None
        assert edge2 > a
        assert edge2 > edge1
