File: homepage.py

package info (click to toggle)
python-igraph 0.7.1.post6-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 2,288 kB
  • ctags: 2,287
  • sloc: ansic: 20,069; python: 14,108; sh: 56; makefile: 9
file content (50 lines) | stat: -rw-r--r-- 1,501 bytes parent folder | download | duplicates (2)
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
import unittest

from igraph import *

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
        fr = g.layout("fr")

    def testKautz(self):
        g = Graph.Kautz(m=3, n=2)
        adj = 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(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]
        mst = g.spanning_tree(weights)
        # Plotting omitted

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

def test():
    runner = unittest.TextTestRunner()
    runner.run(suite())
    
if __name__ == "__main__":
    test()