Fix the mutation tester for a range overlap check
Your task
An assistant's test suite for a date-range overlap library reports 97% line coverage, all green. Coverage shows the lines ran, not that a test would notice a wrong answer. So the team built a small mutation tester. It plants small faults in the overlap check, called mutants, and reports the ones the suite fails to notice.
An assistant wrote surviving_mutants(cases). It is in the editor. It has a bug. Find it and fix it.
Input and output:
cases: the suite's inputs, a list of rows. A full row is[a_start, a_end, b_start, b_end]: two ranges of integers. The list can be empty.- Return the names of the mutants that survive, as a list of strings.
Rules the tests check:
- Both ends of a range are included, so the range 1 to 3 holds 1, 2 and 3.
- Skip any row with fewer than 4 numbers. In a longer row, ignore every number after the fourth.
- The correct check: the ranges overlap when
a_start <= b_endandb_start <= a_end. Apply it exactly as written, even when a range's start is after its end. - The six mutants, each a wrong version of that check:
always_false: always false.always_true: always true.off_by_one:a_start <= b_end + 1andb_start <= a_end + 1.strict_left:a_start < b_endandb_start <= a_end.strict_right:a_start <= b_endandb_start < a_end.swap_and_or:a_start <= b_endorb_start <= a_end.
- A mutant is killed when at least one row gives a different answer under the mutant than under the correct check. Otherwise it survives.
- Return the survivors in alphabetical order, which is the order listed above. With no usable rows, all six survive.
Examples
surviving_mutants(cases: list[list[int]]) -> list[str]Example 1
Input
surviving_mutants([])Output
["always_false", "always_true", "off_by_one", "strict_left", "strict_right", "swap_and_or"]Example 2
Input
surviving_mutants([[1, 5, 3, 8]])Output
["always_true", "off_by_one", "strict_left", "strict_right", "swap_and_or"]Example 3
Input
surviving_mutants([[1, 5, 3, 8], [1, 2, 5, 6]])Output
["off_by_one", "strict_left", "strict_right"]