Example #1
0
def test_merge_entities():
    x = Entity('x',[1,2,3],weight=1,color='r')
    y = Entity('y',[2,3,4],weight=3)
    z = Entity.merge_entities('z',x,y)
    assert z.uidset == set([1,2,3,4])
    assert z.weight == 3
    assert z.color == 'r'
Example #2
0
def test_merge_entities():
    x = Entity("x", [1, 2, 3], weight=1, color="r")
    y = Entity("y", [2, 3, 4], weight=3)
    z = Entity.merge_entities("z", x, y)
    assert z.uidset == set([1, 2, 3, 4])
    assert z.weight == 3
    assert z.color == "r"
Example #3
0
def test_entity_depth():
    e1 = Entity("e1")
    e2 = Entity("e2", [e1])
    e3 = Entity("e3", [e2])
    e4 = Entity("e4", [e3, e1])
    assert e4.depth() == 3
    e3.remove(e2)
    assert e4.depth() == 1
Example #4
0
def test_entity_add():
    # add an element with property
    ent = Entity("e", {"A", "C", "K"})
    ent.add(Entity("D", [1, 2, 3], color="red"))
    assert ent.size() == 4
    assert len(ent.children) == 3
    assert 2 in ent["D"].elements
    assert ent["D"].color == "red"
Example #5
0
def test_entity_depth():
    e1 = Entity('e1')
    e2 = Entity('e2',[e1])
    e3 = Entity('e3',[e2])
    e4 = Entity('e4',[e3,e1])
    assert e4.depth() == 3
    e3.remove(e2)
    assert e4.depth() == 1
Example #6
0
def test_entity_add():
    ### add an element with property
    ent = Entity('e',{'A', 'C', 'K'})
    ent.add(Entity('D',[1,2,3],color='red'))
    assert ent.size() == 4
    assert len(ent.children) == 3
    assert 2 in ent['D'].elements
    assert ent['D'].color == 'red'
Example #7
0
def test_add_and_merge_properties():
    ### assert that adding an existing entity will not overwrite
    e1 = Entity('e1',{'A', 'C', 'K'})
    e2 = Entity('C', w=5)
    e1.add(e2)
    assert e1['C'].w == 5
    ent3 = Entity('C')
    e1.add(ent3)
    assert e1['C'].w ==5
Example #8
0
def test_add_no_overwrite():
    ## adding and entity of the same name as an existing entity
    ## only updates properties
    e1 = Entity('e1',{'A','C','K'})
    e2 = Entity('C', ['X'], w=5)
    assert 'X' in e2.elements
    e1.add(e2)
    assert 'X' not in e1['C']
    assert e1['C'].w == 5
Example #9
0
def test_add_no_overwrite():
    # adding and entity of the same name as an existing entity
    # only updates properties
    e1 = Entity("e1", {"A", "C", "K"})
    e2 = Entity("C", ["X"], w=5)
    assert "X" in e2.elements
    e1.add(e2)
    assert "X" not in e1["C"]
    assert e1["C"].w == 5
Example #10
0
def test_add_and_merge_properties():
    # assert that adding an existing entity will not overwrite
    e1 = Entity("e1", {"A", "C", "K"})
    e2 = Entity("C", w=5)
    e1.add(e2)
    assert e1["C"].w == 5
    ent3 = Entity("C")
    e1.add(ent3)
    assert e1["C"].w == 5
Example #11
0
def test_entity_no_self_reference():
    # confirm entity may not add itself.
    ent = Entity("e", {"A", "C", "K"})
    with pytest.raises(HyperNetXError) as excinfo:
        ent.add(Entity("e"))
    assert "Self reference" in str(excinfo.value)
    with pytest.raises(HyperNetXError) as excinfo2:
        ent.add(ent)
    assert "Self reference" in str(excinfo2.value)
Example #12
0
def test_entity_no_self_reference():
    ### confirm entity may not add itself.
    ent = Entity('e',{'A', 'C', 'K'})
    with pytest.raises(HyperNetXError) as excinfo:
        ent.add(Entity('e'))
    assert 'Self reference' in str(excinfo.value)
    with pytest.raises(HyperNetXError) as excinfo2:
        ent.add(ent)
    assert 'Self reference' in str(excinfo2.value)
Example #13
0
def test_entity_construct_from_entity(triloop):
    e1 = Entity("e1", elements=triloop.edgedict)
    e2 = Entity("e2", entity=e1)
    e3 = Entity("e3", entity=e2, elements={"Z": "A"})
    assert e1 != e2
    assert e1.elements == e2.elements
    assert e1.children == e3.children
    assert e1.elements != e3.elements
    with pytest.raises(HyperNetXError):
        e4 = Entity("e1", entity=e1)
