博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
软件测试-----Graph Coverage作业
阅读量:5210 次
发布时间:2019-06-14

本文共 4743 字,大约阅读时间需要 15 分钟。

/*******************************************************      * Finds and prints n prime integers      * Jeff Offutt, Spring 2003      ******************************************************/     public static void printPrimes (int n)     {         int curPrime; // Value currently considered for primeness         int numPrimes; // Number of primes found so far.         boolean isPrime; // Is curPrime prime?         int [] primes = new int [MAXPRIMES]; // The list of prime numbers.                 // Initialize 2 into the list of primes.         primes [0] = 2;         numPrimes = 1;         curPrime = 2;         while (numPrimes < n)         {             curPrime++; // next number to consider ...             isPrime = true;             for (int i = 0; i <= numPrimes-1; i++)             { // for each previous prime.                 if (curPrime%primes[i]==0)                 { // Found a divisor, curPrime is not prime.                     isPrime = false;                     break; // out of loop through primes.                 }             }             if (isPrime)             { // save it!                 primes[numPrimes] = curPrime;                 numPrimes++;             }         } // End while                 // Print all the primes out.         for (int i = 0; i <= numPrimes-1; i++)         {             System.out.println ("Prime: " + primes[i]);         }     } // end printPrimes

(a).为printPrimes()方法画控制流图

(b).第二问其实就是设计一个错误使得t2=(n=5)比t1=(n=3)更容易发现错误

5>3,所以可以设计一个数组越界问题。

(c).测试路径访问连接while语句开始到for语句的边,二不通过while循环体,就是通过了CFG的2—>12这条边。

所以取n=1就能满足。

(d).第四问要求找出点覆盖、边覆盖和主路径覆盖的所有TR(测试需求)

点覆盖:{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}

边覆盖:{(1,2),(2,3),(2,12),(3,4),(4,5),(5,6),(6,7),(6,8),(7,5),(8,9),(5,9),(9,10),(9,11),(10,11),(11,2),(12,13),(13,14),(14,15),(15,13),(13,16)}

主路径覆盖:

TR= {[1,2,3,4,5,6,8,9,10,11],[1,2,3,4,5,6,8,9,11],[1,2,3,4,5,6,7],[1,2,3,4,5,9,10,11],[1,2,3,4,5,9,11],[1,2,12,13,16],[1,2,12,13,14,15],

[2,3,4,5,6,8,9,10,11,2],[2,3,4,5,6,8,9,11,2],[2,3,4,5,9,10,11,2],[2,3,4,5,9,11,2],

[3,4,5,6,8,9,10,11,2,12,13,16],[3,4,5,6,8,9,10,11,2,12,13,14,15],[3,4,5,6,8,9,11,2,12,13,16],[3,4,5,6,8,9,11,12,13,14,15],[3,4,5,9,10,11,2,12,13,16],[3,4,5,9,10,11,2,12,13,14,15],[3,4,5,9,11,2,12,13,16],[3,4,5,9,11,2,12,13,14,15],[3,4,5,6,8,9,10,11,2,3],[3,4,5,6,8,9,11,2,3],[3,4,5,9,10,11,2,3],[3,4,5,9,11,2,3],

[4,5,6,8,9,10,11,2,3,4],[4,5,6,8,9,11,2,3,4],[4,5,9,10,11,2,3,4],[4,5,9,11,2,3,4],

[5,6,8,9,10,11,2,3,4,5],[5,6,8,9,11,2,3,4,5],[5,9,10,11,2,3,4,5],[5,9,11,2,3,4,5],[5,6,7,5],

[6,8,9,10,11,2,3,4,5,6],[6,8,9,11,2,3,4,5,6],[6,7,5,6],[6,7,5,9,10,11,2,3,4,5,6],[6,7,5,9,11,2,3,4,5,6],[6,7,5,9,10,11,2,12,13,16],[6,7,5,9,10,11,2,14,15],[6,7,5,9,11,2,12,13,16],[6,7,5,9,11,2,14,15],

[7,5,6,7],[7,5,6,8,9,10,11,2,3,4],[7,5,6,8,9,11,2,3,4],[7,5,6,8,9,10,11,2,12,13,16],[7,5,6,8,9,11,2,12,13,16],[7,5,6,8,9,10,11,2,12,13,14,15],[7,5,6,8,9,11,2,12,13,14,15],

[8,9,10,11,2,3,4,5,6,8],[8,9,11,2,3,4,5,6,8],

[9,10,11,2,3,4,5,6,8,9],[9,11,2,3,4,5,6,8,9],

[10,11,2,3,4,5,6,8,9,10],[10,11,2,3,4,5,9,10],

[11,2,3,4,5,6,8,9,10,11],[11,2,3,4,5,9,10,11],[11,2,3,4,5,6,8,9,11],[11,2,3,4,5,9,11],

[13,14,15,13],[14,15,13,14],[14,15,13,16],[15,13,14,13],[15,13,16]}

5.Junit进行主路径覆盖测试

1 package triangle; 2  3 public class triangle { 4     public String typeOfTriangle (int a, int b,int c)  5     {  6         String type = null; 7         if(a+b>c && a+c>b && c+a>b){ 8             type = "scalene"; 9             if(a==b || a==c || b==c){10                 type="isosceles";11                 if(a==b && b==c)12                     type="equilateral";13             }14             return type;15         }16         else{17             type = "not a triangle";18             return type;19         }20     } 21 }
package triangle;import static org.junit.Assert.assertEquals;import java.util.Arrays;import java.util.Collection;import org.junit.Test;import org.junit.runner.RunWith;import org.junit.runners.Parameterized;import org.junit.runners.Parameterized.Parameters;@RunWith(Parameterized.class)public class triangleTest {    private String type;    private int a;    private int b;    private int c;        public triangleTest(String type, int a, int b, int c){        this.type = type;        this.a = a;        this.b = b;        this.c = c;    }    @Parameters    public static Collection prepareData(){        Object[][] object = {                {
"not a triangle",1,1,2},{"equilateral",1,1,1}, {
"isosceles",2,2,3},{"scalene",2,3,4}}; return Arrays.asList(object); } @Test public void TestTypeOfTriangle() { triangle triangle = new triangle (); assertEquals (type, triangle.typeOfTriangle(a,b,c)); }}

转载于:https://www.cnblogs.com/lushilin/p/5336978.html

你可能感兴趣的文章
Hibernate中inverse="true"的理解
查看>>
高级滤波
查看>>
使用arcpy添加grb2数据到镶嵌数据集中
查看>>
[转载] MySQL的四种事务隔离级别
查看>>
QT文件读写
查看>>
C语言小项目-火车票订票系统
查看>>
15.210控制台故障分析(解决问题的思路)
查看>>
BS调用本地应用程序的步骤
查看>>
常用到的多种锁(随时可能修改)
查看>>
用UL标签+CSS实现的柱状图
查看>>
mfc Edit控件属性
查看>>
Linq使用Join/在Razor中两次反射取属性值
查看>>
[Linux]PHP-FPM与NGINX的两种通讯方式
查看>>
Java实现二分查找
查看>>
优秀员工一定要升职吗
查看>>
[LintCode] 462 Total Occurrence of Target
查看>>
springboot---redis缓存的使用
查看>>
架构图-模型
查看>>
sql常见面试题
查看>>
jQuery总结第一天
查看>>