作业一.Use the following method printPrimes() for questions a–d.

printPrimes:

 /** *****************************************************
* Finds and prints n prime integers
* Jeff Offutt, Spring 2003
********************************************************* */
private static void printPrimes (int n)
{
int curPrime; // Value currently considered for primeness
int numPrimes; // Number of primes found so far. boolean isPrime; // Is curPrime prime?
int [] primes = new int [MAXPRIMES]; // The list of prime numbers.
// Initialize 2 into the list of primes.
primes [0] = 2;
numPrimes = 1;
curPrime = 2;
while (numPrimes < n)
{
curPrime++; // next number to consider ...
isPrime = true;
for (int i = 0; i <= numPrimes-1; i++)
{ // for each previous prime.
if (isDivisible (primes[i], curPrime))
{ // Found a divisor, curPrime is not prime.
isPrime = false;
break; // out of loop through primes.
}
}
if (isPrime)
{ // save it!
primes[numPrimes] = curPrime;
numPrimes++;
}
} // End while
// Print all the primes out.
for (int i = 0; i <= numPrimes-1; i++)
{
System.out.println ("Prime: " + primes[i]);
}
} // end printPrimes

问题:(a) Draw the control ow graph for the printPrimes() method.

//为printPrimes方法画控制流图:

(b) Considertestcasest1=(n=3)andt2=(n=5).Although these tourthe same prime paths in printPrimes(), they do not necessarily find the same faults.Designasimplefaultthat t2 would bemorelikelytodiscover than t1 would.

//什么情况下测试用例t2(n=5)会比t1(n=3)更有可能发现错误

答:将MAXPRIMES设置为4时,t2会发生数组越界错误,但t1不会发生错误。

(c) For printPrimes(), find a test case such that the corresponding test path visits the edge that connects the beginning of the while statement to the for statement without going through the body of the while loop.

//找一个测试用例,使得测试路径直接从while循环的开始跳到for循环而不经过while循环体

答:当n=1时符合情况

(d) Enumerate the test requirements for node coverage, edge coverage, and prime path coverage for the graph for printPrimes().

//枚举点覆盖,边覆盖,主路径覆盖

答:

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

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

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

作业二:基于JunitEclemmajacoco)实现一个主路径覆盖的测试

修改后的代码,可以直接运行:

public class hw3 {

     public static void printPrimes (int n)
{
int curPrime; // Value currently considered for primeness
int numPrimes; // Number of primes found so far. boolean isPrime; // Is curPrime prime?
int MAXPRIMES = 10;
int [] primes = new int [MAXPRIMES]; // The list of prime numbers.
// Initialize 2 into the list of primes.
primes [0] = 2;
numPrimes = 1;
curPrime = 2;
while (numPrimes < n)
{
curPrime++; // next number to consider ...
isPrime = true;
for (int i = 0; i <= numPrimes-1; i++)
{ // for each previous prime.
if (curPrime%primes[i]==0) //此处原理:所有合数都能被一个小于它的质数整除
{ // Found a divisor, curPrime is not prime.
isPrime = false;
break; // out of loop through primes.
}
}
if (isPrime)
{ // save it!
primes[numPrimes] = curPrime;
numPrimes++;
}
} // End while
// Print all the primes out.
for (int i = 0; i <= numPrimes-1; i++)
{
System.out.println ("Prime: " + primes[i]);
}
} // end printPrimes public static void main(String[] args){
printPrimes(5);
} }

函数输出:

Prime: 2
Prime: 3
Prime: 5
Prime: 7
Prime: 11

利用JUnit生成测试:

import static org.junit.Assert.*;

import org.junit.Test;

public class hw3Test {

    private hw3 test = new hw3();

    @Test
public void testPrintPrimes() {
test.printPrimes(5);
} }

结果:

eclemma覆盖:

