作业题目:教材49页第7题a到d,并基于Junit及Eclemma实现一个主路径覆盖的测试
一、Use the following method printPrimes() for questions a-f below

1./** *****************************************************
2. * Finds and prints n prime integers
3. * Jeff Offutt, Spring 2003
4. ********************************************************* */
5. private static void printPrimes (int n)
6. {
7. int curPrime; // Value currently considered for primeness
8. int numPrimes; // Number of primes found so far.
9. boolean isPrime; // Is curPrime prime?
10. int [] primes = new int [MAXPRIMES]; // The list of prime numbers.
11.
12. // Initialize 2 into the list of primes.
13. primes [0] = 2;
14. numPrimes = 1;
15. curPrime = 2;
16. while (numPrimes < n)
17. {
18. curPrime++; // next number to consider ...
19. isPrime = true;
20. for (int i = 0; i <= numPrimes-1; i++)
21. { // for each previous prime.
22. if (isDivisible (primes[i], curPrime))
23. { // Found a divisor, curPrime is not prime.
24. isPrime = false;
25. break; // out of loop through primes.
26. }
27. }
28. if (isPrime)
29. { // save it!
30. primes[numPrimes] = curPrime;
31. numPrimes++;
32. }
33. } // End while
34.
35. // Print all the primes out.
36. for (int i = 0; i <= numPrimes-1; i++)
37. {
38. System.out.println ("Prime: " + primes[i]);
39. }
40. } // end printPrimes

(a) Draw the control flow graph for the printPrimes() method.

(b) Consider test cases t1 = (n = 3) and t2 = (n = 5). Although these tour the
same prime paths in printPrimes(), they do not necessarily find the same faults.
Design a simple fault that t2 would be more likely to discover than t1 would.
数组越界

(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.
t3=(n=1)

(d) Enumerate the test requirements for Node Coverage, Edge Coverage, and Prime
Path Coverage for the graph for printPrimes().
Node Coverage:{0,1,2,3,4,5,6,7,8,9,10,11,12}

Edge Coverage:{(0,1),(1,2),(1,9),(2,3),(3,4),(3,7),(4,5),(4,6),(5,7),(6,3),(7,1),(7,8),(8,1),(9,10),(10,11),(10,12),(11,10)}

Prime Path Coverage:

{(0,1,2,3,4,6),

(0,1,2,3,4,6,7,8),

(0,1,2,3,7,8),

(0,1,9,10,11),

(0,1,9,10,12),

(3,4,6,3),

(4,6,3,4),

(6,3,4,6),

(6,3,4,5,7,8,1,2),

(6,3,4,5,7,8,1,9,10,11),

(6,3,4,5,7,8,1,9,10,12),

(6,3,7,8,1,2),

(6,3,7,8,1,9,10,11),

(6,3,7,8,1,9,10,12),

(10,11,10),

(11,10,11)}

二、主路径覆盖测试

以第一次上机判断三角形程序为例

Calculator.java

 1 package moody;
 2 public class Calculator {
 3     private static int result = 0;
 4     public void triangle(int a,int b,int c)
 5     {
 6         if((a+b)>c && (a+c)>b && (b+c)>a && a>0 && b>0 && c>0)//判断是否构成三角形
 7         {
 8             if((a==b)||(a==c)||(b==c))
 9             {
10                 if((a == b)&&(a == c))
11                 {
12                     result = 3;//等边
13                 }
14                 else
15                 {
16                     result = 2;//等腰
17                 }
18
19             }
20             else
21             {
22                 result = 1;//普通
23             }
24         }
25
26         else
27         {
28             result = 0;//不是三角形
29         }
30
31     }
32     public int getReuslt(){
33         return result;
34     }
35 }

TestCalculator.java

 1 package moody;
 2 import static org.junit.Assert.*;
 3 import org.junit.Test;
 4 public class TestCalculator {
 5     private static Calculator cal = new Calculator();
 6     @Test
 7     public void testTriangle(){
 8
 9     cal.triangle(2, 2, 2);
10     assertEquals(3, cal.getReuslt());//等边三角形
11     cal.triangle(3, 3, 5);
12     assertEquals(2, cal.getReuslt());//等腰三角形
13     cal.triangle(2, 3, 4);
14     assertEquals(1, cal.getReuslt());//普通三角形
15     cal.triangle(1, 2, 3);
16     assertEquals(0, cal.getReuslt());//不能构成三角形
17     cal.triangle(-1, 5, 3);
18     assertEquals(0, cal.getReuslt());//不能构成三角形
19     }
20
21 }

覆盖率截图

转载于:https://www.cnblogs.com/moody/p/5338677.html

TJUSCSST第三次作业相关推荐

  1. OO第三单元作业总结

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    本文是 2021年春季学期-信号与系统-第三次作业参考答案 中的参考答案. ▌第七道题 7.有一系统对激励e1(t)=u(t)e_1 \left( t \right) = u\left( t \rig ...

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

    本文是 2021年春季学期-信号与系统-第三次作业参考答案 中的参考答案. ▌第六道题 6.给定系统微分方程: 若激励信号和起始状态为以下两种情况: (1) e(t)=u(t),r(0−)=2,r′( ...

最新文章

  1. 少样本学习原理快速入门,并翻译《Free Lunch for Few-Shot Learning: Distribution Calibration》
  2. 美多商城之用户中心(用户基本信息)
  3. tac rev cat命令使用范例
  4. 爬虫篇——selenium(webdriver)进行用户登录并爬取数据)
  5. java 正规 忽略,java-正则表达式查找变量并忽略方法
  6. C++实现有向图最短路径-Dijkstra单源最短路径算法
  7. 《美团机器学习实践》高清PDF+思维导图+美团算法团队
  8. Linux X64下汇编学习:C语言调用汇编代码,汇编中调用C语言函数
  9. python日志保存为html文件,用 Python 抓取公号文章保存成 HTML
  10. Nodejs模块初始化
  11. 使用MSIL 汇编程序 (Ilasm.exe) 2 强签名
  12. Java开发笔记(一百三十一)Swing的列表框
  13. Inferred type 'S' for type parameter 'S' is not within its bound;
  14. python菜鸟教程100例-菜鸟教程python
  15. 在韩家炜老师的实验室和家里作客 — 旅美散记之二
  16. foobox 2.11(foobar2000 CUI配置)
  17. built a JNCIS LAB系列:Chapter 1 Autonomous System Paths v1.0
  18. 2021-02-10微软漏洞通告
  19. 【算法学习】基本的图算法(广搜、深搜、拓扑排序、强连通分量)
  20. 什么原因导致芯片短路_PCB电路板短路的原因及解决方法-EDA/PCB-与非网

热门文章

  1. kubernetes视频教程笔记 (24)-存储-PV和PVC
  2. JavaSE基础——多态、抽象类、接口
  3. 物联网空开价格_北斗星C2物联网蒸箱集成灶618价格提前开抢,转发送豪礼
  4. 贞炸了!上线之后,消息收不到了!
  5. Docker日志自动化: ElasticSearch、Logstash、Kibana以及Logspout
  6. 阶段3 2.Spring_03.Spring的 IOC 和 DI_5 BeanFactory和ApplicationContext的区别
  7. react里 MD5加密
  8. C#学习笔记(十八):数据结构和泛型
  9. nodejs语法问题
  10. oracle常用操作命令总结