When tests only exercise one branch of a multi-branch condition, negating the condition can redirect execution to a different branch while still producing a result that passes the assertion. Testing all branches and asserting exact values kills condition-negation mutants.
sign_of classifies a number as "positive", "negative", or "zero" using two chained conditions. clamp constrains a value to a range using two guards. Each if condition is a target for negate_condition().
The tests check only that sign_of(5) returns a string (type check) and that clamp(7, 5, 10) returns a number (type check). A negated condition may take a different branch but still return a string or a number.
negate_condition() on if (x > 0) produces if (!(x > 0)). For x = 5:
- Original: !(5 > 0) = FALSE → falls through to else if (x < 0) which is also FALSE → returns "zero".
- Actually: original if (5 > 0) = TRUE → returns "positive".
- Mutant: if (!(5 > 0)) = FALSE → checks else if (5 < 0) = FALSE → returns "zero".
is.character("zero") = TRUE — the type check passes for the mutated return value.
Assert the exact string returned for each branch. Covering all three cases ("positive", "negative", "zero") ensures that redirecting to a different branch fails the test.
When a condition-negation mutant survives, add tests for every branch of the condition and assert the exact return value for each case.
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.