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. .NET责任链模式(混合单例模式,模板方法模式)-----制作与扩展能力验证

    .NET责任链模式.单例模式.模板方法模式混用 前言 哇,看到题目挺长的,这个组合型的东西,到底能干啥呢?本篇文章来一起琢磨琢磨,这两天为了团队的软件赶工,我负责的那一块叫:插件管理器.我们团队的成员 ...

  2. requirejs 优化压缩

    1 配置node环境 2 配置built.js文档 3 执行命令node r.js -o built.js 文件目录: <!DOCTYPE HTML> <html lang=&quo ...

  3. PHP高级特性一之正则表达式用法

    在PHP中,我们进行字符串处理时,能用字符串处理函数时我们当然要使用简单的字符串处理函数,但字符串处理函数的能力是有限的,所以我们就需要利用一个更强大的工具,那就是正则表达式. 简述正则表达式 正则表 ...

  4. Android 如何设置默认语言

    前言          欢迎大家我分享和推荐好用的代码段~~ 声明          欢迎转载,但请保留文章原始出处:          CSDN:http://www.csdn.net        ...

  5. 什么是智能dns解析

    智能DNS解析是针对目前电信和网通互联互通不畅的问题推出的一种DNS解决方案.具体实现是:把同样的域名如test.winiis.com的A记录分别设置指向网通和电信IP,当网通的客户访问时,智能DNS ...

  6. [HDOJ2602]Bone Collector(01背包)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 裸的... #include <algorithm> #include <io ...

  7. UESTC 1074 秋实大哥搞算数 栈模拟

    秋实大哥搞算数 Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Submit S ...

  8. Redis 网络通信及连接机制学习

    看了这篇文章 http://blog.nosqlfan.com/html/4153.html 本文所述内容基于 Redis2.6 及以上版本. 注:在客户端通过 info 命令可以查看服务器版本信息, ...

  9. 51nod1406 与查询

    这题卡I/O...dp一下... #include<cstdio> #include<cstring> #include<cctype> #include<a ...

  10. bzoj3668: [Noi2014]起床困难综合症

    从高位到低位枚举期望的应该是ans最高位尽量取一.如果该数最高位为o的话能够取得1直接更新ans否则判断该位取1是否会爆m不会的话就加上. #include<cstdio> #includ ...