Extract helpers and test the behavior mutation testing was missing.

The switches stay intact. The new tests pin option parsing, file selection, normalization, and which forms each language compares, so the survivors that remain are equivalent mutants.
This commit is contained in:
Robert C. Martin
2026-09-30 17:25:34 -05:00
parent fcf865759d
commit 6892667b34
9 changed files with 875 additions and 108 deletions
+22 -15
View File
@@ -41,6 +41,26 @@ def scan_files(
return entries, warnings
def _same_span(left: Entry, right: Entry) -> bool:
if left.file != right.file:
return False
if left.start_line != right.start_line:
return False
return left.end_line == right.end_line
def _duplicate_key(item: Duplicate):
score = -item.score
return (
score,
item.language,
item.left.file,
item.left.start_line,
item.right.file,
item.right.start_line,
)
def find_duplicates(entries: list[Entry], threshold: float) -> list[Duplicate]:
"""Pair forms of the same language. Each unordered pair is reported once."""
@@ -52,11 +72,7 @@ def find_duplicates(entries: list[Entry], threshold: float) -> list[Duplicate]:
for language, group in by_language.items():
for index, left in enumerate(group):
for right in group[index + 1 :]:
if (
left.file == right.file
and left.start_line == right.start_line
and left.end_line == right.end_line
):
if _same_span(left, right):
continue
score = jaccard(left.fingerprints, right.fingerprints)
if score < threshold:
@@ -71,14 +87,5 @@ def find_duplicates(entries: list[Entry], threshold: float) -> list[Duplicate]:
right_nodes=right.nodes,
)
)
found.sort(
key=lambda item: (
-item.score,
item.language,
item.left.file,
item.left.start_line,
item.right.file,
item.right.start_line,
)
)
found.sort(key=_duplicate_key)
return found