printPrime()代码:

    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

a)control flow graph

b)first condition:   if test case (n = 5) finds the error first, if should execute the error code first. So if in node 7,

isPrime = false became isPrime = true, t2(n=5) will find it first.

second condition:  MAXPRIMES = 4, array out of bounds

c)n=1

d)

  Len0

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

Len1

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

Len3

  [1,2,3,4],[1,2,10,11],[2,3,4,8],[2,3,4,5],[2,10,11,12],[2,10,11,13]!,[3,4,5,6],[3,4,5,7],[3,4,8,2],[3,4,8,9],[4,5,6,4]*,[4,5,7,8],[4,8,9,2],[4,8,2,3],[4,8,2,10],[5,6,4,5]*,[5,6,4,8],[5,7,8,9],[5,7,8,2],[6,4,5,6]*,[6,4,5,7],[6,4,8,2],[6,4,8,9],[7,8,2,3],[7,8,2,10],[7,8,9,2],[8,2,3,4],[8,2,10,11],[8,9,2,3],[8,9,2,10],[9,2,3,4],[9,2,10,11]

Len5

  [1,2,3,4,5,6],[1,2,3,4,5,7],[1,2,3,4,8,9],[2,3,4,5,7,8],[2,3,4,8,9,2]*,[3,4,5,7,8,9],[3,4,5,7,8,2],[3,4,8,9,2,3]*,[3,4,8,9,2,10],[3,4,8,2,10,11],[4,5,7,8,2,3],[4,5,7,8,2,10],[4,5,7,8,9,2],[4,8,9,2,3,4]*,[4,8,9,2,10,11],[4,8,2,10,11,12],[4,8,2,10,11,13]!,[5,6,4,8,9,2],[5,6,4,8,2,3],[5,6,4,8,2,10],[5,7,8,2,3,4],[5,7,8,2,10,11],[5,7,8,9,2,3],[5,7,8,9,2,10],[6,4,5,7,8,2],[6,4,5,7,8,9],[6,4,8,2,10,11],[6,4,8,9,2,3],[6,4,8,9,2,10],[7,8,9,2,3,4],[7,8,9,2,10,11],[7,8,2,3,4,5],[7,8,2,10,11,12],[7,8,2,10,11,13]!,[7,8,9,2,3,4],[7,8,9,2,10,11],[8,2,3,4,5,6],[8,2,3,4,5,7],[8,9,2,3,4,5],[8,9,2,3,4,8]*,[8,9,2,10,11,12],[8,9,2,10,11,13]!,[9,2,3,4,5,6],[9,2,3,4,5,7],[9,2,3,4,8,9]*

Len7

  [1,2,3,4,5,7,8,9],[2,3,4,5,7,8,9,2]*,[3,4,5,7,8,9,2,10],[3,4,5,7,8,2,10,11],[4,5,7,8,2,10,11,12],[4,5,7,8,2,10,11,13]!,[4,5,7,8,9,2,3,4]*,[4,5,7,8,9,2,10,11],[5,6,4,8,2,10,11,12],[5,6,4,8,2,10,11,13]!,[5,6,4,8,9,2,10,11],[5,7,8,9,2,3,4,5]*,[5,7,8,9,2,10,11,12],[5,7,8,9,2,10,11,13]!,[6,4,5,7,8,2,10,11],[6,4,5,7,8,9,2,3],[6,4,5,7,8,9,2,10],[6,4,8,9,2,10,11,12],[6,4,8,9,2,10,11,13]!,[7,8,9,2,3,4,5,6],[7,8,9,2,3,4,5,7]*,[8,9,2,3,4,5,7,8]*.[9,2,3,4,5,7,8,9]*

Len9

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

So, the TR = {[11,12,11],[12,11,12],[4,5,6,4],[5,6,4,5],[6,4,5,6],[1,2,10,11,12],[1,2,10,11,13], [2,3,4,8,2], [3,4,8,2,3], [4,8,2,3,4] ,[8,2,3,4,8],[1,2,3,4,5,6],[1,2,3,4,8,9],[2,3,4,8,9,2],[3,4,8,9,2,3], [4,8,9,2,3,4], [5,6,4,8,2,3],[8,9,2,3,4,8],[9,2,3,4,8,9],[2,3,4,5,7,8,2],[3,4,5,7,8,2,3],[4,5,7,8,2,3,4],[5,6,4,8,9,2,3],[5,7,8,2,3,4,5],[6,4,5,7,8,2,3],[7,8,2,3,4,5,6],[7,8,2,3,4,5,7],[8,2,3,4,5,7,8],[1,2,3,4,5,7,8,9],[2,3,4,5,7,8,9,2], [4,5,7,8,9,2,3,4],[5,6,4,8,2,10,11,12],[5,6,4,8,2,10,11,13],[5,7,8,9,2,3,4,5],[6,4,5,7,8,9,2,3],[7,8,9,2,3,4,5,6],[7,8,9,2,3,4,5,7],[8,9,2,3,4,5,7,8].[9,2,3,4,5,7,8,9],[3,4,5,7,8,2,10,11,12],[3,4,5,7,8,2,10,11,13],[5,6,4,8,9,2,10,11,12],[5,6,4,8,9,2,10,11,13],[6,4,5,7,8,2,10,11,12],[6,4,5,7,8,2,10,11,13],[3,4,5,7,8,9,2,10,11,12],[3,4,5,7,8,9,2,10,11,13],[6,4,5,7,8,9,2,10,11,12],[6,4,5,7,8,9,2,10,11,13]}

2、基于Junit及Eclemma(jacoco)实现一个主路径覆盖的测试。

if we want to test the printPrime(), we shoule use method assertEquals(), so I changed the  return type from

void to String, here is the changed text.

package printPrime;

