/*******************************************************
* Finds and prints n prime integers
* Jeff Offutt, Spring 2003
******************************************************/
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).为printPrimes()方法画控制流图

(b).第二问其实就是设计一个错误使得t2=(n=5)比t1=(n=3)更容易发现错误

5>3,所以可以设计一个数组越界问题。

(c).测试路径访问连接while语句开始到for语句的边,二不通过while循环体,就是通过了CFG的2—>12这条边。

所以取n=1就能满足。

(d).第四问要求找出点覆盖、边覆盖和主路径覆盖的所有TR(测试需求)

点覆盖:{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}

边覆盖:{(1,2),(2,3),(2,12),(3,4),(4,5),(5,6),(6,7),(6,8),(7,5),(8,9),(5,9),(9,10),(9,11),(10,11),(11,2),(12,13),(13,14),(14,15),(15,13),(13,16)}

主路径覆盖:

TR= {[1,2,3,4,5,6,8,9,10,11],[1,2,3,4,5,6,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,16],[1,2,12,13,14,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,12,13,16],[3,4,5,6,8,9,10,11,2,12,13,14,15],[3,4,5,6,8,9,11,2,12,13,16],[3,4,5,6,8,9,11,12,13,14,15],[3,4,5,9,10,11,2,12,13,16],[3,4,5,9,10,11,2,12,13,14,15],[3,4,5,9,11,2,12,13,16],[3,4,5,9,11,2,12,13,14,15],[3,4,5,6,8,9,10,11,2,3],[3,4,5,6,8,9,11,2,3],[3,4,5,9,10,11,2,3],[3,4,5,9,11,2,3],

[4,5,6,8,9,10,11,2,3,4],[4,5,6,8,9,11,2,3,4],[4,5,9,10,11,2,3,4],[4,5,9,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],[6,7,5,9,10,11,2,3,4,5,6],[6,7,5,9,11,2,3,4,5,6],[6,7,5,9,10,11,2,12,13,16],[6,7,5,9,10,11,2,14,15],[6,7,5,9,11,2,12,13,16],[6,7,5,9,11,2,14,15],

[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,16],[7,5,6,8,9,11,2,12,13,16],[7,5,6,8,9,10,11,2,12,13,14,15],[7,5,6,8,9,11,2,12,13,14,15],

[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],

[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,9,10,11],[11,2,3,4,5,6,8,9,11],[11,2,3,4,5,9,11],

[13,14,15,13],[14,15,13,14],[14,15,13,16],[15,13,14,13],[15,13,16]}

5.Junit进行主路径覆盖测试

 package triangle;

 public class triangle {
public String typeOfTriangle (int a, int b,int c)
{
String type = null;
if(a+b>c && a+c>b && c+a>b){
type = "scalene";
if(a==b || a==c || b==c){
type="isosceles";
if(a==b && b==c)
type="equilateral";
}
return type;
}
else{
type = "not a triangle";
return type;
}
}
}
package triangle;

import static org.junit.Assert.assertEquals;

import java.util.Arrays;
import java.util.Collection; import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters; @RunWith(Parameterized.class)
public class triangleTest {
private String type;
private int a;
private int b;
private int c; public triangleTest(String type, int a, int b, int c){
this.type = type;
this.a = a;
this.b = b;
this.c = c;
}
@Parameters
public static Collection prepareData(){
Object[][] object = {
{"not a triangle",1,1,2},{"equilateral",1,1,1},
{"isosceles",2,2,3},{"scalene",2,3,4}};
return Arrays.asList(object);
}
@Test
public void TestTypeOfTriangle()
{
triangle triangle = new triangle ();
assertEquals (type, triangle.typeOfTriangle(a,b,c)); } }

