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

/*******************************************************
* Finds and prints n prime integers
* Jeff Offutt, Spring 2003
******************************************************/
public String 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 [MAXSIZE]; // 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 (isDivisible(primes[i],curPrime))
{ // 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]);
result = result + primes[i] + " ";
}
} // end printPrimes
}

(a)     Draw the control flow graph for the printPrime() method.

Node 15 is the ending node, but I can't make it a Concentric circle.

(b)    Consider test cases t1=(n=3) and t2=(n=5). Although these tour the same prime paths in ptintPrimes(), they do not necessarily find the same faults. Design a simple fault that t2 would be more likely to discover than t1 would.

When MAXPRIME = 3 or 4, t2 will overflow but it is OK for t1.

(c)     For printPrimes(), find a test case such that the corresponding test path visits the edge that connects the beginning of the while statement to the for statement withtout going through the body of the while loop.

t = (n=1)

(d)

Node Coverage:

TR = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}

Test Path:[1, 2, 3, 4, 5, 6, 7, 5, 6, 8, 9, 10, 11, 2, 12, 13, 14, 13, 15]

Edge Coverage:

TR = {(1,2), (2,3), (3,4), (4,5), (5,6), (5,9), (6,7), (7,5) , (6,8), (8,9), (9,10), (10,11), (9,11), (11,2), (2,12), (12,13), (13,14), (14,13), (13,15)}

Test Path: [1, 2, 3, 4, 5, 6, 7, 5, 6, 8, 9, 10, 11, 2, 12, 13, 14, 13, 15]

[1, 2, 3, 4, 5, 9, 11, 2, 12, 13, 14, 13, 15]

Prime Path Coverage:

[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]

[1, 2, 3, 4, 5, 6, 7, 8, 9, 11]

[1, 2, 3, 4, 5, 6, 7]

[1, 2, 3, 4, 5, 9, 10, 11]

[1, 2, 3, 4, 5, 9, 11]

[1, 2, 12, 13, 14]

[1, 2, 12, 15]

[2, 3, 4, 5, 6, 8, 9, 10, 11, 2]

[2, 3, 4, 5, 6, 8, 9, 11, 2]

[2, 3, 4, 5, 9, 10, 11, 2]

[2, 3, 4, 5, 9, 11, 2]

[3, 4, 5, 6, 8, 9, 10, 11, 2, 3]

[3, 4, 5, 6, 8, 9, 11, 2, 3]

[3, 4, 5, 6, 8, 9, 10, 11, 2, 12, 13, 14]

[3, 4, 5, 6, 8, 9, 11, 2, 12, 13, 14]

[3, 4, 5, 6, 8, 9, 10, 11, 2, 12, 13, 15]

[3, 4, 5, 6, 8, 9, 11, 2, 12, 13, 15]

[3, 4, 5, 9, 10, 11, 2, 12, 13, 14]

[3, 4, 5, 9, 11, 2, 12, 13, 14]

[3, 4, 5, 9, 11, 2, 12, 13, 15]

[3, 4, 5, 9, 10, 11, 2, 12, 13, 15]

[4, 5, 6, 8, 9, 10, 11, 2, 3, 4]

[4, 5, 6, 8, 9, 11, 2, 3, 4]

[4, 5, 9, 11, 2, 3, 4]

[4, 5, 9, 10, 11, 2, 3, 4]

[5, 6, 8, 9, 10, 11, 2, 3, 4, 5]

[5, 6, 8, 9, 11, 2, 3, 4, 5]

[5, 9, 10, 11, 2, 3, 4, 5]

[5, 9, 11, 2, 3, 4, 5]

[5, 6, 7, 5]

[6, 8, 9, 10, 11, 2, 3, 4, 5, 6]

[6, 8, 9, 11, 2, 3, 4, 5, 6]

[6, 7, 5, 6]

[7, 5, 6, 7]

[7, 5, 6, 8, 9, 10, 11, 2, 3, 4]

[7, 5, 6, 8, 9, 11, 2, 3, 4]

[7, 5, 6, 8, 9, 10, 11, 2, 12, 13, 14]

[7, 5, 6, 8, 9, 11, 2, 12, 13, 14]

[7, 5, 6, 8, 9, 11, 2, 12, 13, 15]

[7, 5, 6, 8, 9, 10, 11, 2, 12, 13, 15]

[7, 5, 9, 10, 11, 2, 3, 4]

[7, 5, 9, 11, 2, 3, 4]

[7, 5, 9, 10, 11, 2, 12, 13, 14]

[7, 5, 9, 11, 2, 12, 13, 14]

[7, 5, 9, 10, 11, 2, 12, 13, 15]

[7, 5, 9, 11, 2, 12, 13, 15]

[8, 9, 10, 11, 2, 3, 4, 5, 6, 7]

[8, 9, 11, 2, 3, 4, 5, 6, 7]

[8, 9, 10, 11, 2, 3, 4, 5, 6, 8]

[8, 9, 11, 2, 3, 4, 5, 6, 8]

[9, 10, 11, 2, 3, 4, 5, 6, 8, 9]

[9, 11, 2, 3, 4, 5, 6, 8, 9]

[9, 10, 11, 2, 3, 4, 5, 9]

[9, 11, 2, 3, 4, 5, 9]

[10, 11, 2, 3, 4, 5, 6, 8, 9, 10]

[10, 11, 2, 3, 4, 5, 9, 10]

[11, 2, 3, 4, 5, 6, 8, 9, 10, 11]

[11, 2, 3, 4, 5, 6, 8, 9, 11]

[11, 2, 3, 4, 5, 9, 10, 11]

[11, 2, 3, 4, 5, 9, 11]

