Statistics
| Branch: | Revision:

iof-tools / networkxMiCe / networkx-master / networkx / algorithms / assortativity / tests / test_pairs.py @ 5cef0f13

History | View | Annotate | Download (3.93 KB)

1
#!/usr/bin/env python
2
from nose.tools import *
3
import networkx as nx
4
from base_test import BaseTestAttributeMixing, BaseTestDegreeMixing
5

    
6

    
7
class TestAttributeMixingXY(BaseTestAttributeMixing):
8

    
9
    def test_node_attribute_xy_undirected(self):
10
        attrxy = sorted(nx.node_attribute_xy(self.G, 'fish'))
11
        attrxy_result = sorted([('one', 'one'),
12
                                ('one', 'one'),
13
                                ('two', 'two'),
14
                                ('two', 'two'),
15
                                ('one', 'red'),
16
                                ('red', 'one'),
17
                                ('blue', 'two'),
18
                                ('two', 'blue')
19
                                ])
20
        assert_equal(attrxy, attrxy_result)
21

    
22
    def test_node_attribute_xy_undirected_nodes(self):
23
        attrxy = sorted(nx.node_attribute_xy(self.G, 'fish',
24
                                             nodes=['one', 'yellow']))
25
        attrxy_result = sorted([
26
        ])
27
        assert_equal(attrxy, attrxy_result)
28

    
29
    def test_node_attribute_xy_directed(self):
30
        attrxy = sorted(nx.node_attribute_xy(self.D, 'fish'))
31
        attrxy_result = sorted([('one', 'one'),
32
                                ('two', 'two'),
33
                                ('one', 'red'),
34
                                ('two', 'blue')
35
                                ])
36
        assert_equal(attrxy, attrxy_result)
37

    
38
    def test_node_attribute_xy_multigraph(self):
39
        attrxy = sorted(nx.node_attribute_xy(self.M, 'fish'))
40
        attrxy_result = [('one', 'one'),
41
                         ('one', 'one'),
42
                         ('one', 'one'),
43
                         ('one', 'one'),
44
                         ('two', 'two'),
45
                         ('two', 'two')
46
                         ]
47
        assert_equal(attrxy, attrxy_result)
48

    
49
    def test_node_attribute_xy_selfloop(self):
50
        attrxy = sorted(nx.node_attribute_xy(self.S, 'fish'))
51
        attrxy_result = [('one', 'one'),
52
                         ('two', 'two')
53
                         ]
54
        assert_equal(attrxy, attrxy_result)
55

    
56

    
57
class TestDegreeMixingXY(BaseTestDegreeMixing):
58

    
59
    def test_node_degree_xy_undirected(self):
60
        xy = sorted(nx.node_degree_xy(self.P4))
61
        xy_result = sorted([(1, 2),
62
                            (2, 1),
63
                            (2, 2),
64
                            (2, 2),
65
                            (1, 2),
66
                            (2, 1)])
67
        assert_equal(xy, xy_result)
68

    
69
    def test_node_degree_xy_undirected_nodes(self):
70
        xy = sorted(nx.node_degree_xy(self.P4, nodes=[0, 1, -1]))
71
        xy_result = sorted([(1, 2),
72
                            (2, 1), ])
73
        assert_equal(xy, xy_result)
74

    
75
    def test_node_degree_xy_directed(self):
76
        xy = sorted(nx.node_degree_xy(self.D))
77
        xy_result = sorted([(2, 1),
78
                            (2, 3),
79
                            (1, 3),
80
                            (1, 3)])
81
        assert_equal(xy, xy_result)
82

    
83
    def test_node_degree_xy_multigraph(self):
84
        xy = sorted(nx.node_degree_xy(self.M))
85
        xy_result = sorted([(2, 3),
86
                            (2, 3),
87
                            (3, 2),
88
                            (3, 2),
89
                            (2, 3),
90
                            (3, 2),
91
                            (1, 2),
92
                            (2, 1)])
93
        assert_equal(xy, xy_result)
94

    
95
    def test_node_degree_xy_selfloop(self):
96
        xy = sorted(nx.node_degree_xy(self.S))
97
        xy_result = sorted([(2, 2),
98
                            (2, 2)])
99
        assert_equal(xy, xy_result)
100

    
101
    def test_node_degree_xy_weighted(self):
102
        G = nx.Graph()
103
        G.add_edge(1, 2, weight=7)
104
        G.add_edge(2, 3, weight=10)
105
        xy = sorted(nx.node_degree_xy(G, weight='weight'))
106
        xy_result = sorted([(7, 17),
107
                            (17, 10),
108
                            (17, 7),
109
                            (10, 17)])
110
        assert_equal(xy, xy_result)