ST HW3
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, 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]
[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]
基于Junit及Eclemma( jacoco)实现一个主路径覆盖的测试
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的更多相关文章
- BZOJ 4453: cys就是要拿英魂![后缀数组 ST表 单调栈类似物]
4453: cys就是要拿英魂! Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 90 Solved: 46[Submit][Status][Discu ...
- POJ3693 Maximum repetition substring [后缀数组 ST表]
Maximum repetition substring Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9458 Acc ...
- CPU状态信息us,sy,ni,id,wa,hi,si,st含义
转自:http://blog.csdn.net/sasoritattoo/article/details/9318893 转自:http://fishermen.iteye.com/blog/1995 ...
- LCA最近公共祖先 ST+RMQ在线算法
对于一类题目,是一棵树或者森林,有多次查询,求2点间的距离,可以用LCA来解决. 这一类的问题有2中解决方法.第一种就是tarjan的离线算法,还有一中是基于ST算法的在线算法.复杂度都是O( ...
- ST算法
作用:ST算法是用来求解给定区间RMQ的最值,本文以最小值为例 举例: 给出一数组A[0~5] = {5,4,6,10,1,12},则区间[2,5]之间的最值为1. 方法:ST算法分成两部分:离线预处 ...
- poj3368(RMQ——ST)
Frequent values Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 16543 Accepted: 5985 ...
- Scalaz(28)- ST Monad :FP方式适用变量
函数式编程模式强调纯代码(pure code),主要实现方式是使用不可变数据结构,目的是函数组合(composability)最终实现函数组件的重复使用.但是,如果我们在一个函数p内部使用了可变量(m ...
- 泛函编程(34)-泛函变量:处理状态转变-ST Monad
泛函编程的核心模式就是函数组合(compositionality).实现函数组合的必要条件之一就是参与组合的各方程序都必须是纯代码的(pure code).所谓纯代码就是程序中的所有表达式都必须是Re ...
- RMQ(ST算法)
RMQ(Range Minimum/Maximum Query),即区间最值查询,是指这样一个问题:对于长度为n的数列a,回答若干询问RMQ(A,i,j)(i, j<=n),返回数列a中下标在i ...
随机推荐
- Nancy简单实战之NancyMusicStore(二):打造首页
前言 继上一篇搭建好项目之后,我们在这一篇中将把我们NancyMusicStore的首页打造出来. 布局 开始首页之前,我们要先为我们的整个应用添加一个通用的布局页面,WebForm中母版页的概念. ...
- printf 格式化输出
i,d 十进制整数 x,X 十六进制无符号整数 o 八进制无符号整数 u 无符号十进制整数 c 单一字符 s 字符串 e E 指数形式浮 ...
- Spring集成MyBatis框架
Java在写数据库查询时,我接触过四种方式: 1.纯Java代码,引用对应的数据库驱动包,自己写连接与释放逻辑(可以用连接池) 这种模式实际上性能是非常不错的,但是使用起来并不是非常方便:一是要手工为 ...
- GTK+基本图元的绘制
// main.c #include <gtk/gtk.h> static void draw_round_rectangle (cairo_t * cr, double x, doubl ...
- 前端基本知识(一):W3C标准&&冒泡事件,捕获事件,W3C DOM对象模型,对比分析
W3C标准是万维网联盟, 其他的可以参考万维网版本的更新内容 一.W3C标准 二.W3C DOM事件 三.冒泡事件 四.捕获事件 一.W3C标准 其实网页是由三分部组成:1.结构(structure) ...
- WKWebView的使用与JS交互详细解读
前言: WKWebView 这是在iOS8.0之后增加的一个比UIWebView更加完善和强大的控件!看网上关于它的博客也是有许多的了,从各个方面总结一下这个WKWebView看网上说它主要是为了和J ...
- PLSQL程序流程
IF语句结构: if(条件表达式)- -then- -执行语句;- -end; IF-THEN-ELSE语句结构: if(条件表达式)- -then- -执行语句;- -else- -执行语句;- e ...
- Android jni 编程4(对基本类型二维整型数组的操作)
Android jni 编程 对于整型二维数组操作: 类型一:传入二维整型数组,返回一个整型值 类型二:传入二维整型数组,返回一个二维整型数组 声明方法: private native int Sum ...
- ReentrantLock实现原理
以下是本篇文章的大纲 1 synchronized和lock 1.1 synchronized的局限性 1.2 Lock简介 2 AQS 3 lock()与unlock()实现原理 3.1 基础知识 ...
- phpcms如何做企业站--> 替换首页最初操作
首先用一个静态首页的模板,通过cms进行替换做成一个有后台的 首页的替换流程首先要先把静态网页做出来,拿这个页面去替换 页面所有的文件都在这,做静态页面的文件 现在要做的是把这些文件复制一下拿到php ...