[13, 14, 13]

[14, 13, 14]

[14, 13, 15]

基于JunitEclemmajacoco)实现一个主路径覆盖的测试 

My Codes:

https://github.com/newff/st-lab1/tree/newff-hw-3

/**
*
*/
package printPrime; import static org.junit.Assert.*; import org.junit.Before;
import org.junit.Test; /**
* @author lonely
*
*/
public class printPrimeTest { private printPrime printPrime; /**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
printPrime = new printPrime();
} /**
* Test method for {@link printPrime.printPrime#printPrimes(int)}.
*/
@Test
public void testPrintPrimes() {
// assertEquals("2 3 ",printPrime.printPrimes(2));
// assertEquals("2 3 5 ",printPrime.printPrimes(3));
assertEquals("2 3 5 7 ",printPrime.printPrimes(4));
} }

  when n = 2

when n >= 3

if MAXPRIME = 3, n = 4

ST HW3的更多相关文章

  1. BZOJ 4453: cys就是要拿英魂![后缀数组 ST表 单调栈类似物]

    4453: cys就是要拿英魂! Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 90  Solved: 46[Submit][Status][Discu ...

  2. POJ3693 Maximum repetition substring [后缀数组 ST表]

    Maximum repetition substring Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9458   Acc ...

  3. CPU状态信息us,sy,ni,id,wa,hi,si,st含义

    转自:http://blog.csdn.net/sasoritattoo/article/details/9318893 转自:http://fishermen.iteye.com/blog/1995 ...

  4. LCA最近公共祖先 ST+RMQ在线算法

    对于一类题目,是一棵树或者森林,有多次查询,求2点间的距离,可以用LCA来解决.     这一类的问题有2中解决方法.第一种就是tarjan的离线算法,还有一中是基于ST算法的在线算法.复杂度都是O( ...

  5. ST算法

    作用:ST算法是用来求解给定区间RMQ的最值,本文以最小值为例 举例: 给出一数组A[0~5] = {5,4,6,10,1,12},则区间[2,5]之间的最值为1. 方法:ST算法分成两部分:离线预处 ...

  6. poj3368(RMQ——ST)

    Frequent values Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 16543   Accepted: 5985 ...

  7. Scalaz(28)- ST Monad :FP方式适用变量

    函数式编程模式强调纯代码(pure code),主要实现方式是使用不可变数据结构,目的是函数组合(composability)最终实现函数组件的重复使用.但是,如果我们在一个函数p内部使用了可变量(m ...

  8. 泛函编程(34)-泛函变量:处理状态转变-ST Monad

    泛函编程的核心模式就是函数组合(compositionality).实现函数组合的必要条件之一就是参与组合的各方程序都必须是纯代码的(pure code).所谓纯代码就是程序中的所有表达式都必须是Re ...

  9. RMQ(ST算法)

    RMQ(Range Minimum/Maximum Query),即区间最值查询,是指这样一个问题:对于长度为n的数列a,回答若干询问RMQ(A,i,j)(i, j<=n),返回数列a中下标在i ...

随机推荐

  1. 在COM组件中调用JS函数

    要求是很简单的,即有COM组件A在IE中运行,使用JavaScript(JS)调用A的方法longCalc(),该方法是一个耗时的操作,要求通知IE当前的进度.这就要求使用回调函数,设其名称为scri ...

  2. Word常用实用知识3

    纯手打,可能有错别字,使用的版本是office Word 2013 转载请注明出处 http://www.cnblogs.com/hnnydxgjj/p/6322813.html,谢谢. 分页符分页 ...

  3. java基础概略总结

    /*************************************************/ String b=""; String c=""; // ...

  4. 使用 visualstudio code 编辑器调试执行在 homestead 环境中的 laravel 程序

    由于之前做 .net 开发比较熟悉 visualstudio,所以自 visualstudio code 发布后就一直在不同场合使用 vscode ,比如前端.node等等.最近在做 laravel ...

  5. SQL SERVER运维日记--收缩数据库

    一个小故事 某天,小王正在和HR妹妹闲聊,正HAPPY时,,突然收到系统告警消息,数据库磁盘被剩余空间500M,OMG,不行,磁盘快满了,要是业务要停了,,那就小王只能删库到跑路了,,, 先检查下,有 ...

  6. iOS ReactiveCocoa(RAC)学习详解

    概述: ReactiveCocoa(简称为RAC),是由Github开源的一个应用于iOS和OS开发的一个框架,有时间,自己也了解学习了一下这个框架的一些基本的应用,其实你要学的话网上是有很多很多的博 ...

  7. 使用JDBC连接数据库(一)

    JDBC是由java编程语言编写的类及接口组成,同时它为程序开发人员提供了一组用于实现对数据库访问的JDBC API,并支持SQL语言.利用JDBC可以将JAVA代码连接到oracle.DB2.SQL ...

  8. CSS3高级选择器

    CSS3中添加了一些新的选择器 与之前的不同 这些选择器有些类似于jquery的选择器 能够让我们更高的操作DOM 废话不多说 为了更直观的了解 我们以这段为实例 来进行操作 <!DOCTYPE ...

  9. CSS 中的相对量

    CSS 属性的浏览器兼容性,请查询 Can I Use. 已经被标准废弃(Deprecated)的属性,没有列出. 欢迎您与我一同完善这个清单,提供数据的读者姓名将在文中标注. (通过评论方式提供遗漏 ...

  10. 继续学习ant

    今天由于打电话,打了两个小时的电话,结果一下子错过了学习的时间段,表示很惭愧,不过查了一些资料,感觉还不错,明天继续学习吧! ant入门到精通Ant 的最完整build.xml解释ant实用实例Ant ...