英文:
How to solve problem (testing with mutants in java)?
问题
我必须实现一个用于在代码中查找变异体的算法。从输入文件中,我需要读取一些代码,例如:
public static void main(String[] args){
int s = 0;
for (int i = 0; i < x.length; i++) {
s = s + x[i];
}
System.out.println(s);
}
我必须使用两个规则创建变异体:替换算术运算和替换相同类型的变量。
例如:在上面的代码中,我们有一行代码s=s+x[i];
,应将+号替换为-号,
所以第一个变异体将是:
public static void main(String[] args){
int s = 0;
for (int i = 0; i < x.length; i++) {
s = s - x[i];
}
System.out.println(s);
}
第二个变异体将是:
public static void main(String[] args){
int s = 0;
for (int i = 0; i < x.length; i++) {
s = s / x[i];
}
System.out.println(s);
}
以此类推,对于每个符号都要做同样的操作,对相同类型的变量进行替换也是一样的。
变异体必须写入输出文件。
我需要一个Java解决方案。请帮忙?
英文:
I have to implement algorithm for finding mutants in code. From input file, i have to reading some code for example;
public static void main(String[] args){
int s = 0;
for (int i = 0; i < x.length; i++) {
s = s + x[i];
}
System.out.println(s);
}
I have to create mutants using two rules: replacement of arithmetic operations and
replacement of variables of the same type.
For example: in the code above we have line with code s=s+x[i];
The + sign should be replaced by the - sign,
so the first mutant would be;
public static void main(String[] args){
int s = 0;
for (int i = 0; i < x.length; i++) {
s = s - x[i];
}
System.out.println(s);
}
Second mutant would be;
public static void main(String[] args){
int s = 0;
for (int i = 0; i < x.length; i++) {
s = s / x[i];
}
System.out.println(s);
}
And so for each sign. Do the same with replacement of variables of the same type.
Mutants must be written to the output file.
I need a solution in Java. Please help?
专注分享java语言的经验与见解,让所有开发者获益!
评论