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 ...
随机推荐
- ubuntu开机自动关闭独显,使用集成显卡
我的本子是联想y470p-ise,因为是有双显卡,而ubuntu在开机后,双显卡默认是同时工作,会产生巨大的发热,导致很不爽.而且在ubuntu下基本我也不用独显,所以有开机关闭独显的需求. ubun ...
- 关于OI本地简易评测姬3.0发布的通知
本辣鸡蒟蒻的OI本地评测姬3.0出炉辣.[由wjc大蒟蒻编写,rxb神犇秒秒钟搞出编译器命令行,解决了评测姬编译一大难关并便携化,也为评测姬设计提出了宝贵的建议],目前支持pas和cpp(本辣鸡错了, ...
- 警告1909。无法创建快捷方式VMware Workstation Pro.Ink。解决方法(附 VMware_workstation 12的安装方法)
电脑之前装过VMware 10,很长时间没用就卸载了,也没有在意卸载的干不干净,直到最近需要用Linux系统,重新安装了VMware 12,就出现下面这样的情况: 警告1909.无法创建快捷方式VMw ...
- 微端游戏启动器LAUNCHER的制作之MFC版一(序和进程通信)
额...刚开始信誓旦旦说要写launcher制作的博客,还没写完就被抛到脑后了真是没毅力.最近把之前写的wpf的launcher改成了mfc版,遇到很多问题,写了三个星期才写完,好好记录一下吧.我也想 ...
- OSS.Common获取枚举字典列表标准库支持
上篇(.Net Standard扩展支持实例分享)介绍了OSS.Common的标准库支持扩展,也列举了可能遇到问题的解决方案.由于时间有限,同时.net standard暂时还没有提供对Descrip ...
- 深入浅出妙用 Javascript 中 apply、call、bind
这篇文章实在是很难下笔,因为网上相关文章不胜枚举. 巧合的是前些天看到阮老师的一篇文章的一句话: "对我来说,博客首先是一种知识管理工具,其次才是传播工具.我的技术文章,主要用来整理我还不懂 ...
- 在VMware Workstation 9中安装Mac OS X 10.8 Mountain Lion
本文环境: CPU:Intel Core i7 920: OS:Windows 7: 内存:8G: 玩Hackintosh各有各的理由,不管什么理由,利用虚拟机安装Mac OS X都是一个可行的办法. ...
- linux c++ 加载动态库常用的三种方法
链接库时的搜索路径顺序:LD_LIBRARY_PATH --> /etc/ld.so.conf --> /lib,/usr/lib 方法1. vi .bash_profile 设置环 ...
- 2017-2-19 C#基础 数据类型
数据类型分为基本数据类型和引用类型.基本数据类型分为两大类,值类型,字符型(char)和布尔型(bool).其中值类型分为整型和浮点型.整型分为byte,short,int,long.常用的是int( ...
- Javascript高级程序设计——语法、关键字、保留字、变量、数据类型
1.了解基本语法,JS大小写区分.注释风格.什么是严格模式等. 2.知道ES3和ES5的关键字和保留字大概有哪些,如果使用关键字会报什么错,使用保留字决定于特定浏览器引擎. 3.全局变量和局部变量的定 ...