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
def test_is_related(): 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 g.is_related(10, "is less than", 20) assert not g.is_related(20, "is more than", 4)
def test_removal_of_non_existent_node_should_fail(): g = Graph() g.add(10) assert set(g.nodes()) == {10} try: g.remove(12) except KeyError: assert True else: assert False
def test_can_remove(): g = Graph() g.add(10) assert set(g.nodes()) == {10} g.remove(10) assert set(g.nodes()) == set()
def test_can_separate(): 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) g.separate(10, "is less than", 20) assert set(g.nodes()) == {2, 4, 10, 20, 30} assert len(list(g.match())) == 3 assert len(list(g.match(10))) == 2 assert len(list(g.match(20))) == 1 assert len(list(g.match(30))) == 0 assert len(list(g.match(None, "is less than"))) == 1 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))) == 0 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
def test_removal_of_related_node_should_fail(): g = Graph() g.relate(10, "is more than", 4) assert set(g.nodes()) == {4, 10} try: g.remove(10) except NotIsolatedError: assert True else: assert False g.separate(10, "is more than", 4) g.remove(10) assert set(g.nodes()) == {4}