Fix graph unit test edge direction problem

This commit is contained in:
yangdx
2025-04-16 14:33:25 +08:00
parent 33e8b9f284
commit d370c0ae12

View File

@@ -744,16 +744,25 @@ async def test_graph_batch_operations(storage):
print(f"节点 {node3_id} 的出边: {node3_outgoing_edges}")
print(f"节点 {node3_id} 的入边: {node3_incoming_edges}")
# 检查是否包含机器学习来的边,以及到自然语言处理和计算机视觉的
has_edge_from_node2 = any(src == node2_id for src, _ in node3_incoming_edges)
has_edge_to_node4 = any(tgt == node4_id for _, tgt in node3_outgoing_edges)
has_edge_to_node5 = any(tgt == node5_id for _, tgt in node3_outgoing_edges)
# 检查是否包含机器学习自然语言处理和计算机视觉的连接(忽略方向)
has_connection_with_node2 = any(
(src == node2_id and tgt == node3_id) or (src == node3_id and tgt == node2_id)
for src, tgt in nodes_edges[node3_id]
)
has_connection_with_node4 = any(
(src == node3_id and tgt == node4_id) or (src == node4_id and tgt == node3_id)
for src, tgt in nodes_edges[node3_id]
)
has_connection_with_node5 = any(
(src == node3_id and tgt == node5_id) or (src == node5_id and tgt == node3_id)
for src, tgt in nodes_edges[node3_id]
)
assert (
has_edge_from_node2
), f"节点 {node3_id} 的边列表中应包含 {node2_id} 来的边"
assert has_edge_to_node4, f"节点 {node3_id} 的边列表中应包含 {node4_id}"
assert has_edge_to_node5, f"节点 {node3_id} 的边列表中应包含 {node5_id}"
has_connection_with_node2
), f"节点 {node3_id} 的边列表中应包含 {node2_id} 的连接"
assert has_connection_with_node4, f"节点 {node3_id} 的边列表中应包含 {node4_id}连接"
assert has_connection_with_node5, f"节点 {node3_id} 的边列表中应包含 {node5_id}连接"
print("无向图特性验证成功:批量获取的节点边包含所有相关的边(无论方向)")