/*******************************************************
* 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. Spring操作指南-AOP基本示例(基于XML)

  2. laravel5.1学习(1)--安装

    主要学习的是laravel5.1版本,服务器用的是wampserver3.0.4集成环境: 首先,安装composer(windows系统) 下载地址:https://getcomposer.org/ ...

  3. 如何将一个Excel文件中的sheet移动到另外一个Excel?

    背景 工作中往往会有多个excel维护的情况,随着业务的变化, 将一个Excel合并到另外一个Excel,成为必须. 如何移动sheet,对于不会的人,这是一个好问题, 也许你经过多次尝试都没有成功. ...

  4. winserver2008 DNS 很详细

    from http://www.it165.net/admin/html/201312/2182.html DNS(Domain Name System域名系统)区域化管理 分布式 层次性 域名空间结 ...

  5. 关于使用FusionCharts生成图表时出现invalid xml data错误提示的解决方法

    FusionCharts的确功能是够强大的.收集的功能估计更强大.在初次使用时,对着手册,一步一步操作,就是生成图表工具不成功.一直报"Invalid xml data"错误.后面 ...

  6. ubuntu 安装transmission最新版

    访问 www.transmissionbt.com   下载最新版 1)下载transmission:#  wget https://transmission.cachefly.net/transmi ...

  7. UIDatePicker日期选取器

    //定义显示日期的格式 NSDateFormatter *dateFormat = [[NSDateFormatter alloc]init]; //NSDateFormatterMediumStyl ...

  8. python中遍历文件的3个方法

    转自: http://www.jb51.net/article/54640.htm 用python进行文件遍历有多种方法,这里列举并说明一下. os.path.walk() 这是一个传统的用法. wa ...

  9. Mac下搭建git

    一.在本地git库中添加用户名及邮箱 git config --global user.name "username" git config --global user.email ...

  10. 盒子模型(W3C盒子模型、IE盒子模型)

    盒子模型:一个物体在页面中所占据的位置 盒子模型包含以下几种元素: padding:margin:content:border 这是大家都知道的,也是书本上定义说明的,但是在ie的情况下是有点区别的; ...