test homework ~ coverage about method printPrimes
/*******************************************************
* 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
First:
a. first draw the control flow graph, and we use the online tool (processon) to draw it.
here is the result:

b. there are two test case t1=(n=3) and t2=(n=5),if t2 is easier to find a error than t1, it can be the boundary question.
if the list size(MAXSIZE=4) is 4. then t1 cannot find this error. However t2 willl find it.
c. t=(n=1) don't pass throught the while body and just pass while header and for loop.
d. point coverage {1,2,3,4,5,6,7,8,9,10,11,12,13}
edge coverage {(1,2),(2,3),(3,4),(4,5),(4,6),(5,8),(5,9),(6,4),(6,7),(7,5),(8,9),(9,1),(1,10),(10,11),(11,12),(11,13),(12,11)}
prime path coverage {(1,10,11,12)
(1,10,11,13)
(11,12,11)
(12,11,12)
(1,2,3,4,5,8,9,1)
(1,2,3,4,5,9,1)
(1,2,3,4,6,7,5,8,9,1)
(1,2,3,4,6,7,5,9,1)
(4,6,4)
(6,4,6)}
Second: use junit to achieve the goal about prime path coverage for any program
code
package testHomework;
public class triangle {
public String typeOfTriangle (int a, int b,int c)
{
String type = "not";
if(a+b>c && a+c>b && c+a>b){
type = "scalene";
if(a==b || a==c || b==c){
type="isosceles";
if(a==b && b==c)
type="equilateral";
}
return type;
}
else{
return type;
}
}
}
package testHomework;
import static org.junit.Assert.assertEquals; import java.util.Arrays;
import java.util.Collection; import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters; import testHomework.triangle; @RunWith(Parameterized.class)
public class triangleTest {
private String type;
private int a;
private int b;
private int c; public triangleTest(String type, int a, int b, int c){
this.type = type;
this.a = a;
this.b = b;
this.c = c;
}
@Parameters
public static Collection prepareData(){
Object[][] object = {
{"not",1,1,2},{"equilateral",1,1,1},
{"isosceles",2,2,3},{"scalene",2,3,4}};
return Arrays.asList(object);
}
@Test
public void TestTypeOfTriangle()
{
triangle triangle = new triangle ();
assertEquals (type, triangle.typeOfTriangle(a,b,c)); } }
the test case set T={(1,1,2),(1,1,1),(2,2,3),(2,3,4)} can achieve it for prime path coverage
test homework ~ coverage about method printPrimes的更多相关文章
- 软件测试作业3 — PrintPrimes()
一.Use the following method printPrimes() for questions a–d. (a) Draw the control flow graph for the p ...
- 软件测试技术第三次作业——打印质数printPrimes()
作业一.Use the following method printPrimes() for questions a–d. printPrimes: /** ********************* ...
- 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 ...
- ST HW3
7. Use the following method printPrimes() for questions a-f below. /******************************** ...
- Software Testing 3
Questions: • 7. Use the following method printPrimes() for questions a–d. 基于Junit及Eclemma(jacoco)实现一 ...
- Struts 配置文件
web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="htt ...
- DevOps之Pipeline集成junit、jacoco、SonarQube(二)
一.准备工作 1.准备一个持续集成的代码工程 工程下载地址: Github地址为:https://github.com/zbbkeepgoing/springboot-demo 2.springboo ...
- Development of a High Coverage Pseudotargeted Lipidomics Method Based on Ultra-High Performance Liquid Chromatography−Mass Spectrometry(基于超高效液相色谱-质谱法的高覆盖拟靶向脂质组学方法的开发)
文献名:Development of a High Coverage Pseudotargeted Lipidomics Method Based on Ultra-High Performance ...
- The method of using code coverage tool
Please look at the following blog: http://blog.csdn.net/superqa/article/details/9060521 Use ReportG ...
随机推荐
- centos7 web服务器内核优化
net.ipv4.tcp_syn_retries = 1net.ipv4.tcp_synack_retries = 1net.ipv4.tcp_keepalive_time = 600net.ipv4 ...
- java实现excel表格导出数据
/** * 导出清单 eb中 firstRow(EntityBean) 列表第一行数据,键值对(不包含序号)例:("name","姓名") * data(Ent ...
- java内省机制及PropertyUtils使用方法
背景 一般情况下,在Java中你可以通过get方法轻松获取beans中的属性值.但是,当你事先不知道beans的类型或者将要访问或修改的属性名时,该怎么办?Java语言中提供了一些像java.bean ...
- C++程序员如何入门Unreal Engine 4
摘要: 一位程序员网友小保哥分享自己的UE4快速上手过程,只是笔记,52VR做了一点更加适合阅读的修改,整理给大家. 首先,本文只是针对有比较熟练C++技能的程序员,他可以没有任何图形学或游戏引擎方面 ...
- uva 147 Dollars
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- hdu 1556
Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- android案例一 电话拨号器
效果图: 电话拨号器的核心原理: 意图 MainActivity代码: private EditTest et_number; //加载一个布局 setContentView(R.l ...
- iOS 开发:利用第三方插件来安装CoCoapods
引言:通过上一篇博客我们知道了怎么样去通过终端来安装CoCoapods,这一篇我们着重与用第三方插件来安装CoCoapods: 1. 首先在提下链接下载插件 https://github.com/ka ...
- 纳尼,java可以在接口中实现非抽象方法了?
纳尼,接口中可以定义实例方法了?! 纳尼,接口中还可以定义静态方法了?! 没错,在Java8中新增了很多新的特性,其中就包括可以在接口中添加方法和变量. 首先我们来看下代码 public interf ...
- 无语啊,sublime给我弄乱玩,玩坏了,而且安装插件也安装不了
国内的什么插件地址都TMMD失效了,没办法,只能翻"强"到外面找了,而且找了很多也用不了,所以收藏一个为了预防以后不行有补救的方法: 百度的99%都不行,不是报这个错就是那个错,可 ...