软件测试 作业三 《软件测试基础》2.3节第7题

Use the following method printPrimes() for questions a–d.

原书:《Introduction to Software Testing》BY Paul Ammann and Jeff Offutt

题目为书中2.3小节第7题。

题目代码如下:

/** *****************************************************
 * Finds and prints n prime integers
* Jeff Offutt, Spring 2003
 ********************************************************* */
 private 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 (isDivisible (primes[i], curPrime))
 { // 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) Draw the control flow graph for the printPrimes() method.

(a)如图

(b) Consider test cases t 1 = (n = 3) and t 2 = (n = 5). Although these tour the same prime paths in printPrimes(), they do not necessarily find the same faults. Design a simple fault that t 2 would be more likely to discover than t 1 would.

答:(b)将while循环中的循环判断条件改为while(numPrimes<3)

(c)For printPrimes(), find a test case such that the corresponding test path visits the edge that connects the beginning of the while statement to the for statement without going through the body of the while loop.

答:(c)可以设计为n=1

(d) Enumerate the test requirements for Node Coverage, Edge Coverage, and Prime Path Coverage for the graph for printPrimes().

答:(d)节点覆盖:{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}

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

主路径覆盖:{

[0, 1, 2, 3, 4, 5, 7, 8, 9]

[0, 1, 2, 3, 4, 5, 7, 9]

[0, 1, 2, 3, 4, 6]

[0, 1, 2, 3, 7, 8, 9]

[0, 1, 2, 3, 7, 9]

[0, 1, 10, 11, 12, 13]

[0, 1, 10, 11, 14]

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

[2, 3, 4, 5, 7, 8, 9, 1, 10, 11, 12, 13]

[2, 3, 4, 5, 7, 9, 1, 10, 11, 14]

[2, 3, 4, 5, 7, 9, 1, 10, 11, 12, 13]

[2, 3, 7, 8, 9, 1, 10, 11, 14]

[2, 3, 7, 8, 9, 1, 10, 11, 12, 13]

[2, 3, 7, 9, 1, 10, 11, 14]

[2, 3, 7, 9, 1, 10, 11, 12, 13]

[4, 6, 3, 7, 8, 9, 1, 10, 11, 14]

[4, 6, 3, 7, 8, 9, 1, 10, 11, 12, 13]

[4, 6, 3, 7, 9, 1, 10, 11, 14]

[4, 6, 3, 7, 9, 1, 10, 11, 12, 13]

[12, 13, 11, 14]

[1, 2, 3, 4, 5, 7, 8, 9, 1]

[1, 2, 3, 4, 5, 7, 9, 1]

[1, 2, 3, 7, 8, 9, 1]

[1, 2, 3, 7, 1]

[3, 4, 6, 3]

[11, 12, 13, 11] },其中后面六个代表类似的循环的路径

时间: 2024-12-27 15:20:17

软件测试 作业三 《软件测试基础》2.3节第7题的相关文章

软件测试作业——三

作业见<软件测试基础>中文版49页第7题.英文版63页 a) b) 令MAXPRIMES = 4,t1不能检查出错误,t2发生数组越界,使得t2比t1更容易发现. c)t3=(n=1) d)节点覆盖:TR={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16} 边覆盖:TR={(1,2),(2,3),(2,12),(3,4),(4,5),(5,6),(6,8),(8,5),(6,7),(7,9), (5,9),(9,10),(10,11),(9,11),(12,13)

软件测试作业三-printPrimes()

作业内容: private static void printPrimes(int n) { int curPrime; int numPrimes; boolean isPrime; int MAXPRIMES=50; int [] primes = new int [MAXPRIMES]; primes [0] = 2; numPrimes = 1; curPrime = 2; while (numPrimes < n) { curPrime++; isPrime = true; for (

软件测试作业三

作业内容: Use the following method printPrimes() for questions a–f below. 代码如下: 1. /** ***************************************************** 2. * Finds and prints n prime integers 3. * Jeff Offutt, Spring 2003 4. *****************************************

软件测试作业三 尝试使用JUnit

写一个判断三角形种类的代码,对其进行测试. 判断三角形代码: package 测试1; public class sjx { public String f(int a,int b,int c) { if(a<=0||b<=0||c<=0||a+b<=c||a+c<=b||b+c<=a) return "不是三角形"; if(a == b&&b == c) return "等边三角形"; else if(a ==

Software Testing (软件测试作业三) HW3 prin

The source code: 源代码: /******************************************************* * Finds and prints n prime integers * Jeff Offutt, Spring 2003 ******************************************************/ public static void printPrimes (int n) { int curPrim

软件测试作业2 — 软件测试中的错误Failure, Error, Fault的区别

软件测试中的错误Failure, Error, Fault的区别: Failure: External, incorrect behavior with respect to the requirements or other description of the expected behavior(预期行为出错或与其他的外部行为描述不符).指软件在运行时出现的功能的丧失,类似于看病时病人发病的症状. Fault: A static defect in the software(软件中的静态缺陷

软件测试作业——Junit使用

软件测试作业--Junit使用 [TOC] 题目要求 Install Junit(4.12),Hamcrest(1.3) with Eclipse Install Eclemma with Eclipse Write a javaprogram for the triangle problem and test the program with Junit. Description oftriangle problem:Functiontriangle takes three integers

软件测试中的那些基础知识

软件测试是一项批判性的工作,目的就是找出软件中的缺陷.这里暂时不去深究为什么要进行软件测试,以及软件测试带来的好处.只介绍软件测试中一些基本的测试方法.根据是否查看代码程序分为黑盒测试和白盒测试:根据是否运行软件又可分为静态测试和动态测试. 黑盒测试:又叫功能测试或行为测试,只需考虑各个功能,不需要考虑整个软件的内部结构及代码. 白盒测试:访问代码,通过检查代码的线索来协助测试. 静态测试:测试软件不运行的部分,只是检查和审核. 动态测试:使用和运行软件进行测试. 1.静态黑盒测试:检查产品说明

第三百六十四节,Python分布式爬虫打造搜索引擎Scrapy精讲—elasticsearch(搜索引擎)的mapping映射管理

第三百六十四节,Python分布式爬虫打造搜索引擎Scrapy精讲-elasticsearch(搜索引擎)的mapping映射管理 1.映射(mapping)介绍 映射:创建索引的时候,可以预先定义字段的类型以及相关属性elasticsearch会根据json源数据的基础类型猜测你想要的字段映射,将输入的数据转换成可搜索的索引项,mapping就是我们自己定义的字段数据类型,同时告诉elasticsearch如何索引数据以及是否可以被搜索 作用:会让索引建立的更加细致和完善 类型:静态映射和动态