printPrime()代码:

/******************************************************* * Finds and prints n prime integers * Jeff Offutt, Spring 2003 ******************************************************/ 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 [] 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

a)control flow graph

b)

first condition:   if test case (n = 5) finds the error first, if should execute the error code first. So if in node 7,

isPrime = false became isPrime = true, t2(n=5) will find it first.

second condition:  MAXPRIMES = 4, array out of bounds

c)

n=1

d)

Len0

[1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11], [12], [13]!

Len1

[1,2],[2,3],[2,10],[3,4],[4,5],[4,8],[5,6],[5,7],[6,4],[7,8],[8,2],[8,9],[9,2],[10,11],[11,12],[11,13]!,[12,11]

Len3

  [1,2,3,4],[1,2,10,11],[2,3,4,8],[2,3,4,5],[2,10,11,12],[2,10,11,13]!,[3,4,5,6],[3,4,5,7],[3,4,8,2],[3,4,8,9],[4,5,6,4]*,[4,5,7,8],[4,8,9,2],[4,8,2,3],[4,8,2,10],[5,6,4,5]*,[5,6,4,8],[5,7,8,9],[5,7,8,2],[6,4,5,6]*,[6,4,5,7],[6,4,8,2],[6,4,8,9],[7,8,2,3],[7,8,2,10],[7,8,9,2],[8,2,3,4],[8,2,10,11],[8,9,2,3],[8,9,2,10],[9,2,3,4],[9,2,10,11]

Len5

  [1,2,3,4,5,6],[1,2,3,4,5,7],[1,2,3,4,8,9],[2,3,4,5,7,8],[2,3,4,8,9,2]*,[3,4,5,7,8,9],[3,4,5,7,8,2],[3,4,8,9,2,3]*,[3,4,8,9,2,10],[3,4,8,2,10,11],[4,5,7,8,2,3],[4,5,7,8,2,10],[4,5,7,8,9,2],[4,8,9,2,3,4]*,[4,8,9,2,10,11],[4,8,2,10,11,12],[4,8,2,10,11,13]!,[5,6,4,8,9,2],[5,6,4,8,2,3],[5,6,4,8,2,10],[5,7,8,2,3,4],[5,7,8,2,10,11],[5,7,8,9,2,3],[5,7,8,9,2,10],[6,4,5,7,8,2],[6,4,5,7,8,9],[6,4,8,2,10,11],[6,4,8,9,2,3],[6,4,8,9,2,10],[7,8,9,2,3,4],[7,8,9,2,10,11],[7,8,2,3,4,5],[7,8,2,10,11,12],[7,8,2,10,11,13]!,[7,8,9,2,3,4],[7,8,9,2,10,11],[8,2,3,4,5,6],[8,2,3,4,5,7],[8,9,2,3,4,5],[8,9,2,3,4,8]*,[8,9,2,10,11,12],[8,9,2,10,11,13]!,[9,2,3,4,5,6],[9,2,3,4,5,7],[9,2,3,4,8,9]*

Len7

  [1,2,3,4,5,7,8,9],[2,3,4,5,7,8,9,2]*,[3,4,5,7,8,9,2,10],[3,4,5,7,8,2,10,11],[4,5,7,8,2,10,11,12],[4,5,7,8,2,10,11,13]!,[4,5,7,8,9,2,3,4]*,[4,5,7,8,9,2,10,11],[5,6,4,8,2,10,11,12],[5,6,4,8,2,10,11,13]!,[5,6,4,8,9,2,10,11],[5,7,8,9,2,3,4,5]*,[5,7,8,9,2,10,11,12],[5,7,8,9,2,10,11,13]!,[6,4,5,7,8,2,10,11],[6,4,5,7,8,9,2,3],[6,4,5,7,8,9,2,10],[6,4,8,9,2,10,11,12],[6,4,8,9,2,10,11,13]!,[7,8,9,2,3,4,5,6],[7,8,9,2,3,4,5,7]*,[8,9,2,3,4,5,7,8]*.[9,2,3,4,5,7,8,9]*

