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 ...
随机推荐
- Android开发常用代码片段
拨打电话 public static void call(Context context, String phoneNumber) { context.startActivity( new Inten ...
- 微信jssdk uploadImage 巨坑
//解决IOS无法上传的坑 if (localId.indexOf("wxlocalresource") != -1) { localId = localId.replace(&q ...
- OpenMp之sections用法
section语句是用在sections语句里用来将sections语句里的代码划分成几个不同的段 #pragma omp [parallel] sections [子句] { #pragma ...
- WCF约束名称的用法
<!--<endpoint address="" binding="basicHttpBinding" bindingConfiguration=& ...
- Java 基础-运算符
Java运算符 算术运算符 赋值运算符 比较运算符 逻辑运算符 位运算符 运算符优先级 1. 算术运算符 运算符 运算 范例 结果 + 正号 +3 3 - 负号 b=4;-b -4 + 加 5+5 1 ...
- 台湾P2P平台
2014年6月28日下午1:30,“2014两岸三地P2P网贷行业高峰论坛”在上海会展中心友谊会堂如期举行,现场高朋满座,来自全国各地的众多知名P2P网站平台的负责人参与了讨论,并就当前P2P行业的一 ...
- java 求取某一段时间内的每一天、每一月、每一年
1.求取某一段时间内的每一天 Date date0 = new SimpleDateFormat("yyyy-MM-dd").parse("2014-01-01" ...
- URAL1900 Brainwashing Device(dp)
1900 二维dp挺好推 dp[i][j] = max(dp[i][j],dp[g][j-1]+o[i][i+1]-o[g][i+1])(i>g>=j-1) dp[i][j]表示第i个站台 ...
- JS 去除字符串中的空格
1. 去掉字符串前后所有空格: 代码如下: function Trim(str) { return str.replace(/(^\s*)|(\s*$)/g, ""); } 说明: ...
- Open Explorer Plugin for Eclipse (eclipse 插件 在eclipse里面打开文件目录)
就是在eclipse里面直接打开文件所在的目录地址 只要将下面的jar 文件放到你的 “$ECLIPSE_HOME/plugins” 下面,重启eclipse就ok了 要想卸载的话 停止eclip ...