File: test_coloring.py

package info (click to toggle)
python-igraph 0.11.8%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,480 kB
  • sloc: ansic: 24,545; python: 21,699; sh: 107; makefile: 35; sed: 2
file content (39 lines) | stat: -rw-r--r-- 970 bytes parent folder | download | duplicates (3)
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()