-
Notifications
You must be signed in to change notification settings - Fork 1
Mutation Operations
Some mutations are categorized as "strong" as it can break data dependencies, which can affect experiment results.
It mutates math operators as follows
-
+↔- -
*↔/ -
%→*
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;
}
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>
}
}
An example:
if (a == b) {
↓
if (true) {
It mutates conditional operators as follows
-
<=↔>= -
<↔> -
==↔!=
It mutates conditional operators as follows
-
<=↔< -
>=↔>
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);
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.
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.
It checks the method's return type, and replaces the return value with the type's default value.
They are:
-
byte,short,long,int→0 -
boolean→false -
float,double→0.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,int→1 -
boolean→true -
float,double→1.0 -
char→\u0001
public int foo(int a) {
return a;
}
↓
public int foo(int a) {
return 0;
}