An assertion that only checks whether a result is numeric cannot detect arithmetic operator swaps. Different operators produce different numbers, but all of them are numeric. Asserting the exact expected value kills the mutant.
calculate(x, y) computes x * y + x. It contains both * and +, giving arithmetic operator mutators two targets to swap.
The test asserts only that the result of calculate(2, 3) is numeric. Any arithmetic expression on two numbers returns a number, so is.numeric() passes for the original and all mutants.
* → / produces x / y + x. For x = 2, y = 3: 2/3 + 2 ≈ 2.67 — numeric. + → - produces x * y - x. For the same inputs: 2*3 - 2 = 4 — also numeric. Both mutants satisfy is.numeric().
Assert the exact expected value. calculate(2, 3) should equal 2 * 3 + 2 = 8. The mutants return ≈ 2.67 and 4 respectively — neither equals 8, so both are killed.
When an arithmetic mutant survives, replace type or property checks with
expect_equaland an exact numeric value computed by hand.
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.