File: test_homepage.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 (53 lines) | stat: -rw-r--r-- 1,526 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import unittest

from igraph import Graph, Layout


class HomepageExampleTests(unittest.TestCase):
    """Smoke tests for the Python examples found on the homepage to ensure
    that they do not break."""

    def testErdosRenyiComponents(self):
        g = Graph.Erdos_Renyi(n=300, m=250)
        colors = ["lightgray", "cyan", "magenta", "yellow", "blue", "green", "red"]
        components = g.components()
        for component in components:
            color = colors[min(6, len(components) - 1)]
            g.vs[component]["color"] = color

        # No plotting here, but we calculate the FR layout
        g.layout("fr")

    def testKautz(self):
        g = Graph.Kautz(m=3, n=2)
        g.get_adjacency()
        # Plotting omitted

    def testMSTofGRG(self):
        def distance(p1, p2):
            return ((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2) ** 0.5

        g = Graph.GRG(100, 0.2)
        layout = Layout(list(zip(g.vs["x"], g.vs["y"])))

        weights = [distance(layout[edge.source], layout[edge.target]) for edge in g.es]
        max_weight = max(weights)
        g.es["width"] = [6 - 5 * weight / max_weight for weight in weights]
        g.spanning_tree(weights)
        # Plotting omitted


def suite():
    homepage_example_suite = unittest.defaultTestLoader.loadTestsFromTestCase(
        HomepageExampleTests
    )
    return unittest.TestSuite([homepage_example_suite])


def test():
    runner = unittest.TextTestRunner()
    runner.run(suite())


if __name__ == "__main__":
    test()