Fix the surviving mutant report for a coverage push
Your task
An AI agent took the PricingEngine module to 91 percent test coverage, all green. Coverage shows which lines ran, not whether any test would notice a bug in them. So your team runs mutation testing: a tool plants small bugs called mutants, and a test that fails on a mutant kills it. The mutants nobody kills are the bugs the suite would ship.
An assistant wrote surviving_mutants(mutant_ids, kill_lines). It is in the editor. It has a bug. Find it and fix it.
Input and output:
mutant_ids: the ids of the planted mutants.kill_lines: the tool's report, one line per test, writtentest_name>id,id,.... The list after>can be empty.- Return the ids of the surviving mutants, in the order they first appear in
mutant_ids.
Rules the tests check:
- In a kill line, the killed ids are the items after the first
>, split on,, each with whitespace trimmed from both ends. Empty items are ignored. A line with no>kills nothing. - Trim whitespace from both ends of each entry in
mutant_ids. Skip an entry that is empty, and skip a repeat of an id already seen. - A mutant is killed when some killed id equals its id exactly, case included.
- Return every id that is not killed.
Examples
surviving_mutants(mutant_ids: list[str], kill_lines: list[str]) -> list[str]Example 1
Input
surviving_mutants(["m_lt_to_lte", "m_round_half_down", "m_discount_skip"], ["test_price_basic>m_lt_to_lte", "test_zero_quantity>", "test_snapshot_output>"])Output
["m_round_half_down", "m_discount_skip"]Example 2
Input
surviving_mutants(["m_lt_to_lte", "m_round_half_down"], ["test_boundary_price>m_lt_to_lte,m_round_half_down", "test_smoke>"])Output
[]Example 3
Input
surviving_mutants(["m_currency_floor"], ["test_calls_engine>m_ghost_mutant", "test_no_assertions>"])Output
["m_currency_floor"]