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. ThinkPHP学习笔记

    1.什么是框架? 特征一:是一对代码的集合: 特征二:一个半成品的应用: 特征三:包含了一些优秀的设计模式: 定义:框架是一堆包含了常量.方法和类等代码的集合,它是一个半成品的应用,只包含了一些项目开 ...

  2. Distance on the tree

    Distance on the tree https://nanti.jisuanke.com/t/38229 DSM(Data Structure Master) once learned abou ...

  3. pip升级后出现cannot import name 'main'

    运行pip install  --upgrade pip还有出现这个情况. cd /usr/bin/pip3 修改成: from pip import __main__ if __name__ == ...

  4. 批量替换表中某字段的“\t”

    update dbo.Hishop_Products set [Description]=replace(cast([Description] as varchar(8000)),' ',' ')

  5. xmal中的渐变

    <LinearGradientBrush> <LinearGradientBrush.GradientStops> <GradientStop Offset=" ...

  6. Unity3D 物体移动方法总结

    1. 简介 在Unity3D中,有多种方式可以改变物体的坐标,实现移动的目的,其本质是每帧修改物体的position. 2. 通过Transform组件移动物体 Transform 组件用于描述物体在 ...

  7. VBA 删除Excel中所有的图片

    Sub DeletePic()     Dim p As Shape     For Each p In Sheet1.Shapes         If p.Type = Then         ...

  8. 7B - 今年暑假不AC

    “今年暑假不AC?” “是的.” “那你干什么呢?” “看世界杯呀,笨蛋!” “@#$%^&*%...” 确实如此,世界杯来了,球迷的节日也来了,估计很多ACMer也会抛开电脑,奔向电视了.  ...

  9. Oracle 12导出、导入数据

    Precondition: complete the work described in Oracle 12 创建新的数据库实例.用户 1. export data under user " ...

  10. java socket编程(一)简介

    #Java TCP Ip编程 其实下面几张图片就可以解释简单解释tcp-ip协议的大体流程了. ###计算机网络,分组报文和协议 网络是一组通过通信信道相互连接的机器组成. 组与组之间通过路由器连接 ...