1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
import unittest
from igraph import Graph
def assert_valid_vertex_coloring(graph, coloring):
assert min(coloring) == 0
for edge in graph.es:
source, target = edge.tuple
assert source == target or coloring[source] != coloring[target]
class VertexColoringTests(unittest.TestCase):
def testGreedyVertexColoring(self):
g = Graph.Famous("petersen")
col = g.vertex_coloring_greedy()
assert_valid_vertex_coloring(g, col)
col = g.vertex_coloring_greedy("colored_neighbors")
assert_valid_vertex_coloring(g, col)
col = g.vertex_coloring_greedy("dsatur")
assert_valid_vertex_coloring(g, col)
def suite():
vertex_coloring_suite = unittest.defaultTestLoader.loadTestsFromTestCase(
VertexColoringTests
)
return unittest.TestSuite([vertex_coloring_suite])
def test():
runner = unittest.TextTestRunner()
runner.run(suite())
if __name__ == "__main__":
test()
|