Len9

  [3,4,5,7,8,9,2,10,11,12],[3,4,5,7,8,9,2,10,11,13]!,[6,4,5,7,8,9,2,10,11,12],[6,4,5,7,8,9,2,10,11,13]!

So, the TR = {[11,12,11],[12,11,12],[4,5,6,4],[5,6,4,5],[6,4,5,6],[1,2,10,11,12],[1,2,10,11,13], [2,3,4,8,2], [3,4,8,2,3], [4,8,2,3,4] ,[8,2,3,4,8],[1,2,3,4,5,6],[1,2,3,4,8,9],[2,3,4,8,9,2],[3,4,8,9,2,3], [4,8,9,2,3,4], [5,6,4,8,2,3],[8,9,2,3,4,8],[9,2,3,4,8,9],[2,3,4,5,7,8,2],[3,4,5,7,8,2,3],[4,5,7,8,2,3,4],[5,6,4,8,9,2,3],[5,7,8,2,3,4,5],[6,4,5,7,8,2,3],[7,8,2,3,4,5,6],[7,8,2,3,4,5,7],[8,2,3,4,5,7,8],[1,2,3,4,5,7,8,9],[2,3,4,5,7,8,9,2], [4,5,7,8,9,2,3,4],[5,6,4,8,2,10,11,12],[5,6,4,8,2,10,11,13],[5,7,8,9,2,3,4,5],[6,4,5,7,8,9,2,3],[7,8,9,2,3,4,5,6],[7,8,9,2,3,4,5,7],[8,9,2,3,4,5,7,8].[9,2,3,4,5,7,8,9],[3,4,5,7,8,2,10,11,12],[3,4,5,7,8,2,10,11,13],[5,6,4,8,9,2,10,11,12],[5,6,4,8,9,2,10,11,13],[6,4,5,7,8,2,10,11,12],[6,4,5,7,8,2,10,11,13],[3,4,5,7,8,9,2,10,11,12],[3,4,5,7,8,9,2,10,11,13],[6,4,5,7,8,9,2,10,11,12],[6,4,5,7,8,9,2,10,11,13]}

2、基于Junit及Eclemma(jacoco)实现一个主路径覆盖的测试。

if we want to test the printPrime(), we shoule use method assertEquals(), so I changed the  return type from

void to String, here is the changed text.

