def test_regular_when_product_of_V_and_k_is_not_even_should_raise_valueError( self): for nbVertices in range(3, 6): for k in range(0, nbVertices): if ((nbVertices * k) % 2 == 1): self.assertRaises(ValueError, generators.regular, nbVertices, k) else: generators.regular(nbVertices, k) # ne doit pas lancer d'erreur
def test_regular_V2K2(self): bException = False try: self.regular = generators.regular(1, 2) except ValueError: bException = True self.assertTrue(self.regular is not None and bException is False)
def test_regular_V1K2(self): bException = False try: self.regular = generators.regular(-1, -2) except ValueError: bException = True self.assertTrue(self.regular is None and bException is True)
def test_regular(self): for nbVertices in range(3, 6): for k in range(0, nbVertices): if ((nbVertices * k) % 2 == 0): graph = generators.regular(nbVertices, k) self.assertEqual(graph.V(), nbVertices) # test V self.assertEqual(graph.E(), k * nbVertices // 2) # test E #on compte le nombre d'arretes connectes a chaque noeud nbEdgesPerVertice = [0] * nbVertices for edge in graph.edges(): if (len(edge) == 1): #pour les noeuds qui pointent vers eux memes nbEdgesPerVertice[list(edge)[0]] += 2 else: for v in edge: nbEdgesPerVertice[v] += 1 #le graphe est regulier si chaque noeud possede #le meme nombre d'arrete et, dans notre cas, ce #nombre correspond a la valeur desiree for i in nbEdgesPerVertice: self.assertEqual(i, k)
def test_eulerianCycle_multiplication_V_K_is_pair(self): exceptionWasRaised = False try: self.regularGraph = regular(2, 4) except: exceptionWasRaised = True self.assertFalse(exceptionWasRaised and self.regularGraph is not None)
def test_eulerianCycle_K_smaller_than_zero(self): exceptionWasRaised = False try: self.regularGraph = regular(4, -1.0) except: exceptionWasRaised = True self.assertTrue(exceptionWasRaised and self.regularGraph is None)
def test_regular_V3K2VK1(self): exceptionWasRaised = False try: self.regularGraph = regular(4, 2) except Exception: exceptionWasRaised = True self.assertFalse( exceptionWasRaised, 'Exception was raised, method has not passed with V=4 and K=2')
def test_regular_VK2(self): exceptionWasRaised = False try: # Try to create a regular graph with V*K not even self.regularGraph = regular(3, 3) except Exception: exceptionWasRaised = True self.assertTrue( exceptionWasRaised, 'Exception was not raised, method has passed with VK=9')
def test_regular_K1(self): exceptionWasRaised = False try: # Try to create a regular graph with negative degree self.regularGraph = regular(3, -1) except Exception: exceptionWasRaised = True self.assertTrue( exceptionWasRaised, 'Exception was not raised, method has passed with K=-1')
def test_regular_V2(self): exceptionWasRaised = False try: # Try to create a regular graph with invalid numbers of vertices and degree self.regularGraph = regular(3, 3) except Exception: exceptionWasRaised = True self.assertTrue( exceptionWasRaised, 'Exception was not raised, method has passed with V=3 and K=3')
def test_regular_V1(self): exceptionWasRaised = False try: # Try to create a regular graph with negative number of vertices self.regularGraph = regular(-1, 2) except Exception: exceptionWasRaised = True self.assertTrue( exceptionWasRaised, 'Exception was not raised, method has passed with V=-1')