Exemple #1
0
def test_same_relationship_will_overwrite():
    g = Graph()
    g.relate(10, "is more than", 4)
    g.relate(10, "is more than", 2)
    assert set(g.nodes()) == {2, 4, 10}
    assert len(list(g.match())) == 2
    g.relate(10, "is more than", 2)
    assert set(g.nodes()) == {2, 4, 10}
    assert len(list(g.match())) == 2
Exemple #2
0
def test_can_build_simple_graph():
    g = Graph()
    g.relate(10, "is more than", 4)
    g.relate(10, "is more than", 2)
    g.relate(10, "is less than", 20)
    g.relate(20, "is less than", 30)
    assert set(g.nodes()) == {2, 4, 10, 20, 30}
    assert len(list(g.match())) == 4
    assert len(list(g.match(10))) == 3
    assert len(list(g.match(20))) == 1
    assert len(list(g.match(30))) == 0
    assert len(list(g.match(None, "is less than"))) == 2
    assert len(list(g.match(None, "is more than"))) == 2
    assert len(list(g.match(None, "is equal to"))) == 0
    assert len(list(g.match(None, None, 2))) == 1
    assert len(list(g.match(None, None, 4))) == 1
    assert len(list(g.match(None, None, 20))) == 1
    assert len(list(g.match(None, None, 30))) == 1
    assert len(list(g.match(10, "is more than"))) == 2
    assert len(list(g.match(20, "is more than"))) == 0
    assert len(list(g.match(20, "is less than", 30))) == 1
    assert len(list(g.match(20, "is less than", 40))) == 0