软件测试:3.Exercise Section 2.3
软件测试:3.Exercise Section 2.3
/************************************************************ * 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 primes. // 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; i++ ) { //for each previous prime. if(isDvisible(primes[i],curPrime)) { //Found a divisor, curPrime is not prime. isPrime = false; break; } } if(isPrime) { // save it! primes[numPrimes] = curPrime; numPrimes++; } }// End while // Print all the primes out for(int i = 0; i < numPrimes; i++) { System.out.println("Prime: " + primes[i] ); } }// End printPrimes.
Questions:
(a) Draw the control flow graph for the printPrimes() method.
(b) Consider test cases t1 = (n = 3) and t2 = ( n = 5). Although these tour the same prime paths in printPrime(), they do not necessarily find the same faults. Design a simple fault that t2 would be more likely to discover than t1 would.
(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.
(d) Enumerate the test requirements for node coverage, edge coverage, and prime path coverage for the graph for printPrimes().
(e) List test paths that achieve node coverage but not edge coverage ont the graph.
(f) List test paths that achieve edge coverage but not prime path coverage on the graph.
Answers:
(a) Draw the control flow graph for the printPrimes() method:
(b) 将MAXPRIMES设置为4时,t2会发生数组越界错误,但t1不会发生错误。
(c) n=1
(d) Node Coverage
TR={1,2,3,4,5,6,7,8,9,10,11,12,13,14}
Edge Coverage
TR={(1,2), (2,3), (2,10), (3,4), (4,5), (5,6), (5,8), (6,5), (6,7), (7,8), (8,2),(8,9), (9,2), (10,11), (11,12), (11,14), (12,13), (13,11)}
Prime Path Coverage
Test Paths: [1,2,3,4,5,6,7],
[1,2,3,4,5,6,8,9,10,11],
[1,2,3,4,5,6,8,9,11],
[1,2,3,4,5,9,10,11],
[1,2,3,4,5,9,11],
[1,2,12,13,14,15],
[1,2,12,16],
[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,14,15],
[3,4,5,6,8,9,11,2,12,13,14,15],
[3,4,5,6,8,9,10,11,2,12,13,16],
[3,4,5,6,8,9,11,2,12,13,16],
[3,4,5,9,10,11,2,12,13,14,15],
[3,4,5,9,11,2,12,13,14,15],
[3,4,5,9,10,11,2,12,13,16],
[3,4,5,9,11,2,12,13,16],
[5,6,7,5],
[6,7,5,9,10,11,2,12,13,14,15],
[6,7,5,9,11,2,12,13,14,15],
[6,7,5,9,10,11,2,12,13,16],
[6,7,5,9,11,2,12,13,16],
[13,14,15,13],
[14,15,13,16]
软件测试:3.Exercise Section 2.3的更多相关文章
- <<C++ Primer>> 第四版Exercise Section 8.4.1 练习题
For exercise 8.6 // ConsoleApplication10.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #incl ...
- C++ 容器对象vector和list 的使用
在<<c++ primer>>第四版Exercise Section 9.3.4 的Exercise 9.20 是这样的一道题目:编写程序判断一个vector<int&g ...
- vector 对象中存放指针类型数据
<<C++ Primer>> 第四版Exercise Section 5.6 的5.1.6 有一道题是这样的:编写程序定义一个vector对象,其每个元素都是指向string类 ...
- C 风格字符串相加
<<C++ Primer>> 第四版Exercise Section 4.3.1 的4.3.0 有如下题目:编写程序连接两个C风格字符串字面值,把结果存储在C风格字符串中.代码 ...
- C风格字符串和C++ string 对象赋值操作的性能比较
<<C++ Primer>> 第四版 Exercise Section 4.3.1 部分Exercise 4.2.9 习题如下: 在自己本机执行如下程序,记录程序执行时间: # ...
- C++ Primer 5th Edition自学笔记(1)
好吧,第一次写东西...如何下手呢...(请无视) -------------------------------------------------------------- Chapter 1. ...
- MIT 6.828 JOS学习笔记5. Exercise 1.3
Lab 1 Exercise 3 设置一个断点在地址0x7c00处,这是boot sector被加载的位置.然后让程序继续运行直到这个断点.跟踪/boot/boot.S文件的每一条指令,同时使用boo ...
- Conway's Game of Life: An Exercise in WPF, MVVM and C#
This blog post was written for the Lockheed Martin Insight blog, sharing here for the external audie ...
- CMSC 216 Exercise #5
CMSC 216 Exercise #5 Spring 2019Shell Jr (”Shellito”) Due: Tue Apr 23, 2019, 11:30PM1 ObjectivesTo p ...
随机推荐
- 基于CBOW网络手动实现面向中文语料的word2vec
最近在工作之余学习NLP相关的知识,对word2vec的原理进行了研究.在本篇文章中,尝试使用TensorFlow自行构建.训练出一个word2vec模型,以强化学习效果,加深理解. 一.背景知识: ...
- java中的i++与++i的区别以及除法、模的用法(基础)
java中i++与++i的区别: 例如:int i=3; (先运算再赋值)j=++i; i的值先变成4,再赋给j,j的值为4: (先赋值再运算)j=i++; 先将i的值3赋给j,j的值为3,然后i变成 ...
- two pointers
two pointers是算法编程中一种非常重要的思想,但是很少会有教材单独拿出来将,其中一个原因是它更倾向于是一种编程技巧,而长得不太像是一个是“算法”的模样.two pointers的思想十分简介 ...
- jQuery-4.动画篇---动画基础隐藏和显示
jQuery中隐藏元素的hide方法 让页面上的元素不可见,一般可以通过设置css的display为none属性.但是通过css直接修改是静态的布局,如果在代码执行的时候,一般是通过js控制元素的st ...
- Android方法引用超过65535的解决方式
//在app/build.gradle android { compileSdkVersion buildToolsVersion "24.0.1" defaultConfig { ...
- [转]如何正确学习JavaScript
原文:How to Learn JavaScript Properly(2014-2-7) 学习时长:6-8周 学习前提:中学水平,无需编程经验 更新(2014-1-7) 在Reddit上创建了一个学 ...
- AI之旅(6):神经网络之前向传播
前置知识 求导 知识地图 回想线性回归和逻辑回归,一个算法的核心其实只包含两部分:代价和梯度.对于神经网络而言,是通过前向传播求代价,反向传播求梯度.本文介绍其中第一部分. 多元分类:符号转换 ...
- Golang微服务:Micro限流、熔断
Wrapper Wrapper提供了一种包装机制,使得在执行某方法前先执行Wrapper,优点Filter的意思:因此可以在客户端和服务器做很多功能:熔断限流.Filter.Auth等. client ...
- DashBoard创建各种表(二)
添加范围过滤器 “ 范围过滤器”允许您将过滤应用于其他仪表板项.此项目显示带有选择拇指的图表,允许您过滤掉沿参数轴显示的值. 如图,可以根据选择不同的CategorySales范围显示图表1的内容了. ...
- ccf-命令行选项-201403-3
分析: 这道题不是很难 用了一个split()函数 核心是: 对命令选项的判断 不要一个字符字符的判断 要一项一项的判断 比如ab:m: 分析步骤 (1) 读取一个字符(2)判断下一步是否有字符,下一 ...