Spaces:
Sleeping
Sleeping
File size: 1,212 Bytes
0908f70 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | """Unit tests for draft overlap / Jaccard helpers (library scan uses vector store)."""
from app.services.content_similarity import find_draft_overlaps, jaccard_similarity
def test_jaccard_identical() -> None:
assert jaccard_similarity("hello world", "hello world") == 1.0
def test_jaccard_disjoint() -> None:
assert jaccard_similarity("aaa bbb", "ccc ddd") == 0.0
def test_jaccard_partial() -> None:
sim = jaccard_similarity("slipped roof tiles on main hip", "main hip roof with slipped tiles")
assert sim > 0.4
def test_find_draft_overlaps_line() -> None:
text = "solid brick wall 275mm dpc visible slight crack nw corner"
peers = {"E4": "solid brick construction 275mm dpc hairline crack north west corner elevation"}
hits = find_draft_overlaps(text, "D", peers, line_threshold=0.25, block_threshold=0.55)
assert len(hits) >= 1
assert hits[0].other_section_code == "E4"
assert hits[0].overlap_kind in ("line", "block")
def test_find_draft_overlaps_skips_same_section() -> None:
text = "duplicate line about gutters blocked"
peers = {"E3": "duplicate line about gutters blocked"}
hits = find_draft_overlaps(text, "E3", peers)
assert hits == []
|