软件测试第三次作业——习题2.3.7

a)

b)若MAXPRIMES为2,则t2在primes[numPrimes]=curPrime(即上图节点8)处会发生访问非法内存的错误,因为n=5时质数有2,3,5.但t1不会出错,因为n=3时质数只有2,3.

c)t=(n=1).

d)点覆盖:{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}

边覆盖:{(0,1),(1,2),(1,11),(2,3),(3,4),(3,7),(4,5),(4,6),(5,7),(6,3),(7,8),(8,9),(8,10),(9,10),(10,1),(11,12),(12,13),(13,14),(13,15),(14,13)}

主路径覆盖{(13,14,13)(14,13,14)(14,13,15)(3,4,6,3)(4,6,3,4)(6,3,4,6)(0,1,2,3,4,6)(0,1,11,12,13,14)(0,1,11,12,13,15)(0,1,2,3,7,8,10)(1,2,3,7,8,10,1)(2,3,7,8,10,1,2)(3,7,8,10,1,2,3)(7,8,10,1,2,3,7)(8,10,1,2,3,7,8)(10,1,2,3,7,8,10)(0,1,2,3,7,8,9,10)(1,2,3,7,8,9,10,1)(2,3,7,8,9,10,1,2)(3,7,8,9,10,1,2,3)(4,6,3,7,8,10,1,2)(7,8,9,10,1,2,3,7)(8,9,10,1,2,3,7,8)(9,10,1,2,3,7,8,9)(10,1,2,3,7,8,9,10)(0,1,2,3,4,5,7,8,10)(1,2,3,4,5,7,8,10,1)(2,3,4,5,7,8,10,1,2)(3,4,5,7,8,10,1,2,3)(4,5,7,8,10,1,2,3,4)(4,6,3,7,8,9,10,1,2)(5,7,8,10,1,2,3,4,5)(5,7,8,10,1,2,3,4,6)(6,3,4,5,7,8,10,1,2)(7,8,9,10,1,2,3,4,6)(7,8,10,1,2,3,4,5,7)(8,10,1,2,3,4,5,7,8)(10,1,2,3,4,5,7,8,10)(0,1,2,3,4,5,7,8,9,10)(1,2,3,4,5,7,8,9,10,1)(2,3,4,5,7,8,9,10,1,2)(3,4,5,7,8,9,10,1,2,3)(4,5,7,8,9,10,1,2,3,4)(5,7,8,9,10,1,2,3,4,5)(5,7,8,9,10,1,2,3,4,6)(6,3,4,5,7,8,9,10,1,2)(7,8,9,10,1,2,3,4,5,7)(8,9,10,1,2,3,4,5,7,8)(9,10,1,2,3,4,5,7,8,9)(10,1,2,3,4,5,7,8,9,10)(2,3,7,8,9,10,1,11,12,13,14)(2,3,7,8,9,10,1,11,12,13,15)(4,6,3,7,8,10,1,11,12,13,14)(4,6,3,7,8,10,1,11,12,13,15)(2,3,4,5,7,8,10,1,11,12,13,14)(2,3,4,5,7,8,10,1,11,12,13,15)(4,6,3,7,8,9,10,1,11,12,13,14)(4,6,3,7,8,9,10,1,11,12,13,15)(6,3,4,5,7,8,10,1,11,12,13,14)(6,3,4,5,7,8,10,1,11,12,13,15)(2,3,4,5,7,8,9,10,1,11,12,13,14)(2,3,4,5,7,8,9,10,1,11,12,13,15)(6,3,4,5,7,8,9,10,1,11,12,13,14)(6,3,4,5,7,8,9,10,1,11,12,13,15)}

基于Junit测试:

package test;

import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
public class testhello {
private hello cal;

	// 执行任意一个方法之前都会执行setUp方法
	@Before
	public void setUp(){
		cal = new hello();
	}

	// 加了@Test表示该方法是一个单元测试
 	@Test
	public void testPrime(){
 		cal.printPrimes(20);
	}

 	//hamcrest 1.3
}

  结果截图:

覆盖测试:

时间: 2024-10-21 07:10:36

