Skip to content

Mutation Operations

Boh Cheng Hin edited this page Nov 8, 2022 · 13 revisions

Strong Mutations

Some mutations are categorized as "strong" as it can break data dependencies, which can affect experiment results.

Mutations Strong
Replacing math operators
Replacing loops with if statements
Conditional negation
Conditional boundaries
java.lang.Math mutation
Replacing variables with another of the same type
Setting condition in if statement to true
Replace return value with an argument of same type
Removal of all statements within curly braces
Replace return value with default value

Supported mutations

Replacing math operators

It mutates math operators as follows

  • +-
  • */
  • %*

Replacing variables with another of the same type

After finding a variable usage to replace (e.g. b in int a = b + c;), it identifies its type, and finds all variable declarations that occurred before the chosen variable, that are of the same type.
It randomly chooses a variable, and replaces the variable used in the statement.
An example is shown below, where the a used in the if statement is replace with b:

int b = 0;
int a = b;
if (condition) {
    int c = a;
}

int b = 0;
int a = b;
if (condition) {
    int c = b;
}

Replacing loops with if statements

It takes the loop condition, and creates an if statement with the loop condition. The loop body becomes the if statement's body.
For loops has more steps. The entire if statement is wrapped in an "if true" block, as it can contain variable initialization, e.g. int i = 0;.

for (int i = 0; i < n; i++) {
    <body>
}

if (true) {
    int i = 0;
    if (i < n) {
        <body>
    }
}

Setting condition in if statement to true

An example:

if (a == b) {

if (true) {

Conditional negation

It mutates conditional operators as follows

  • <=>=
  • <>
  • ==!=

Conditional boundaries

It mutates conditional operators as follows

  • <=<
  • >=>

java.lang.Math mutation

Replaces Math method invocations with another Math method with same arguments and return type. For example

double a = Math.pow(1,2);

double a = Math.addExact(1,2);

Replace return value with an argument of same type

public int foo(int a) {
    return 0;
}

public int foo(int a) {
    return a;
}

This mutation can help in creating data dependencies between the user defined inputs and test case outputs, which helps in debugging experimentation.

Removal of all statements within curly braces

It removes all statements found in curly brace blocks. For instance, method bodies, if statement bodies, loop bodies, etc.
An example:

if (condition) {
    int a = b;
    b++;
}

if (condition) {
}

However, this mutation can lead to compilation errors. Checks are done to prevent this.
Below are cases where block removal is skipped.

  • Contains nested blocks (This is to simplify the logic for checking)
  • The block contains a return statement
  • Is a try block
  • Contains assignment but not the declaration of that variable. For example,
int a;
if (condition) {
    a = 0;
}

Clearing the block above would result in a not being declared.

Replace return value with default value

It checks the method's return type, and replaces the return value with the type's default value.
They are:

  • byte, short, long, int0
  • booleanfalse
  • float, double0.0
  • char\u0000
  • Object or array → null

If the return values are already the default, they will be replaced with the following.

  • byte, short, long, int1
  • booleantrue
  • float, double1.0
  • char\u0001
public int foo(int a) {
    return a;
}

public int foo(int a) {
    return 0;
}