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. Linux命令-dd

    dd命令用于指定大小的拷贝的文件或指定转换文件. 以下命令作用:将光驱设备拷贝成镜像文件 参数 if 输入的文件名称 参数 of 输出的文件名称 [root@localhost testA]# dd ...

  2. 传统三层结构和MVC之于贫血模式和充血模式以及领域建模

      相信很多人跟我一样,一开始在使用贫血模式的三层结构:抽象出来一个贫血的实体封装,然后把对模型的所有操作,分离出来,分离到BLL层去,然后DALL层负责把这些操作和数据库产生映射,负责读写删改的操作 ...

  3. JVM的stack和heap,JVM内存模型,垃圾回收策略,分代收集,增量收集

    (转自:http://my.oschina.net/u/436879/blog/85478) 在JVM中,内存分为两个部分,Stack(栈)和Heap(堆),这里,我们从JVM的内存管理原理的角度来认 ...

  4. Java用于取得当前日期相对应的月初,月末,季初,季末,年初,年末时间

    package com.zrar.date; import java.util.Calendar; /** * * 描述:此类用于取得当前日期相对应的月初,月末,季初,季末,年初,年末,返回值均为St ...

  5. [原]素数筛法【Sieve Of Eratosthenes + Sieve Of Euler】

    拖了有段时间,今天来总结下两个常用的素数筛法: 1.sieve of Eratosthenes[埃氏筛法] 这是最简单朴素的素数筛法了,根据wikipedia,时间复杂度为 ,空间复杂度为O(n). ...

  6. 8.cadence.CIS[原创]

    一.CIS数据库配置 ------ ---------------------------- --------------- ------------------ ---- 二.CIS放置元件 --- ...

  7. 《OD学hive》第六周20160731

    一.hive的压缩 1. hadoop的压缩 1)为什么需要压缩 MapReduce的性能瓶颈:网络IO.磁盘IO 数据量:对于MapReduce的优化,最主要.根本就是要能够减少数据量 Combin ...

  8. 作业调度框架 Quartz.NET 2.0 StepByStep

    注:目前网上诸多介绍Quartz.net的文章,甚至Quartz.net官网上的Tutorial都是1.0版本的,而这个项目在2.0版本对项目进行了比较大规模的修改,使得原有的很多例子都不能运行,故写 ...

  9. [转载]charisma-master 加载慢的原因及解决方法

    [我的总结] 原文中指出的地址有的已经转换,因为版本问题. 所以根据2014年11月获取的charisma-master版本,应做以下更改: 1.charisma-app.css 这个文件中的外链字体 ...

  10. BZOJ 2151 种树

    贪心+priority_queue. #include<iostream> #include<cstdio> #include<cstring> #include& ...