def test_intersect_basic(): proxies_a = [random_proxies() for _ in range(5)] proxies_b = [random_proxies() for _ in range(5)] common = [random_proxies() for _ in range(5)] g_a = EntityGraph() g_a.add_proxies(proxies_a) g_a.add_proxies(common) g_b = EntityGraph() g_b.add_proxies(proxies_b) g_b.add_proxies(common) g = EntityGraph.intersect(g_a, g_b) assert len(g) == len(common) assert all(p.id in g for p in common) assert all(p.id not in g for p in proxies_a) assert all(p.id not in g for p in proxies_b)
def test_intersect_merge(): proxies_a = [random_proxies() for _ in range(5)] proxies_b = [random_proxies() for _ in range(5)] common = [random_proxies() for _ in range(5)] g_a = EntityGraph() g_a.add_proxies(proxies_a) g_a.add_proxies(common) g_a.merge_proxies(proxies_a[0], common[0]) g_a.add_proxy(create_link([common[3]], [common[4]])) assert len(g_a) == 10 g_b = EntityGraph() g_b.add_proxies(proxies_b) g_b.add_proxies(common) g_b.merge_proxies(proxies_b[0], common[1]) assert len(g_b) == 9 g = EntityGraph.intersect(g_a, g_b) assert len(g) == len(common) + 2 + 1 # 2 -> merge, 1 -> edge assert all(p.id in g for p in common) assert proxies_a[0].id in g assert proxies_b[0].id in g assert len(g.get_proxy_data(proxies_a[0])) == 2 assert len(g.get_proxy_data(proxies_b[0])) == 2 assert all(p.id not in g for p in proxies_a[1:]) assert all(p.id not in g for p in proxies_b[1:]) node = g.get_node_by_proxy(common[3]) assert len(list(g.edges())) == 1 assert len(list(G.get_node_out_edges(node))) == 1