Statistics
| Branch: | Revision:

iof-tools / networkxMiCe / networkx-master / networkx / generators / tests / test_duplication.py @ 5cef0f13

History | View | Annotate | Download (2.25 KB)

1
# -*- encoding: utf-8 -*-
2
# test_duplication.py - unit tests for the generators.duplication module
3
#
4
# Copyright 2010-2019 NetworkX developers.
5
#
6
# This file is part of NetworkX.
7
#
8
# NetworkX is distributed under a BSD license; see LICENSE.txt for more
9
# information.
10
"""Unit tests for the :mod:`networkx.generators.duplication` module.
11

12
"""
13
from nose.tools import assert_equal
14
from nose.tools import assert_raises
15
from nose.tools import raises
16

    
17
from networkx.exception import NetworkXError
18
from networkx.generators.duplication import duplication_divergence_graph
19
from networkx.generators.duplication import partial_duplication_graph
20

    
21

    
22
class TestDuplicationDivergenceGraph(object):
23
    """Unit tests for the
24
    :func:`networkx.generators.duplication.duplication_divergence_graph`
25
    function.
26

27
    """
28

    
29
    def test_final_size(self):
30
        G = duplication_divergence_graph(3, 1)
31
        assert_equal(len(G), 3)
32
        G = duplication_divergence_graph(3, 1, seed=42)
33
        assert_equal(len(G), 3)
34

    
35
    @raises(NetworkXError)
36
    def test_probability_too_large(self):
37
        duplication_divergence_graph(3, 2)
38

    
39
    @raises(NetworkXError)
40
    def test_probability_too_small(self):
41
        duplication_divergence_graph(3, -1)
42

    
43

    
44
class TestPartialDuplicationGraph(object):
45
    """Unit tests for the
46
    :func:`networkx.generators.duplication.partial_duplication_graph`
47
    function.
48

49
    """
50

    
51
    def test_final_size(self):
52
        N = 10
53
        n = 5
54
        p = 0.5
55
        q = 0.5
56
        G = partial_duplication_graph(N, n, p, q)
57
        assert_equal(len(G), N)
58
        G = partial_duplication_graph(N, n, p, q, seed=42)
59
        assert_equal(len(G), N)
60

    
61
    def test_initial_clique_size(self):
62
        N = 10
63
        n = 10
64
        p = 0.5
65
        q = 0.5
66
        G = partial_duplication_graph(N, n, p, q)
67
        assert_equal(len(G), n)
68

    
69
    @raises(NetworkXError)
70
    def test_invalid_initial_size(self):
71
        N = 5
72
        n = 10
73
        p = 0.5
74
        q = 0.5
75
        G = partial_duplication_graph(N, n, p, q)
76
        assert_equal(len(G), n)
77

    
78
    def test_invalid_probabilities(self):
79
        N = 1
80
        n = 1
81
        for p, q in [(0.5, 2), (0.5, -1), (2, 0.5), (-1, 0.5)]:
82
            args = (N, n, p, q)
83
            assert_raises(NetworkXError, partial_duplication_graph, *args)