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)的更多相关文章

  1. 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 ...

  2. 【Software Test】Introduction to Software Testing

    Introduction to Software Testing 文章目录 Going to Learn --. Evolution of The Software Industry Errors, ...

  3. The Most Simple Introduction to Hypothesis Testing

    https://www.youtube.com/watch?v=UApFKiK4Hi8

  4. 软件测试技术(三)——使用因果图法进行的UI测试

    目标程序 较上次增加两个相同的输入框 使用方法介绍 因果图法 在Introduction to Software Testing by Paul一书中,将软件测试的覆盖标准划分为四类,logical ...

  5. Django 2.0.1 官方文档翻译:接下来读什么(page 14)

    接下来读什么(page 14) 现在你应该已经阅读了所有的(page1-13 )介绍材料,决定继续使用Django.我们仅仅做了简要的介绍(事实上,如果你阅读了前面所有的内容,也只是全部文档的5%.) ...

  6. Spring 5 (0) - Introduction & Index

    Spring Framework Reference Documentation I. Overview of Spring Framework . Getting Started with Spri ...

  7. [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 ...

  8. 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- ...

  9. Typeclassopedia

    https://wiki.haskell.org/wikiupload/8/85/TMR-Issue13.pdf By Brent Yorgey, byorgey@gmail.com Original ...

随机推荐

  1. Java数据结构之排序

    1.冒泡排序:时间复杂度为O(n2) 假设是由小到大排序:相邻两个数之间进行比较,较大的数在后面.一次比较过后最大的数排在最后面 如:40.8.15.18.12一次排序后为:8.15.18.12.40 ...

  2. python操作json

    概念 序列化(Serialization):将对象的状态信息转换为可以存储或可以通过网络传输的过程,传输的格式可以是JSON.XML等.反序列化就是从存储区域(JSON,XML)读取反序列化对象的状态 ...

  3. FFmpeg FFmpeg的使用及常用参数

    FFmpeg的使用及常用参数 一.下载: 官网:http://ffmpeg.org/ 二.demo: 1 class Program 2 { 3 static void Main(string[] a ...

  4. (九)ASP.NET自定义用户控件(2)

    http://www.cnblogs.com/SkySoot/archive/2012/09/04/2670678.html 用户控件 在 .NET 里,可以通过两种方式把自己的控件插入到 Web 窗 ...

  5. 验证码图片生成工具类——Captcha.java

    验证码图片生成工具,使用JAVA生成的图片验证码,调用getRandcode方法获取图片验证码,以流的方式传输到前端页面. 源码如下:(点击下载  Captcha.java) import java. ...

  6. 《OD学hadoop》在LINUX下如何将tar压缩文件解压到指定的目录下

    linux下tar命令解压到指定的目录 :#tar zxvf /bbs.tar.zip -C /zzz/bbs //把根目录下的bbs.tar.zip解压到/zzz/bbs下,前提要保证存在/zzz/ ...

  7. 运行时报错 ADB server didn’t ACK

    查看进程中所有和ADB有关的进程,全都结束了,包括什么豌豆荚之类的(大多数情况是占用端口),之后重新启动Eclipse.

  8. As of ADT 14, resource fields cannot be used as switch cases

        在导入Android Sample的ApiDemos的时候,发现R.id.xx的文件不能够在 switch cases 中使用 在google查询了下,找到以下答案: As of ADT 14 ...

  9. Spring 实践 -拾遗

    Spring 实践 标签: Java与设计模式 Junit集成 前面多次用到@RunWith与@ContextConfiguration,在测试类添加这两个注解,程序就会自动加载Spring配置并初始 ...

  10. IE 火狐浏览器对时间格式的兼容性;使用原型对象的方式 prototype关键字;时间格式化

    在ie中 时间格式如果用横杠来显示  "2013-05-10 19:20:59" 是可以正确识别的(如果用斜杠,IE也可以正确识别), 但是如果是火狐,则只能识别斜杠模式 &quo ...