Skip to content

Fix #44: group survivors into patterns - #52

Open
lefticus wants to merge 1 commit into
mainfrom
fix/issue-44-survivor-patterns
Open

lefticus wants to merge 1 commit into
mainfrom
fix/issue-44-survivor-patterns

Conversation

@lefticus

Copy link
Copy Markdown
Member

Fixes #44.

What changes

strain/patterns.py groups survivors that make the same kind of change in the same file into patterns, keeping groups of two or more. Each pattern names the test that would kill the whole group.

Kind Changes Advice
boundary <↔<=, >↔>= add a test exactly at the limit
negated-comparison <↔>=, >↔<= add a test on each side of the comparison
equality ==↔!= add a test where the values are equal and one where they differ
and-to-or &&→`
or-to-and `
arithmetic aor, asr assert the computed values, not just that there are results
  • One pattern per survivor: a survivor has one kind and one file, so it's in one primary pattern at most.
  • Hotspots: the functions with the most survivors, with their not_reached/not_detected split. They cut across patterns, so they're listed after them and aren't primary.
  • Where patterns appear:
    • the console, in a Patterns section before the action items;
    • summary.md and index.html, in a Patterns list;
    • report.json, in a top-level patterns array with each group's kind, primary, file, survivors, summary, advice and mutants (IDs). Hotspots have "primary": false, a function and the split.
  • README: a paragraph on reading patterns, the console example, and the report.json addition.

From the acceptance fixture below:

▸ Patterns
  · 4 survivors move a comparison's limit by one in sample.cpp: add a test exactly at the limit
  · 2 survivors turn `&&` into `||` in sample.cpp: add inputs that must be rejected, since the tests check only what is accepted
  · hotspot: is_identifier_start() in sample.cpp has 6 survivors: 6 not_reached

Left for later

Tests

  • End to end (the acceptance in the issue): a recogniser, (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_', whose test only checks that 'm', 'M' and '_' are accepted. I worked out by hand that this leaves 4 boundary survivors and 2 && → || survivors, and kills the rest. The test checks:
    • the console section and summary.md show exactly those two patterns, with those counts, then the 6-survivor hotspot;
    • report.json's primary patterns are [("boundary", 4), ("and-to-or", 2)], with no mutant in two of them;
    • index.html has the section.
  • tests/test_patterns.py:
    • grouping by kind and file, ignoring killed mutants and singletons;
    • every comparison change lands in exactly one pattern;
    • the hotspot split;
    • the JSON shape, including primary: false for hotspots.
  • python -W error -m pytest: 260 passed, 9 skipped. ruff format --check, ruff check and lizard are clean.

🤖 Generated with Claude Code

With dozens of survivors, the useful conclusions come from groups: twelve
`&&` -> `||` survivors in one file mean the tests check only what is
accepted. The new strain/patterns.py groups survivors that make the same
kind of change in the same file, keeping groups of two or more.

- Kinds: a comparison moved by one at its limit, an inverted comparison,
  == and != swapped, && to ||, || to &&, and arithmetic. Each comes with
  the test that would kill the whole group.
- Each survivor is in one primary pattern at most.
- Hotspots, the functions with the most survivors and their
  not_reached/not_detected split, are listed after the patterns.

The console shows a Patterns section before the action items, and
summary.md and index.html list them too. report.json gains a `patterns`
array with each group's kind, file, advice and mutant IDs; hotspots have
`"primary": false`.

Fixes #44.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Group survivors into patterns, not just one hint per survivor

1 participant