Skip to content

Supported Mutations

Oli Wennell edited this page Apr 23, 2019 · 6 revisions

Fettle supports the following mutations:

  • Conditional Operator

  • Equality Operators

  • Increment/Decrement Operators

  • Logical Operators

  • Mathematical Operators

  • Mathematical Assignment Operators

  • Relational Operators

  • If Statement Condition

  • Null-Coalescing Expressions

Conditional Operator

Swaps the left-hand and right-hand expressions of a conditional operator:

E.g.

var x = isEnabled ? 10 : 0;
mutates to:
var x = isEnabled ? 0 : 10;

Equality Operators

Inverts equality operators: ==, !=

E.g.

var b = a == 10;
mutates to:
var b = a != 10;

Increment/decrement Operators

Negates increment and decrement operators: a`, `a--`, `a, --a

E.g.

for (int i = 0; i < 10; ++a)
mutates to:
for (int i = 0; i < 10; --a)

Logical Operators

Inverts logical operators: &&, ||

E.g.

var c = a && b;
mutates to:
var c = a || b;

Mathematical Operators

Swaps mathematical operators: +, -, *, /, %

E.g.

var c = a + b;
mutates to:
var c = a - b;

Mathematical Assignment Operators

Swaps mathematical assignment operators: +=, -=, *=, /=, %=

E.g.

a += 3;
mutates to:
a -= 3;

Relational Operators

Swaps relational operators: >, >=, <,

E.g.

for (int i = 0; i < 10; ++a)
mutates to:
for (int i = 0; i <= 10; ++a)

If Statement Condition

Negates the condition of if statements.

E.g. if (x) mutates to if (!x).

E.g. if (!x) mutates to if (x).

Null-Coalescing Expressions

Swaps the expressions of a null-coalescing operator (??)

E.g. a = b ?? c mutates to a = c ?? b