public class printPrimePro {

    private static final int MAXPRIMES = 1000;

    public static String printPrimes (int n)
{
int curPrime; // Value currently considered for primeness
int numPrimes; // Number of primes found so far.
boolean isPrime; // Is curPrime prime?
String str = "";
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++)
{
str += primes[i]+" ";
} return str;
} // end printPrimes }

test code

package printPrime;

import static org.junit.Assert.*;

import org.junit.Before;
import org.junit.Test; public class printPrimeTest {
public printPrimePro testPrime = new printPrimePro();
@Before
public void setUp() throws Exception {
}
@Test
public void testPrintPrimes() {
assertEquals("2 3 5 ", testPrime.printPrimes(3));
}
}

the coverage is 100%.

软件测试-homework3的更多相关文章

  1. 软件测试基础homework3

    //本次的作业为/******************************************************* * Finds and prints n prime integers ...

  2. 小公司0成本基于Pythony的单元\GUI\Web自动化\性能的几个开源软件测试工具

    以下是当前流行的几款适合小公司0成本的几个开源软件测试解决方案: 1.单元测试 a.unittest :Python自带的单元测试框架 b.pyunit:Junit的Python版本 2.使用Pyho ...

  3. Anliven - 基础知识梳理汇总 - 软件测试

    基础知识梳理 - 软件测试 - 概念 基础知识梳理 - 软件测试 - 分类 基础知识梳理 - 软件测试 - 流程 基础知识梳理 - 软件测试 - 用例 基础知识梳理 - 软件测试 - 方法 基础知识梳 ...

  4. IEEE829-2008软件测试文档标准介绍

    1998版中定义了一套文档用于8个已定义的软件测试阶段: 测试计划: 一个管理计划的文档 包括:   测试如何完成 (包括SUT的配置).   谁来做测试   将要测试什么   测试将持续多久 (虽然 ...

  5. 自动化测试工具QTP的使用实例 分类: 软件测试 2015-06-17 00:23 185人阅读 评论(0) 收藏

    1. QTP简介 1.1QTP功能与特点 QTP是QuickTest Professional的简称,是一种自动化软件测试工具.在软件的测试过程中,QTP主要来用来通过已有的测试脚本执行重复的手动测试 ...

  6. <<软件测试实战>>读书笔记

    软件测试基础 软件的复杂度已经超越了人的理解能力 1. 虽然高抽象的层次语言,程序框架,程序库等提高了人的生产力,但是还是需要开发者深入理解细节,可以减少开发时间,但是无法减少开发者学习整个技术栈的时 ...

  7. 软件测试基本理论-IBM模式

    软件测试基本理论(1) IBM生产模式 1   参考书目 <IBM-从菜鸟到测试架构师-一个测试工程师的成长日记> 出版社:电子工业出版社 印次:2013年6月 作者:IBM主要工程师 2 ...

  8. 安卓下如何使用JUnit进行软件测试

    软件测试作为程序员必备的一项技能是决定软件开发周期长短以及软件运行成败的关键,可以说好的软件不是代码写得好而是有效的测试决定的.本文将介绍在android下利用eclipse进行开发时如何使用JUni ...

  9. 关于软件测试人员能力模型的建立(from知乎)

    转自: http://www.zhihu.com/question/20254092 测试思维方面:1.测试基础理论(测试流程.测试的基础知识)2.测试用例设计方法论(黑盒.白盒)3.软件质量体系(建 ...

随机推荐

  1. background-attachment: fixed 在iphone设备失效的解决

    下面为引用,源代码有点问题,自己修改了一下.先做记录,回头再细修. 引用部分,但代码有问题 http://www.ptbird.cn/css-background-attachment--fiexed ...

  2. paloalto防火墙安装内容和软件更新

    1.为了确保您始终不会受到最新威胁(包括尚未发现的威胁)的攻击,您必须确保防火墙始终具有 Palo Alto Networks 发布的最新更新内容及软件. • Antivirus(防病毒)— 包括新的 ...

  3. php tp3.2生成二维码

    public function qrcode() { // 二维码链接 $href = 'http://' . $_SERVER['HTTP_HOST'] . '/?g=diapp&m=reg ...

  4. centos7 使用kubeadm 快速部署 kubernetes 国内源

    前言 搭建kubernetes时看文档以及资料走了很多弯路,so 整理了最后成功安装的过程已做记录.网上的搭建文章总是少一些步骤,想本人这样的小白总是部署不成功(^_^). 准备两台或两台以上的虚拟机 ...

  5. python 字典 拼接SQL语句

    def gen_sql(table_name, data):  """ :param table_name: 表名称 :param data: 字典对象 key为字段(要 ...

  6. GUI学习之十——QFrame和的QAbstractScrollArea学习总结

    上一章我们学习了单行的文本框QLineEdit类,下面我们要为多行的文本框的学习坐下准备,总结一下QFrame类和QAbstractScrollArea类 一.QFrame类 1.描述 QFrame的 ...

  7. pd 注意事项

  8. 一、PTA实验作业

    一.PTA实验作业 1.题目1: 6-2 线性表元素的区间删除 2. 设计思路 定义i,j; 判断L,minD,maxD; while(i<l->Last) { 判断所有满足条件的数,de ...

  9. XBee PRO 900HP远距离无线模块

    XBee PRO S3B也称为XBee-900HP无线模块,它是一款工作在频段900~928MHz之间,基于FHSS跳频技术的远距离无线数传电台核心模块.常用型号如下: 类别 型号 开发套件 XKB9 ...

  10. day33 锁和队列

    队列 #put 和  get #__author : 'liuyang' #date : 2019/4/16 0016 上午 11:32 # 多进程之间的数据是隔离的 # 进程之间的数据交互 # 是可 ...