资源简介
基于路径覆盖的自动化生成测试用例,含有三角形判断等近十个测试函数
代码片段和文件信息
package random;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Date;
import java.io.*;
import jxl.*;
import jxl.write.*;
//Random版本1(新适应值)
//8个benchmark:1三角形,2阶乘,3排序,4最大公约数,5中位数,6万年历,7tomorrow,8calculator 9commission 10premium
//11decision
//序号修改:1(344);2(121);3(1021);4(242);5(343);6(263);7(4105);8(21515);9(332);10(21110);
//11(4114)
public class Random1210 {
private static final int RUN = 1 ; //the number of the program run .
private static final int fun_num = 1 ; //the serial number of the target benchmark function.
private static final int R = 3 ; //the number of parameters of test case
private static final int PATHNUM = 4 ; //the number of the dependent paths
private static final int NODENUM = 4; //the number of the nodes in the target benchmark function.
private static final int MCN = R*1000;
private static final int col = 2 ;
static double start; //the beginning time of the program run
static double finish; //the finish time of the program run
static float[] coverage = new float[RUN];
static double[] runtime = new double[RUN];
static int[] case_num = new int[RUN];
public static void main(String[] args)
{
int[] lb = new int[R] ;
int[] ub = new int[R] ;
if( (fun_num == 1) || (fun_num == 2) || (fun_num == 3) || (fun_num == 4) || (fun_num == 5) || (fun_num == 9) || (fun_num == 11))
for(int j = 0 ; j < R ; j++ )
{
lb[j] = 1 ;
ub[j] = 100 ;
}
else if(fun_num == 6)
{
lb[0] = 1900 ;
ub[0] = Integer.MAX_VALUE ;
lb[1] = 1 ;
ub[1] = 12 ;
}
else if(fun_num == 7)
{
lb[0] = 1 ;
ub[0] = 7 ;
lb[1] = 1900 ;
ub[1] = Integer.MAX_VALUE ;
lb[2] = 1 ;
ub[2] = 12 ;
lb[3] = 1 ;
}
else if(fun_num == 8)
for(int j = 0 ; j < R ; j++ )
{
lb[j] = 1 ;
ub[j] = 200 ;
}
else //fun_num == 10
{
lb[0] = 1 ;
ub[0] = Integer.MAX_VALUE ;
lb[1] = 1 ;
ub[1] = 12 ;
}
for(int run = 0 ; run < RUN ; run++ )
{
int[] x = new int[R];
boolean[] statu = new boolean[PATHNUM]; //to mark whether the path has been covered.
int[][] solution = new int[PATHNUM][R];
int Path ;
int obj = 0 ;
Date mydate = new Date();
start= mydate.getTime(); //begin to calculate the time
while( obj < PATHNUM ) //case_num[run] <= MCN &&
{
for(int j = 0 ; j < R ; j++) //生成新的测试用例
{
double r0 = Math.random() ;
if(fun_num == 7 && j == 3)
{
if((x[2] == 4) || (x[2] == 6) || (x[2] == 9) || (x[2] == 11))
ub[3] = 30 ;
else if( (x[2] == 2) && (isRun(x[1])) )
ub[3] = 29 ;
else if( (x[2] == 2) && (!isRun(x[1])) )
ub[3] = 28 ;
else
ub[3] = 31 ;
}
x[j] = (int)Math.round( lb[j] + r0 * ( ub[j] - lb[j]) ) ;
- 上一篇:用Java语言编写简易学生管理系统
- 下一篇:Android Demo实现书架效果
评论
共有 条评论