Page 16 Exercises 1.2.3 -------Introduction to Software Testing (Paul Ammann and Jeff Offutt)
Below are four faulty programs. Each includes a test case that results in failure. Answer the following questions about each progrma.
(a) Indentify the fault.
(b) If possible, identify a test case that does not execute the fault.
(c) If possible, identify a test case that executes the fault, but does not result in an error state.
(d) If possible, identify a test case that resutls in an error, but not a failure. Hint: Don't forget about the program counter.
(e) For the given test case, identify the first error state. Be sure to describe the complete state.
(f) Fix the fault and verify that the given test now produces the expected output.
Program 1:
public int findLast(int[] x, int y){
//Effects: If x==null throw NullPointerException
// else return the index of the last element
// in x that equals y.
// if no sunch element exists, return -1
for (int i = x.length - 1; i > 0; i--)
{
if(x[i]==y)
{
return i;
}
}
return -1;
}
//test: x= [2, 3, 5]; y = 2
// Expected = 0
(a) fault: in the for loop, it shoule be:
for(int i = x.length-1; i >= 0; i--)
(b) test case: x = [1]; y = 2, it doesn't execute i > 0
(c) test case: x = [1, 2, 3]; y = 3, it executes x > 0 but doesn't go to i = 0
(d) test case: x = [1, 2, 3]; y = -1, it goes to i = 0 but the result is right
(e) first error state: x = [2, 3, 4], y = 2, i = 0, it should compare x[0] to y, but it doesn't
(f) see(a)
Program 2:
public static int lastZero(int[] x){
//Effects: if x==null throw NullPointerException
// else return the index of the LAST 0 in x.
// Return -1 if 0 does not occur in x
for(int i = 0; i < x.length; i++)
{
if(x[i] = 0)
{
return i;
}
}
return -1;
}
//test: x = [0, 1, 2]
// Excepted = 2;
(a) fault: in the for loop, it shoule be:
for(int i = x.length-1; i >= 0; i--)
(b) test: x = []
(c) test: x = [1]
(d) test: x = [0, 1]
(e) first error state: x = [0, 1, 0], i = 0, after that i should decrease 1
(f) see (a)
Program 3:
public int countPositive(int[] x){
//Effects: If x==null throw NullPointerException
// else return the number of
// positive elements in x.
int count = 0;
for(int i = 0; i < x.length; i++)
{
if(x[i] >= 0)
{
count++;
}
}
return count;
}
//test: x= [-4, 2, 0, 2]
// Excepted = 2
(a) fault: it shoule be:
if(x[i] > 0)
(b) test case: x = []
(c) test case: x = [1]
(d) if it goes to an error, it must results in failure
(e) first error state: x = [-4, 2, 0, 2], i = 2, after that it should continue the for loop instead of increasing the count
(f) see (a)
Program 4:
public static int oddOrPos(int[] x){
//Effects: if x==null throw NullPointerException
// else return the number of elements in x that
// are either odd or positive (or both)
int count = 0;
for(int i =0; i < x.length; i++)
{
if(x[i]%2 == 1 || x[i] > 0)
{
count++;
}
}
return count;
}
//test: x = [-3, -2, 0, 1, 4]
// Excepted = 3
(a) fault: it should be:
if(x[i] % 2 == -1 || x[i] > 0)
(b) test: x = []
(c) test: x = [1]
(d) test: the test case that results in an error, but not a failure does not exist
(e) first error state: x = [-3, -2, 0, 1, 4], i = 0, after that it should execute count++, but it doesn't
(f) see(a)
Page 16 Exercises 1.2.3 -------Introduction to Software Testing (Paul Ammann and Jeff Offutt)的更多相关文章
- Page 63-64 Exercises 2.3.7 -------Introduction to Software Testing (Paul Ammann and Jeff Offutt)
Use the following method printPrimes() for question a-d below //Find and prints n prime integers pri ...
- 【Software Test】Introduction to Software Testing
Introduction to Software Testing 文章目录 Going to Learn --. Evolution of The Software Industry Errors, ...
- The Most Simple Introduction to Hypothesis Testing
https://www.youtube.com/watch?v=UApFKiK4Hi8
- 软件测试技术(三)——使用因果图法进行的UI测试
目标程序 较上次增加两个相同的输入框 使用方法介绍 因果图法 在Introduction to Software Testing by Paul一书中,将软件测试的覆盖标准划分为四类,logical ...
- Django 2.0.1 官方文档翻译:接下来读什么(page 14)
接下来读什么(page 14) 现在你应该已经阅读了所有的(page1-13 )介绍材料,决定继续使用Django.我们仅仅做了简要的介绍(事实上,如果你阅读了前面所有的内容,也只是全部文档的5%.) ...
- Spring 5 (0) - Introduction & Index
Spring Framework Reference Documentation I. Overview of Spring Framework . Getting Started with Spri ...
- [Draft]iOS.Architecture.16.Truth-information-flow-and-clear-responsibilities-immutability
Concept: Truth, Information Flow, Clear Responsibilities and Immutability 1. Truth 1.1 Single Source ...
- 1: 介绍Prism5.0 Introduction to the Prism Library 5.0 for WPF(英汉对照版)
Prism provides guidance designed to help you more easily design and build rich, flexible, and easy- ...
- Typeclassopedia
https://wiki.haskell.org/wikiupload/8/85/TMR-Issue13.pdf By Brent Yorgey, byorgey@gmail.com Original ...
随机推荐
- Jquery中用offset().top和offsetTop的比较
今天,想测试一个div与顶部的距离,用的是.offsetTop,但是offsetTop获得的值,怎么都打印不出来.折腾了半天,打印的结果都是undefined,虽然网上很多资料都说返回的是数值.虽然这 ...
- ubuntu下安装与测试mysql
1.在决定安装mysql之前,要先确定系统是否已经安装mysql. 输入: 1 mysql 结果:说明尚未安装mysql The program 'mysql' is currently notins ...
- [android警告] AndroidManifest.xml警告 Should explicitly set android:allowBackup to true or false
http://www.cnblogs.com/javadu/p/3812528.html Android中AndroidManifest.xml警告 Should explicitly set and ...
- mencoder mencoder 安装使用及常用参数
mencoder 安装及使用 1.安装: 参考:http://hi.baidu.com/putword/item/e5910a187d2aed14e2f9867f 2.合并视频: ...
- 获取sde 工作空间 propertys
// This example shows how to inspect and display different types of properties for a workspace. publ ...
- Sass&Compass学习笔记(一)
1.sass中可以使用变量 变量名以$符号开头,可包含所有可用作CSS类名的字符,包括下划线和中划线. 可见,中划线也是可以作为命名的字符,这是与很多其他语言的不同之处.变量的使用实例: $compa ...
- Python自带包建立简单web服务器
在DOS里cd到准备做服务器根目录的路径下,输入命令: python -m Web服务器模块 [端口号,默认8000] 例如: python -m SimpleHTTPServer 8080 然后就可 ...
- STL笔记(2) STL之父访谈录
年3月,dr.dobb's journal特约记者, 著名技术书籍作家al stevens采访了stl创始人alexander stepanov. 这份访谈纪录是迄今为止对于stl发展历史的最完备介绍 ...
- mysql安装图解 mysql图文安装教程(详细说明)
MySQL5.0版本的安装图解教程是给新手学习的,当前mysql5.0.96是最新的稳定版本. mysql 下载地址 http://www.jb51.net/softs/2193.html 下面的是M ...
- 【笨嘴拙舌WINDOWS】剪切板
Windows剪贴板是一种比较简单同时也是开销比较小的IPC(InterProcess Communication,进程间通讯)机制.Windows系统支持剪贴板IPC的基本机制是由系统预留的一块全局 ...