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 ...
随机推荐
- Linux系统文件访问控制列表
linux系统中的RWX权限.特殊权限.隐藏权限都是对某一类用户设置的, 而如果希望对某个指定的用户进行单独的权限设置的话就需要用到文件的 访问控制权限了. 我们可以对普通文件或目录进行设置ACL,通 ...
- Oracle ->> 连续聚合
select id, grp_factor, sum (id) over( partition by grp_factor order by id rows between unbounded pre ...
- 局部敏感哈希Locality Sensitive Hashing(LSH)之随机投影法
1. 概述 LSH是由文献[1]提出的一种用于高效求解最近邻搜索问题的Hash算法.LSH算法的基本思想是利用一个hash函数把集合中的元素映射成hash值,使得相似度越高的元素hash值相等的概率也 ...
- django如何检查创建的模型(model)是否有语法错误或者逻辑错误
首先,用下面的命令验证模型的有效性: python manage.py validate validate 命令检查你的模型的语法和逻辑是否正确. 如果一切正常,你会看到 0 errors found ...
- linux硬件驱动层
1.make menuconfig scripts/kconfig/lxdialog/menubox.o: In function `print_buttons':menubox.c:(.text+0 ...
- hihoCoder 1043 完全背包 (dp)
http://hihocoder.com/problemset/problem/1043 动态转移方程 :for v=cost..V f[v]=max(f[v],f[v-c[i]]+w[i]); #i ...
- UVA 11019 Matrix Matcher(ac自动机)
题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- Introduction
http://www.entityframeworktutorial.net/EntityFramework5/entity-framework5-introduction.aspx Basics o ...
- Server Profiler
Server Profiler 2014-10-31 工作原理 SQL Server Profiler这个工具是SQL Trace的一个GUI的版本,而SQL Trace是一组脚本,自SQL Serv ...
- innodb锁之间的兼容性判断
检查锁与锁之间的兼容性 路径:/mysql-5.5.43/storage/innobase/lock/lock0lock.c 实现:见锁的强度比较 row 可理解为 lock 的锁模式 colum ...