/*******************************************************
* 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的更多相关文章

  1. 软件测试作业3 — PrintPrimes()

    一.Use the following method printPrimes() for questions a–d. (a) Draw the control flow graph for the p ...

  2. 软件测试技术第三次作业——打印质数printPrimes()

    作业一.Use the following method printPrimes() for questions a–d. printPrimes: /** ********************* ...

  3. 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 ...

  4. ST HW3

    7. Use the following method printPrimes() for questions a-f below. /******************************** ...

  5. Software Testing 3

    Questions: • 7. Use the following method printPrimes() for questions a–d. 基于Junit及Eclemma(jacoco)实现一 ...

  6. Struts 配置文件

    web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="htt ...

  7. DevOps之Pipeline集成junit、jacoco、SonarQube(二)

    一.准备工作 1.准备一个持续集成的代码工程 工程下载地址: Github地址为:https://github.com/zbbkeepgoing/springboot-demo 2.springboo ...

  8. 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 ...

  9. The method of using code coverage tool

    Please look at the following blog: http://blog.csdn.net/superqa/article/details/9060521 Use  ReportG ...

随机推荐

  1. 解决:tomcat部署时deploy location不能显示加载后的路径

    项目总是报错,添了删,删了又添了N次以后,发现添加部署的时候,Deploy Location 没有值了,Deploy Location 没有值在自带的Tomcat上就无法用浏览器浏览(Open in ...

  2. ionic build android error when download gradle

    这里我遇到一个问题,当用  ionic build android 的时候,无数次build,无数次失败的时候,我真想骂一句,NND的GNF,我又想起武大的臭鸡蛋,是的,该丢,发明这种东西的人,难道不 ...

  3. 当利用pip安装模块出现错误时咋办

    >在DOS窗口中到Python安装路径的scripts中执行  pip install pyperclip 出现错误 >>错误提示:Fatal error in launcher: ...

  4. 中英文维基百科语料上的Word2Vec实验

    最近试了一下Word2Vec, GloVe 以及对应的python版本 gensim word2vec 和 python-glove,就有心在一个更大规模的语料上测试一下,自然而然维基百科的语料进入了 ...

  5. mac安装paramiko

    $ brew install openssl $ /usr/local/opt/openssl/bin/c_rehash $ export ARCHFLAGS="-arch x86_64&q ...

  6. Activity 横竖屏切换

    前言 在开发中常要处理横竖屏切换,怎么处理先看生命周期 申明 Activity 横竖屏切换时需要回调两个函数 ,所以在此将这个两个函数暂时看成是Activity 横竖屏切换的生命周期的一部分,这两个函 ...

  7. 基础编程-java之股神

    买了一支股票,他知道从他买股票的那天开始,股票会有以下变化:第一天不变,以后涨一天,跌一天,涨两天,跌一天,涨三天,跌一天...依此类推. 为方便计算,假设每次涨和跌皆为1,股票初始单价也为1,请计算 ...

  8. 关于在left join的on子句中限制左边表的取值时出现非期望的结果

    使用的SQL大概是这样的: select * from A left join B on A.id=B.id and A.id>10; --错误的使用 我们期望的结果集应该是 A中的id> ...

  9. 关于区域性网站CMS的一些个人看法

    最近了解了几款国外开源CMS,与现有国内客户需求及业务习惯,结论如下:1.国人的习惯,有后台管理和会员管理2种,而老外大部分开源系统都是一个管理即前台管理,而且大部分架构是固定死的,如果在想抽出一个后 ...

  10. dd-wrt 定时重连 pppoe 更换ip地址

    因为做代理,IP时常被封的原因,所以,需要每天定时重启路由器,重启路由器影响太大,所以重新拨号是一个更好的选择. 在dd-wrt里面,杀掉pppoe服务进程就可以了,这个进程会自动重新启动,然后就相当 ...