示例#1
0
def ClusteringCoefNodesDontExist_test():
    G = Graph()
    G.add_nodes_from(Friends)
    G.add_edges_from(Relationships)
    obs = G.clustering_coef(['Lexa', 'Roy', 'Demmi'])
    exp = {}
    assert_equal(exp, obs)
示例#2
0
def clustCoefempty_test():
    G = Graph()
    G.add_nodes_from(Friends)
    G.add_edges_from(Relationships)
    # give an empty list
    obs = G.clustering_coef(node_list=[])
    exp = {}
    assert_equal(exp, obs)
示例#3
0
def emptyEdges_test():
    G = Graph()
    G.add_nodes_from(Friends)
    G.add_edges_from(Relationships)
    # test "edges" when given a string and not a list of strings
    obs = G.edges('Alex')
    exp = [['Alex', 'Julie'], ['Alex', 'Michael'], ['Alex', 'Ved']]
    assert_equal(exp, obs)
示例#4
0
def degreeNodeList():
    G = Graph()
    G.add_nodes_from(Friends)
    G.add_edges_from(Relationships)
    # give and empty list
    obs = G.degree(node_L=[])
    exp = False
    assert_equal(exp, obs)
示例#5
0
def hasNodeEmpty_test():
    G = Graph()
    G.add_nodes_from(Friends)
    G.add_edges_from(Relationships)
    # given an empty list to "has_node" should return empty list
    exp = False
    obs = G.has_node([])
    assert_equal(exp, obs)
示例#6
0
def neighborsNoNode_test():
    G = Graph()
    G.add_nodes_from(Friends)
    G.add_edges_from(Relationships)
    # give empty list
    obs = G.neighbors([])
    # need to figure how to capture standard out
    exp = False
    assert_equal(exp, obs)
示例#7
0
def removeEmptyStr_test():
    # try to remove a node but user gives an empty string
    G = Graph()
    G.add_nodes_from(Friends)
    G.add_edges_from(Relationships)
    G.remove_node('')
    exp = {'Alex', 'Julie', 'Rob', 'Ved', 'Michael', 'Mark', 'Jeff'}
    obs = G.nodes()
    assert_equal(exp, obs)
示例#8
0
def removePartEdge_test():
    G = Graph()
    G.add_nodes_from(Friends)
    G.add_edges_from(Relationships)
    exp = G.edges()
    # remove an edge but give a single part of the edge
    G.remove_edge(['Alex'])
    obs = G.edges()
    assert_equal(exp, obs)
示例#9
0
def removeEdgeMorethan2_test():
    G = Graph()
    G.add_nodes_from(Friends)
    G.add_edges_from(Relationships)
    # remove an edge but give three entries
    G.remove_edge(['Alex', 'Julie', 'Michael'])
    exp = 21
    obs = len(G.edges())
    assert_equal(exp, obs)
示例#10
0
def removeNodeSet_test():
    G = Graph()
    G.add_nodes_from(Friends)
    G.add_edges_from(Relationships)
    # try to remove an empty set
    G.remove_node({})
    exp = {'Alex', 'Julie', 'Rob', 'Ved', 'Michael', 'Mark', 'Jeff'}
    obs = G.nodes()
    assert_equal(exp, obs)
示例#11
0
def removeEmptylst_test():
    G = Graph()
    G.add_nodes_from(Friends)
    G.add_edges_from(Relationships)
    # try and remove an empty list
    G.remove_node(node=[])
    exp = {'Alex', 'Julie', 'Rob', 'Ved', 'Michael', 'Mark', 'Jeff'}
    obs = G.nodes()
    assert_equal(exp, obs)
示例#12
0
def relabelNodesUneven_test():
    G = Graph()
    G.add_nodes_from(Friends)
    G.add_edges_from(Relationships)
    Notsame = ['A', 'B', 'C', 'D', 'E', 'F']
    obs = relabel_nodes(G, Notsame)
    exp = False
    # get standard out
    assert_equal(exp, obs)
示例#13
0
def addNoEdge_test():
    G = Graph()
    G.add_nodes_from(Friends)
    G.add_edges_from(Relationships)
    exp = G.edges()
    # remove an edge but give an empty list
    G.remove_edge([])
    obs = G.edges()
    assert_equal(exp, obs)
示例#14
0
def numNode_test():
    # create a small graph
    G = Graph()
    G.add_nodes_from(Friends)
    G.add_edges_from(Relationships)

    exp = {'Alex', 'Julie', 'Rob', 'Ved', 'Michael', 'Mark', 'Jeff'}
    obs = G.nodes()
    assert_equal(exp, obs)
示例#15
0
def relabelNodesBlank_test():
    G = Graph()
    G.add_nodes_from(Friends)
    G.add_edges_from(Relationships)
    Blank = ['', '', '', '', '', '', '']
    # give a blank list, a list with stuff, but they are all the same
    # and are empty character strings
    obs = relabel_nodes(G, Blank)
    exp = {'': ['', '', '']}
    assert_equal(exp, obs)
示例#16
0
def Graph_setup():
    Friends = ['Alex', 'Julie', 'Rob', 'Ved', 'Michael', 'Mark', 'Jeff']
    Relationships = [['Alex', 'Julie'], ['Julie', 'Alex'], ['Alex', 'Michael'],
                     ['Michael', 'Alex'], ['Julie', 'Michael'],
                     ['Michael', 'Julie'], ['Mark', 'Michael'],
                     ['Michael', 'Mark'], ['Jeff', 'Mark'], ['Mark', 'Jeff'],
                     ['Ved', 'Michael'], ['Michael', 'Ved'], ['Alex', 'Ved'],
                     ['Ved', 'Alex'], ['Ved', 'Jeff'], ['Jeff', 'Ved'],
                     ['Ved', 'Rob'], ['Rob', 'Ved'], ['Julie', 'Rob'],
                     ['Rob', 'Julie'], ['Rob', 'Jeff'], ['Jeff', 'Rob']]
    G = Graph()
    G.add_nodes_from(Friends)
    G.add_edges_from(Relationships)
示例#17
0
def subgraphNoneNode_test():
    G = Graph()
    G.add_nodes_from(Friends)
    G.add_edges_from(Relationships)
    # A node in the subgraph list does not exist in "Nodes"
    sub_list = ['Alex', 'Michael', 'Julie', 'Matt']
    obs = subgraph(G, sub_list).G
    exp = {
        'Alex': ['Julie', 'Michael'],
        'Julie': ['Alex', 'Michael'],
        'Michael': ['Alex', 'Julie', 'Ved']
    }
    assert_equal(exp, obs)