- SPipe_server_2026-10-30.zip 내용을 풀어서 등록 (압축 파일은 올리지 않음) - README에 데모 v2 서버 업데이트 순서 추가, 저장소에 없는 문서 목차 정리 - 패치내역을 docs/로 이동, _worklog.md 추가 - 임시 파일(backend/temp.*)과 API 키가 든 파일은 제외
47 lines
1.4 KiB
Python
47 lines
1.4 KiB
Python
from __future__ import annotations
|
|
|
|
import networkx as nx
|
|
import pytest
|
|
|
|
from blocksys.partition import partition
|
|
|
|
K_VALUES = [4, 6, 8]
|
|
|
|
|
|
@pytest.mark.parametrize("k", K_VALUES)
|
|
def test_node_preservation(weighted_graph, cfg, k):
|
|
labels = partition(weighted_graph, k, cfg)
|
|
assert set(labels.keys()) == set(weighted_graph.nodes)
|
|
|
|
|
|
@pytest.mark.parametrize("k", K_VALUES)
|
|
def test_block_connectivity(weighted_graph, cfg, k):
|
|
labels = partition(weighted_graph, k, cfg)
|
|
blocks: dict[int, list] = {}
|
|
for n, label in labels.items():
|
|
blocks.setdefault(label, []).append(n)
|
|
|
|
for label, nodes in blocks.items():
|
|
sub = weighted_graph.subgraph(nodes)
|
|
assert nx.is_connected(sub), f"block {label} is not a single connected component"
|
|
|
|
|
|
def test_reproducibility(weighted_graph, cfg):
|
|
labels1 = partition(weighted_graph, 6, cfg)
|
|
labels2 = partition(weighted_graph, 6, cfg)
|
|
assert labels1 == labels2
|
|
|
|
|
|
def test_k_too_large_raises(weighted_graph, cfg):
|
|
with pytest.raises(ValueError):
|
|
partition(weighted_graph, weighted_graph.number_of_nodes() + 1, cfg)
|
|
|
|
|
|
def test_louvain_method(weighted_graph, cfg):
|
|
cfg.partition.method = "louvain"
|
|
try:
|
|
labels = partition(weighted_graph, 6, cfg)
|
|
assert set(labels.keys()) == set(weighted_graph.nodes)
|
|
finally:
|
|
cfg.partition.method = "spectral"
|