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 ...
随机推荐
- 使用CTE减少统计子查询
Set Statistics IO ON SET STATISTICS TIME ON --/*--原来语句 DECLARE @CkNo nvarchar(4000),@ProWarn int,@Sk ...
- 数据迁移工具sqoop
有问题........数据迁移工具sqoop sqoop安装 [root@sqoop data]# wget wget http://apache.fayea.com/sqoop/1.4.6/sqo ...
- ActiveMQ 复杂类型的发布与订阅
很久没po文章了,但是看到.Net里关于ActiveMQ发送复杂类型的文章确实太少了,所以贴出来和大家分享 发布: //消息发布 public class Publisher { private IC ...
- ubuntu16.04部署RED5流媒体服务器
前提:jdk已经安装 1,下载RED5(https://github.com/Red5/red5-server/releases)选择red5-server-X.X.X-MXX.tar.gz 2,解压 ...
- oracle同一个数据库实例不同的用户之间的表、序列授权操作
1.背景:用户jtuser中有jtproduct中表A,B的同义词,在用户jtuser中向表A,B插入数据,提示“权限不够” 2.将A,B表授权给jtuser用户 $ sqlplus / as sys ...
- NDK开发历程(一):android native code的调试方法
引用:http://www.cnblogs.com/ychellboy/archive/2013/02/22/2922683.html 使用NDK在android上做开发是一件“痛并快乐着”的差事,之 ...
- 如何写出优雅的Python(二)
Print sorted list: colors=['red','green','blue','yellow'] for color in sorted(colors): print color f ...
- PowerShell 连接SQL
因为对SQL操作比较多,但有些操作其实都是重复性的,只是参数不太一样了,例如silo id, server name 等.希望可以通过powershell脚本提高效率. 尝试如下 1. 使用Power ...
- 自定义子tabBar
基本设置 设置APPIcon(直接拖图片) 设置启动图片 将launch Screen File里的LaunchScreen.xib给删掉 点击launch image source框内的Use As ...
- python之信用卡ATM(第五天)
本节作业 作业需求: 模拟实现一个ATM + 购物商城程序 额度 15000或自定义 实现购物商城,买东西加入 购物车,调用信用卡接口结账 可以提现,手续费5% 每月22号出账单,每月10号为还款日, ...