Statistics
| Branch: | Revision:

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

History | View | Annotate | Download (753 Bytes)

1
# -*- encoding: utf-8 -*-
2
# test_cographs.py - unit tests for cograph generators
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.cographs` module.
11

12
"""
13

    
14
import networkx as nx
15
from nose.tools import *
16

    
17

    
18
def test_random_cograph():
19
    n = 3
20
    G = nx.random_cograph(n)
21

    
22
    assert_equal(len(G), 2 ** n)
23

    
24
    #Every connected subgraph of G has diameter <= 2
25
    if nx.is_connected(G):
26
        assert_true(nx.diameter(G) <= 2)
27
    else:
28
        components = nx.connected_components(G)
29
        for component in components:
30
            assert_true(nx.diameter(G.subgraph(component)) <= 2)