软件测试第三次作业——习题2.3.7的相关文章

软件测试第三次作业 课后习题7

一.题目要求 使用下面方法printPrimes()完成后面的问题(a)-(d): 代码如下: /******************************************************* * Finds and prints n prime integers * Jeff Offutt, Spring 2003 ******************************************************/ public static void printPr

软件测试第三次作业

这次作业主要是根据代码,画出控制流图,并涉及计边覆盖,点覆盖,主路径的知识. 具体作业内容如下 /******************************************************* * Finds and prints n prime integers * Jeff Offutt, Spring 2003 ******************************************************/ public static void printPr

软件测试第三周作业——测试多个输入的合法性

这次作业,我用JavaFX来写程序测试输入的合法性 这是我的输入界面截图, 三个框同时输入, 按submit即可测试三个输入的合法性, 最后在控制台显示测试结果 测试用例: 等价类的划分: 有效等价类:长度1-6,仅含有a-z,A-Z,0-9的字符 无效等价类:长度0或大于7,含有但并不一定都是除a-z,A-Z,0-9以外的字符,控制字符.标点符号等. 以下是测试用例 第一次测试: 输入: er43t dgddsgdfg fds!# 输出: OK 所有输入长度应为1-6 所有输入字符应为a-z,

软件测试 第三次作业

1. 计算整数X和整数Y的最大公约数.(不允许采用课堂上所用的方式实现). 请用类和方法(写一个求最大公约数的方法)实现,命名时请按照规范命名.在main方式中获取用户输入的两个整数,调用之前写的方法,输出它们的最大公约数.利用FindBugs查找程序中是否存在bug. Demo类 package cn.wu.test; public class Demo { /** * @param args */ public static void main(String[] args) { // TOD

软件测试第三次作业2

2. 逻辑覆盖的应用 l         按照所给的程序流程图,写出Java代码(用类和方法实现) l         写出语句覆盖.分支覆盖的测试用例,以及它所覆盖的路径,用JUnit编写测试用例进行测试 package HAN; import java.util.Scanner; /** * * @author hanzhenyi * 2016.4.7 * 2. 逻辑覆盖的应用 */ public class two { public static void main(String[] ar

软件测试第三次作业1

1. 计算整数X和整数Y的最大公约数.(不允许采用课堂上所用的方式实现) l         请用类和方法(写一个求最大公约数的方法)实现,命名时请按照规范命名. l         在main方式中获取用户输入的两个整数,调用之前写的方法,输出它们的最大公约数. l         利用FindBugs查找程序中是否存在bug. package HAN; import java.util.Scanner; /** * @author hanzhenyi * 2016.4.7 * 1. 计算整数

软件测试第三次作业——7.使用下面方法printPrimes()完成后面的问题(a)~(f)

(a)控制流图如下: (b)令MAXPRIMES=4,会出现越界错误. (c)令n=1,不会经过while循环体. (d)节点覆盖:{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15} 边覆盖:{(1,2),(2,3),(3,4),(4,5),(5,6),(6,7),(6,8),(8,5),(5,9),(7,9),(9,10),(10,11),(9,11),(11,2),(2,12),(12,13),(13,14),(14,13),(13,15)} 主路径覆盖:{(3,4,

软件测试第三次作业junit和Eclemma的使用

1. 2.将第20行 for(int i = 0; i<=numPrimes-1;i++) 改为 for(int i = 0; i<numPrimes-1;i++) 3.n=2 4.节点覆盖: [0,1,2,3,5,3,4,6,7,8,9,10,11] 边覆盖 [0,1,2,3,5,3,4,6,7,8,9,10,9,10,11] [0,1,2,3,4,7,1,2,3,4,7,8,9,10,11] 主路径覆盖: [0,1,2,3,5,3,5,3,4,6,7,1,2,3,4,7,1,2,3,4,6

软件测试第三次作业:Graph Coverage

package homework3; public class prime { public String printPrimes (int n) { int curPrime; int numPrimes; boolean isPrime; int [] primes = new int [10000]; primes [0] = 2; numPrimes = 1; curPrime = 2; while (numPrimes < n) { curPrime++; isPrime = true