~ubuntu-branches/ubuntu/vivid/python-igraph/vivid

« back to all changes in this revision

Viewing changes to igraph/test/games.py

  • Committer: Package Import Robot
  • Author(s): TANIGUCHI Takaki
  • Date: 2012-03-17 17:23:55 UTC
  • Revision ID: package-import@ubuntu.com-20120317172355-e9iki37igmxnlq38
Tags: upstream-0.5.4
ImportĀ upstreamĀ versionĀ 0.5.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import unittest
 
2
from igraph import *
 
3
 
 
4
class GameTests(unittest.TestCase):
 
5
    def testGRG(self):
 
6
        g = Graph.GRG(50, 0.2)
 
7
        self.failUnless(isinstance(g, Graph))
 
8
        g = Graph.GRG(50, 0.2, True)
 
9
        self.failUnless(isinstance(g, Graph))
 
10
        g, xs, ys = Graph.GRG(50, 0.2, True, True)
 
11
        self.failUnless(isinstance(g, Graph))
 
12
        self.failUnless(isinstance(xs, list))
 
13
        self.failUnless(isinstance(ys, list))
 
14
        self.failUnless(isinstance(Layout(zip(xs,ys)), Layout))
 
15
 
 
16
    def testForestFire(self):
 
17
        g=Graph.Forest_Fire(100, 0.1)
 
18
        self.failUnless(isinstance(g, Graph) and g.is_directed() == False)
 
19
        g=Graph.Forest_Fire(100, 0.1, directed=True)
 
20
        self.failUnless(isinstance(g, Graph) and g.is_directed() == True)
 
21
 
 
22
    def testRecentDegree(self):
 
23
        g=Graph.Recent_Degree(100, 5, 10)
 
24
        self.failUnless(isinstance(g, Graph))
 
25
 
 
26
    def testPreference(self):
 
27
        g=Graph.Preference(100, [1, 1], [[1, 0], [0, 1]])
 
28
        self.failUnless(isinstance(g, Graph) and len(g.clusters()) == 2)
 
29
 
 
30
        g=Graph.Preference(100, [1, 1], [[1, 0], [0, 1]], attribute="type")
 
31
        l=g.vs.get_attribute_values("type")
 
32
        self.failUnless(min(l) == 0 and max(l) == 1)
 
33
 
 
34
    def testAsymmetricPreference(self):
 
35
        g=Graph.Asymmetric_Preference(100, [[0, 1], [1, 0]], [[0, 1], [1, 0]])
 
36
        self.failUnless(isinstance(g, Graph) and len(g.clusters()) == 2)
 
37
 
 
38
        g=Graph.Asymmetric_Preference(100, [[0, 1], [1, 0]], [[1, 0], [0, 1]],\
 
39
                                      attribute="type")
 
40
        l=g.vs.get_attribute_values("type")
 
41
        l1=[i[0] for i in l]
 
42
        l2=[i[1] for i in l]
 
43
        self.failUnless(min(l1) == 0 and max(l1) == 1 and
 
44
                        min(l2) == 0 and max(l2) == 1)
 
45
 
 
46
        g=Graph.Asymmetric_Preference(100, [[0, 1], [1, 0]], [[1, 0], [0, 1]])
 
47
        self.failUnless(isinstance(g, Graph) and len(g.clusters()) == 1)
 
48
 
 
49
    def testWattsStrogatz(self):
 
50
        g=Graph.Watts_Strogatz(1, 20, 1, 0.2)
 
51
        self.failUnless(isinstance(g, Graph) and g.vcount()==20 and g.ecount()==20)
 
52
        
 
53
def suite():
 
54
    game_suite = unittest.makeSuite(GameTests)
 
55
    return unittest.TestSuite([game_suite])
 
56
 
 
57
def test():
 
58
    runner = unittest.TextTestRunner()
 
59
    runner.run(suite())
 
60
    
 
61
if __name__ == "__main__":
 
62
    test()
 
63