Example #14
0
def test_add_node_to_edge(seven_by_six):
    sbs = seven_by_six
    H = Hypergraph(sbs.edgedict)
    assert H.shape == (7, 6)
    # add node not already in hypergraph to edge
    # alreadyin hypergraph
    node = Entity('B')
    edge = H.edges['P']
    H.add_node_to_edge(node, edge)
    assert H.shape == (8, 6)
    # add edge with nodes already in hypergraph
    H.add_edge(Entity('Z', ['A', 'B']))
    assert H.shape == (8, 7)
    # add edge not in hypergraph with nodes not in hypergraph
    H.add_edge(Entity('Y', ['M', 'N']))
    assert H.shape == (10, 8)
Example #15
0
def test_add_node_to_edge(seven_by_six):
    sbs = seven_by_six
    H = Hypergraph(sbs.edgedict)
    assert H.shape == (7, 6)
    # add node not already in hypergraph to edge
    # alreadyin hypergraph
    node = Entity("B")
    edge = H.edges["P"]
    H.add_node_to_edge(node, edge)
    assert H.shape == (8, 6)
    # add edge with nodes already in hypergraph
    H.add_edge(Entity("Z", ["A", "B"]))
    assert H.shape == (8, 7)
    # add edge not in hypergraph with nodes not in hypergraph
    H.add_edge(Entity("Y", ["M", "N"]))
    assert H.shape == (10, 8)
Example #16
0
def test_entity_constructor():
    ent = Entity("edge", {"A", "C", "K"})
    assert ent.uid == "edge"
    assert ent.size() == 3
    assert len(ent.uidset) == 3
    assert len(ent.children) == 0
    assert isinstance(ent.incidence_dict["A"], set)
    assert "A" in ent
Example #17
0
def test_entity_constructor():
    ent = Entity('edge',{'A', 'C', 'K'})
    assert ent.uid == 'edge'
    assert ent.size() == 3
    assert len(ent.uidset) == 3
    assert len(ent.children) == 0
    assert isinstance(ent.incidence_dict['A'],set)
    assert 'A' in ent
Example #18
0
def test_entity_set():
    eset = EntitySet('eset1', {'A', 'C', 'K'})
    eset2 = eset.clone('eset2')
    assert eset.elements == eset2.elements
    assert len(eset) == 3
    assert eset.uid == 'eset1'
    assert len(eset.children) == 0
    with pytest.raises(HyperNetXError) as excinfo:
        eset2.add(Entity('Z',['A','C','B']))
    assert 'Fails the bipartite condition' in str(excinfo.value)
Example #19
0
def test_entity_set():
    eset = EntitySet("eset1", {"A", "C", "K"})
    eset2 = eset.clone("eset2")
    assert eset.elements == eset2.elements
    assert len(eset) == 3
    assert eset.uid == "eset1"
    assert len(eset.children) == 0
    with pytest.raises(HyperNetXError) as excinfo:
        eset2.add(Entity("Z", ["A", "C", "B"]))
    assert "Fails the bipartite condition" in str(excinfo.value)
Example #20
0
def test_equality():
    ## Different uids, elements generated differently
    e1 = Entity('e1',[1,2,3])
    e2 = Entity('e2',[1,2,3])
    assert not e1 == e2
    assert not e1[1] == e2[1]
    ## Different uids, elements generated the same
    elts = [Entity(uid) for uid in [1,2,3]]
    e1 = Entity('e1',elts)
    e2 = Entity('e2',elts)
    assert not e1==e2
    assert e1[1]==e2[1]
    ## Different properties only
    e1 = Entity('e1',elts)
    e2 = Entity('e1',elts,weight=1)
    assert not e1==e2
Example #21
0
def test_entity_from_dict_mixed_types():
    e1 = Entity("e1", [2])
    d = {"e1": e1, "e2": [5]}
    e3 = Entity("e3", d)
    assert 2 in e3.children
Example #22
0
def test_static_hypergraph_constructor_entity(seven_by_six):
    sbs = seven_by_six
    E = Entity('sbs', sbs.edgedict)
    H = Hypergraph(E, static=True)
    assert H.isstatic
    assert 'A' in H.edges.incidence_dict['P']
Example #23
0
def test_entity_from_dict_mixed_types():
    e1 = Entity('e1',[2])
    d = {'e1':e1, 'e2':[5]}
    e3 = Entity('e3',d)
    assert 2 in e3.children
Example #24
0
def test_entity_remove():
    ent = Entity('e',{'A', 'C', 'K'})
    assert ent.size() == 3
    ent.remove('A')
    assert ent.size() == 2
Example #25
0
def test_entity_remove():
    ent = Entity("e", {"A", "C", "K"})
    assert ent.size() == 3
    ent.remove("A")
    assert ent.size() == 2