如何解决问题(使用 Java 中的变异体进行测试)?

huangapple 未分类评论49阅读模式
英文:

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 &lt; 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 &lt; 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 &lt; 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?

huangapple
  • 本文由 发表于 2020年6月29日 03:42:37
  • 转载请务必保留本文链接:https://java.coder-hub.com/62627451.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定