package printPrime;public class printPrimePro {private static final int MAXPRIMES = 1000; public static String printPrimes (int n) { int curPrime; // Value currently considered for primeness int numPrimes; // Number of primes found so far. boolean isPrime; // Is curPrime prime? String str = ""; 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++) { str += primes[i]+" "; } return str; } // end printPrimes  }

test code

package printPrime;import static org.junit.Assert.*;import org.junit.Before; import org.junit.Test; public class printPrimeTest { public printPrimePro testPrime = new printPrimePro(); @Before public void setUp() throws Exception { } @Test public void testPrintPrimes() { assertEquals("2 3 5 ", testPrime.printPrimes(3)); } }

the coverage is 100%!

转载于:https://www.cnblogs.com/jinteng/p/8647965.html

软件测试——第三次作业相关推荐

  1. 软件测试第三次作业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.节点覆 ...

  2. 软件测试 第三次作业

    (a) 将就一下锻炼颈椎吧,废了半天劲也没把图片正过来 (b) 改为isDivisiable( primes[0], curPrime) (c) n = 1 (d) Node Coverage: { ...

  3. OO第三单元作业总结

    OO第三次作业总结 一.JML (一)JML语言理论基础 (1)JML表达式: JML表达式包括以下几种: 原子表达式如\result(方法执行后的返回值).\old(表达式在相应方法执行前的取值): ...

  4. 程序设计第三次作业附加 代码规范

    题目:第三次作业附加 myGithub 我的程序设计第三次作业 Calculator.h //==============================// //文件名称:calculator.h ...

  5. JML规格编程——BUAA OO第三单元作业总结

    整体概述 这个单元整体围绕Java Model Language(JML)展开,通过学习JML规格了解契约式编程的过程,课上实验中进行了JML规格的简要编写,课下实验主要通过阅读规格并按照规格的要求正 ...

  6. 2021年人工神经网络第三次作业-第二题:遗传算法与人工神经网络-参考答案

    简 介: 给出了对于BP网络求解异或问题过程中,利用遗传算法完成网络演变的过程.所使用的遗传算法是最基本的遗传算法.利用遗传算法对于网络的系数进行演变,可以对网络系数初始化过程进行优化.对于不同的遗传 ...

  7. 2021年春季学期-信号与系统-第三次作业参考答案-第十一道题

    本文是 2021年春季学期-信号与系统-第三次作业参考答案 中的参考答案. ▌第十一道题 11. 如果已知系统的输入输出关系可以使用二阶常系数 差分方程来描述.如果相应输入为:x[n]=u[n]x\l ...

  8. 2021年春季学期-信号与系统-第三次作业参考答案-第十道题

    本文是 2021年春季学期-信号与系统-第三次作业参考答案 中的参考答案. ▌第十道题 10. 求解差分方程: (1)第一小题 y[n]=−5y[n−1]+ny\left[ n \right] = - ...

  9. 2021年春季学期-信号与系统-第三次作业参考答案-第九道题

    本文是 2021年春季学期-信号与系统-第三次作业参考答案 中的参考答案. ▌第九道题 9. 已知因果线性时不变系统的输入输出之间的微分方程为: ddty(t)+5y(t)=∫−∞∞x(τ)f(t−τ ...

  10. 2021年春季学期-信号与系统-第三次作业参考答案-第八道题

    本文是 2021年春季学期-信号与系统-第三次作业参考答案 中的参考答案. ▌第八道题 8. 某LTI系统,输入信号e(t)=2e−3tu(t)e\left( t \right) = 2e^{ - 3 ...

最新文章

  1. 为什么在C中需要使用volatile?
  2. SAP 解决长时间不操作掉线问题
  3. 异步和同步区别是什么_一次相亲经历,我彻底搞懂了什么叫阻塞非阻塞,同步异步...
  4. IO对象不可以复制或者赋值
  5. 《关键对话——从“心”开始,如何确定目标》读书笔记(三)
  6. mysql 数据查询优化_优化MySQL数据库查询的三种方法
  7. 事业编,还有前途可谈么?
  8. php7版本搭建sqli labs,CentOS 7 LAMP搭建并且部署sqli-labs
  9. 每日N题—数据结构题集
  10. Java学习笔记:统计视频播放量
  11. Smart3D系列教程5之 《案例实战演练2——大区域的地形三维重建》
  12. 物联网导论知识部分梳理
  13. (转)简体繁体转换代码(Big5-GB | GBK简体-GBK繁体)
  14. 【建议收藏】六个免费的在线OCR识别网站,显著提高你的工作效率!
  15. ConvE,知识图谱嵌入(KGE) autodl 服务器运行
  16. 解决“事件ID(487)的描述(在资源(Zend Optimizer)中)无法找到”问题
  17. 2019第九届中国测绘地理信息技术装备博览会
  18. 房产抵押贷款需要的资质有哪些
  19. 关于go在函数退出后子协程的退出问题
  20. Ue4 UI优化文档整理理解

热门文章

  1. 五、K8s pod相关操作(1)
  2. Python3的os.popen()与subprocess使用(关于数据处理)
  3. 操作系统习题解答 (张尧学) 第一章
  4. 从头开始学Android之(一)——— Android架构
  5. 2015年Java开发岗位面试题归类
  6. linux 分区 LVM 挂载
  7. MySQL学习笔记之约束条件
  8. dede后台文章不能上传图片及缩略图的解决办法
  9. linspace函数matlab_MATLAB用不同颜色绘制多条曲线
  10. 利用bug来进行调试