def test_bipartite_V1_2V2_2E3(self): bException = False try: self.bipartite = generators.bipartite(1, 1, 1) except ValueError: bException = True self.assertTrue(self.bipartite is not None and bException is False)
def test_bipartite_V2_2V2_2E2(self): bException = False try: self.bipartite = generators.bipartite(1, 1, 2) except ValueError: bException = True self.assertTrue(self.bipartite is None and bException is True)
def test_bipartite_V1_1V2_1E3(self): bException = False try: self.bipartite = generators.bipartite(-1, -1, 1) except ValueError: bException = True self.assertTrue(self.bipartite is None and bException is True)
def test_bipartite_E_smaller_than_zero(self): exceptionWasRaised = False try: self.bipartiteGraph = bipartite(4, 4, -1.0) except: exceptionWasRaised = True self.assertTrue(exceptionWasRaised and self.bipartiteGraph is None)
def test_bipartite_V2_smaller_than_zero(self): exceptionWasRaised = False bipartiteGraph = None try: bipartiteGraph = bipartite(4, -1, 6) except: exceptionWasRaised = True self.assertTrue(exceptionWasRaised and bipartiteGraph is None)
def test_bipartite_E_greater_than_the_multiplication_of_V1_V2(self): exceptionWasRaised = False bipartiteGraph = None try: bipartiteGraph = bipartite(2, 2, 6) except: exceptionWasRaised = True self.assertTrue(exceptionWasRaised and bipartiteGraph is None)
def test_bipartite_E_smaller_than_the_multiplication_of_V1_V2(self): exceptionWasRaised = False bipartiteGraph = None try: bipartiteGraph = bipartite(4, 4, 6) except: exceptionWasRaised = True self.assertFalse(exceptionWasRaised and bipartiteGraph is not None)
def test_bipartite_V2_greater_than_V1_E_greater_than_zero(self): exceptionWasRaised = False bipartiteGraph = None try: bipartiteGraph = bipartite(1, 2, 6) except: exceptionWasRaised = True self.assertFalse(exceptionWasRaised and bipartiteGraph is not None)
def test_bipartite_E_equals_zero(self): exceptionWasRaised = False bipartiteGraph = None try: bipartiteGraph = bipartite(2, 4, 0) except: exceptionWasRaised = True self.assertFalse(exceptionWasRaised and bipartiteGraph is not None)
def test_bipartite_V2_equals_zero(self): exceptionWasRaised = False bipartiteGraph = None try: bipartiteGraph = bipartite(4, 0, 8) except: exceptionWasRaised = True self.assertTrue(exceptionWasRaised and bipartiteGraph is None)
def test_bipartite_E_between_G1(self): exceptionWasRaised = False try: self.bipartiteGraph = bipartite(2, 2, 6) except: exceptionWasRaised = True self.assertFalse(exceptionWasRaised and self.bipartiteGraph is not None)
def test_bipartite(self): for v1 in range(1, 3): for v2 in range(1, 3): for e in range(1, v1 * v2): graph = generators.bipartite(v1, v2, e) self.assertEqual(graph.V(), v1 + v2) # test V self.assertEqual(graph.E(), e) # test E #on va essayer d'extraire les noeuds en 2 sous-graphes bipartites vertices1 = [] vertices2 = [] edges = graph.edges() firstSet = list(edges[0]) vertices1.append(firstSet[0]) vertices2.append(firstSet[1]) for edge in edges: asList = list(edge) if (vertices1.count(asList[0]) > 0): #on s'assure les noeuds de l'arrete ne se trouvent pas dans le meme sous-ensemble self.assertEqual(vertices1.count(asList[1]), 0) if (vertices2.count(asList[1]) == 0): vertices2.append(asList[1]) elif (vertices2.count(asList[0]) > 0): #on s'assure les noeuds de l'arrete ne se trouvent pas dans le meme sous-ensemble self.assertEqual(vertices2.count(asList[1]), 0) if (vertices1.count(asList[1]) == 0): vertices1.append(asList[1])