软件测试-----Graph Coverage作业的更多相关文章

  1. 软件测试第二周作业 WordCount

    本人github地址:  https://github.com/wenthehandsome23 psp阶段 预估耗时 (分钟) 实际耗时 (分钟) 计划 30 10 估计这个任务需要多少时间 20 ...

  2. 软件测试第二次作业:初识JUNIT单元测试方法

    软件测试有很多分类,从测试的方法上可分为:黑盒测试.白盒测试.静态测试.动态测试   从软件开发的过程分为:单元测试.集成测试.确认测试.验收.回归等. 在众多的分类中,与开发人员关系最紧密的莫过于单 ...

  3. 软件测试第二次作业——Fault,Failure,Error辨析与设计测试用例

    Fault 静态错误 ,Failure 外部错误 ,Error 内部错误 问题答案 第一题 1.1 当数组x内的元素≥2时,该循环不会检测到x[0]这个元素. 1.2 test: x=[2, 3, 2 ...

  4. Python模拟wc命令(软件测试第二次作业)

    Python实现字符,单词,行,代码行,空行及可视化 Gitee项目地址:https://gitee.com/biubiubiuLYQ/word_and_character_statistics 一. ...

  5. MapReduce 编程模型

    一.简单介绍 1.MapReduce 应用广泛的原因之中的一个在于它的易用性.它提供了一个因高度抽象化而变得异常简单的编程模型. 2.从MapReduce 自身的命名特点能够看出,MapReduce ...

  6. MapReduce 编程模型概述

    MapReduce 编程模型给出了其分布式编程方法,共分 5 个步骤:1) 迭代(iteration).遍历输入数据, 并将之解析成 key/value 对.2) 将输入 key/value 对映射( ...

  7. Flink History Job

    history job的写入1. org.apache.flink.runtime.jobmanager,Object JobManagerrunJobManager中指定使用MemoryArchiv ...

  8. Tomcat一闪而过的调试方法

    很少用tomcat来部署,都是用springboot微服务.只是以前学的时候搞demo试过而已. 软件测试的期末作业要求要测一个Javaweb的项目,给了一个包然后要求部署在tomcat中并启动. 然 ...

  9. Pycharm+Selenium webdriverPython自动化测试

    这是关于软件测试的一个作业! 1.Pycharm下载,这里可以自己去官网下载即可:https://www.jetbrains.com/pycharm/download/#section=windows ...

随机推荐

  1. Ubuntu 使用笔记

    持续更新 从前使用sudo apt update更新时, 发现软件源是cn.archive.ubuntu.com. 最近在system setting 中将软件源改成了archive.ubuntu.c ...

  2. COGS 577 蝗灾

    传送门 时间限制:2 s 内存限制:128 MB DESCRIPTION C国国土辽阔,地大物博......但是最近却在闹蝗灾..... 我们可以把C国国土当成一个W×W的矩阵,你会收到一些诸如(X, ...

  3. MyBatis详解 与配置MyBatis+Spring+MySql

    MyBatis 是一个可以自定义SQL.存储过程和高级映射的持久层框架.MyBatis 摒除了大部分的JDBC代码.手工设置参数和结果集重获.MyBatis 只使用简单的XML 和注解来配置和映射基本 ...

  4. Beta版本——第二次冲刺博客

    我说的都队 031402304 陈燊 031402342 许玲玲 031402337 胡心颖 03140241 王婷婷 031402203 陈齐民 031402209 黄伟炜 031402233 郑扬 ...

  5. Python 培训之MySql

    1. Install  1.1 install mysql sudo apt-get install lamp-server^ (tip: Set password) 1.2 install MySQ ...

  6. JS-制作可伸缩的水平菜单栏

      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.or ...

  7. centos设置编码

    CentOS6.5解决中文乱码与设置字符集 Windows的默认编码为GBK,Linux的默认编码为UTF-8.在Windows下编辑的中文,在Linux下显示为乱码.为了解决此问题,修改Linux的 ...

  8. smith waterman算法

    http://www.360doc.com/content/14/0106/00/14641369_342933143.shtml

  9. 9月26日JavaScript表单验证、正则表达

    一.非空验证 trim:去空格(去掉前后的空格),任何字符串都可以用这个方法.写法为:if(v.trim().length==0),表示如果去掉空格后的字符串的长度为0. <body> & ...

  10. windows命令关机

    不知道为啥,远程连接的window服务器没有关机命令,感觉是不是管理员权限导致的,所以找了下用命令关机,如下 shutdown -s -t #5秒内关机 shutdown -r -t #5秒内重启