软件测试技术第三次作业——打印质数printPrimes()的更多相关文章

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

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

  2. C高级第三次作业

    C高级第三次作业(1) 6-1 输出月份英文名 1.设计思路 (1)算法: 第一步:定义整型变量n,字符指针s,输入一个数赋给n. 第二步:调用函数getmonth将值赋给s. 第三步:在函数getm ...

  3. 2017-2018-1 JaWorld 第三周作业

    2017-2018-1 JaWorld 第三周作业 团队展示 队员学号 队名 团队项目描述 队员风采 团队的特色 团队合照 团队初步合作 前两周的反思与总结 需要改进的地方 团队选题 *采访老师或有开 ...

  4. 耿丹CS16-2班第三次作业汇总

    -- Deadline: 2016-10-12 22:48 -- 作业内容: 1.实验2-6 猜数字游戏 2.实验2-7 判断能否为三角形 3.实验2-8 个人所得税计算器 -- 第三次作业总结: 1 ...

  5. 第三次作业随笔(new)包含了补作业

    第三次作业的题目:http://www.cnblogs.com/fzuoop/p/5187275.html 第一次看到题目的时候觉得应该是挺简单的,只要把输入的那一串东西挨个判断,用数列的方法,如果碰 ...

  6. C语言程序设计第三次作业--选择结构(1)

    Deadline: 2017-10-29 22:00 一.学习要点 掌握关系运算符和关系表达式 掌握如何判断两个实数相等 掌握常用数学函数的使用 掌握逻辑运算符和逻辑表达式 理解逻辑运算的短路特性 掌 ...

  7. JAVA之旅(三十)——打印流PrintWriter,合并流,切割文件并且合并,对象的序列化Serializable,管道流,RandomAccessFile,IO其他类,字符编码

    JAVA之旅(三十)--打印流PrintWriter,合并流,切割文件并且合并,对象的序列化Serializable,管道流,RandomAccessFile,IO其他类,字符编码 三十篇了,又是一个 ...

  8. C#基础第三天-作业答案-集合-冒泡排序-模拟名片

    .冒泡排序 Console.WriteLine("对集合里的数进行排序,请输入第一个数:"); int a = int.Parse(Console.ReadLine()); Con ...

  9. C#基础第三天-作业-集合-冒泡排序-模拟名片

    1.名片:用两种集合(ArrayList/List<>)去输出余下信息.身份证号码,电话号码,性别,姓名,身高,年龄,体重.需求:根据 姓名 去查询某一行数据.如果集合中不存在提示(“自定 ...

随机推荐

  1. C++期中考试

    第一题1. 补足日期类实现,使得能够根据日期获取这是一年中第多少天.(12分) date.h #ifndef DATE_H #define DATE_H class Date { public: Da ...

  2. 换根DP+树的直径【洛谷P3761】 [TJOI2017]城市

    P3761 [TJOI2017]城市 题目描述 从加里敦大学城市规划专业毕业的小明来到了一个地区城市规划局工作.这个地区一共有ri座城市,<-1条高速公路,保证了任意两运城市之间都可以通过高速公 ...

  3. swift -- 单例+ lazy懒加载 + 第三方库

    //工具类单例 static let goods : NHGoods = { let good = NHGoods() return good }() //懒加载 lazy var registerB ...

  4. Python入门8文件处理

    文件处理文本模式name = input("请输入用户名:").strip()with open("a.txt","wt",encoding ...

  5. Photoshop入门教程(四):混合模式

    学习心得:混合模式在Photoshop常容易被忽视,最大原因就是它所处的位置比较隐蔽,在图层面板左上部的角落里.使用混合模式,决定图像中上图层像素如何与图像中的下层像素进行混合,使图层的叠加更加炫酷. ...

  6. 19. Remove Nth Node From End of List(C++,Python)

    Given a linked list, remove the nth node from the end of list and return its head. For example, Give ...

  7. uva 815之理解诡异的海平线题目之不容易

    首先题意:(这个真的令人无奈,题目都看不太明白) 网上百度了一下,就是以下意思: 给你n*m个格子,每个格子的面积是10*10米,整个区域外看作无限高的墙壁.输入每个格子的海拔高度(可能为负数),以及 ...

  8. Dev Express Report 学习总结(四)Dev Express 动态生成XRTable使用总结

    1. XRTableCell常见属性  XRTableCell xrTableCell = new XRTableCell(); A. 字体及字体大小 xrTableCell.Font = new S ...

  9. http 协议的简单学习 虽然有点老但是 还不错

    HTTP简介 HTTP协议是Hyper Text Transfer Protocol(超文本传输协议)的缩写,是用于从万维网(WWW:World Wide Web )服务器传输超文本到本地浏览器的传送 ...

  10. PS使模糊图片变清晰

    操作步骤 \(文件\)