Exemplo n.º 1
0
Arquivo: AC_test.py Projeto: fx46/3430
 def test_eulerianCycle_V2E2(self):
     bException = False
     try:
         self.eulerianCycle = generators.eulerianCycle(2, 2)
     except:
         bException = True
     self.assertTrue(self.eulerianCycle is not None and bException is False)
Exemplo n.º 2
0
Arquivo: AC_test.py Projeto: fx46/3430
 def test_eulerianCycle_V2E1(self):
     bException = False
     try:
         self.eulerianCycle = generators.eulerianCycle(1, 0)
     except:
         bException = True
     self.assertTrue(self.eulerianCycle is None and bException is True)
Exemplo n.º 3
0
    def test_eulerianCycle_E_smaller_than_zero(self):
        exceptionWasRaised = True

        try:
            self.eulerianCycle = eulerianCycle(4, -1.0)
        except:
            exceptionWasRaised = True

        self.assertTrue(exceptionWasRaised and self.eulerianCycle is None)
    def test_eulerianCycle_E_equals_zero(self):
        exceptionWasRaised = False
        eulerianCycleGraph = None

        try:
            eulerianCycleGraph = eulerianCycle(4, 0)
        except:
            exceptionWasRaised = True

        self.assertTrue(exceptionWasRaised and eulerianCycleGraph is None)
    def test_eulerianCycle_V_and_E_greater_than_zero(self):
        exceptionWasRaised = False
        eulerianCycle = None

        try:
            eulerianCycle = eulerianCycle(4, 4)
        except:
            exceptionWasRaised = True

        self.assertFalse(exceptionWasRaised and eulerianCycle is not None)
    def test_eulerianCycle_E_is_smaller_than_zero(self):
        exceptionWasRaised = False
        eulerianCycleGraph = None

        try:
            eulerianCycleGraph = eulerianCycle(4, -1.0)
        except:
            exceptionWasRaised = True

        self.assertTrue(exceptionWasRaised and eulerianCycleGraph is None)
Exemplo n.º 7
0
    def test_eulerian_cycle(self):
        for nbVertices in range(4, 10):
            for nbEdges in range(4, nbVertices * (nbVertices - 1) // 4):

                graph = generators.eulerianCycle(nbVertices, nbEdges)
                self.assertEqual(graph.V(), nbVertices)
                self.assertEqual(graph.E(), nbEdges)

                # on compte combien d'arretes chaque noeud possede
                nbEdgesPerVertice = [0] * nbVertices

                for edge in graph.edges():
                    #pour les noeuds qui pointent vers eux memes
                    if (len(edge) == 1):
                        nbEdgesPerVertice[list(edge)[0]] += 2
                    else:
                        for v in edge:
                            nbEdgesPerVertice[v] += 1

                #un graphe est un cycle eulerien si et seulement si
                #chaque noeud possede un nombre pair d'arretes
                #(Theoreme d'Euler sur les cycles euleriens)
                for i in nbEdgesPerVertice:
                    self.assertTrue(i % 2 == 0)