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
最新文章
- jquery修改css样式,样式带!important
- 通用PE工具箱 4.0精简优化版
- Ioc Autofac心得
- C# 结构转化
- frame和bounds区别
- 配置Hibernate二级缓存步骤
- java log日志的输出。
- 首页在linux下的哪个文件夹
- Android相框 与 源代码结构
- Linux下pecl命令无法执行的解决
- Json简介1
- 我的第一篇博客:vue-cli配置项目
- Windows 远程桌面剪贴板失效的处理办法
- 事件方法on()
- leecode第十四题(最长公共前缀)
- 【CF913F】Strongly Connected Tournament 概率神题
- Ubuntu:系统启动服务
- YBB.DBUtils用法
- Spring Boot干货系列:(五)开发Web应用JSP篇
- Hive UDF IP解析(一):依赖包兼容性问题
热门文章
- dubbo源码分析6-telnet方式的管理实现
- c语言二维数组求最大值
- 画布清理////////////////////////////zzzz
- python执行线程方法
- APICloud开发App总结(一)
- css3样式控制(鼠标滑过 显示标注信息)
- Selenium Chrome浏览器的启动以及proxy设置
- Jersey 2 + Maven + Tomcat + IntelliJ IDEA 搭建RESTful服务
- QFile QDataStream QTextStream
- 安装win7的那些事