软件测试 覆盖部分作业

题目代码如下:

 1 /*******************************************************
 2      * Finds and prints n prime integers
 3      * Jeff Offutt, Spring 2003
 4      ******************************************************/
 5     public static void printPrimes (int n)
 6     {
 7         int curPrime; // Value currently considered for primeness
 8         int numPrimes; // Number of primes found so far.
 9         boolean isPrime; // Is curPrime prime?
10         int [] primes = new int [MAXPRIMES]; // The list of prime numbers.
11
12         // Initialize 2 into the list of primes.
13         primes [0] = 2;
14         numPrimes = 1;
15         curPrime = 2;
16         while (numPrimes < n)
17         {
18             curPrime++; // next number to consider ...
19             isPrime = true;
20             for (int i = 0; i <= numPrimes-1; i++)
21             { // for each previous prime.
22                 if (curPrime%primes[i]==0)
23                 { // Found a divisor, curPrime is not prime.
24                     isPrime = false;
25                     break; // out of loop through primes.
26                 }
27             }
28             if (isPrime)
29             { // save it!
30                 primes[numPrimes] = curPrime;
31                 numPrimes++;
32             }
33         } // End while
34
35         // Print all the primes out.
36         for (int i = 0; i <= numPrimes-1; i++)
37         {
38             System.out.println ("Prime: " + primes[i]);
39         }
40     } // end printPrimes

a.控制流图如下:

b.设计一个t2=(n=5)比t1=(n=3)更容易发现的错误。容易想到数组越界,即当 MAXPRIMES = 3 or 4 时,t1正常通过,而t2会因越界而报错。

c.显然当 n = 1 时不会经过while循环。

d.找出所有点覆盖、边覆盖和主路径覆盖的TR。

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

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

主路径覆盖:{ (1,2,3,4,8,2,10,11,13), (1,2,3,4,8,2,10,11,12,11,13), (1,2,3,4,8,9,2,10,11,13), (1,2,3,4,8,9,2,10,11,12,11,13),

(1,2,3,4,5,6,8,2,10,11,13), (1,2,3,4,5,6,8,2,10,11,12,11,13), (1,2,3,4,5,6,8,9,2,10,11,13), (1,2,3,4,5,6,8,9,2,10,11,12,11,13),

(3,4,5,6,8,9,10,11,2,12,13), (3,4,5,6,8,9,11,2,12,13), (3,4,5,6,8,9,10,11,2,12,13), (4,5,7,4), (11,12,11), (2,3,4,8,2), (2,3,4,8,9,2),

(2,3,4,5,6,8,9,2)... }

e.对上次的三角形判定程序设计主路径覆盖的测试用例。

 1 //Triangle.java
 2 import java.util.Arrays;
 3
 4 public class Triangle
 5 {
 6     public String check( String p, String q, String r )
 7     {
 8         int[] a = new int[3];
 9         a[0] = Integer.parseInt(p);
10         a[1] = Integer.parseInt(q);
11         a[2] = Integer.parseInt(r);
12         Arrays.sort(a);
13         if ( a[0] + a[1] > a[2] )
14         {
15             if ( a[0] == a[2] )
16             {
17                 return "equilateral";
18             }
19             else
20             {
21                 if ( a[0] == a[1] || a[1] == a[2] )
22                 {
23                     return"isosceles";
24                 }
25                 else
26                 {
27                     return "scalene";
28                 }
29             }
30         }
31         else
32         {
33             return "not a triangle";
34         }
35     }
36 }
 1 import static org.junit.Assert.*;
 2 import java.util.Arrays;
 3 import java.util.Collection;
 4 import org.junit.Before;
 5 import org.junit.Test;
 6 import org.junit.runner.RunWith;
 7 import org.junit.runners.Parameterized;
 8 import org.junit.runners.Parameterized.Parameters;
 9
10 @RunWith(Parameterized.class)
11 public class TriangleTest
12 {
13     private String p;
14     private String q;
15     private String r;
16     private String expected;
17     private Triangle tmp;
18
19     public TriangleTest( String p, String q, String r, String expected )
20     {
21         this.p = p;
22         this.q = q;
23         this.r = r;
24         this.expected = expected;
25     }
26
27     @Before
28     public void setUp()
29     {
30         tmp = new Triangle();
31     }
32
33     @Parameters
34     public static Collection<String[]> getData()
35     {
36         return Arrays.asList( new String[][]
37         {
38             { "3", "3", "3", "equilateral" },
39             { "3", "4", "4", "isosceles" },
40             { "3", "4", "5", "scalene" },
41             { "3", "4", "7", "not a triangle" },
42         });
43     }
44
45     @Test
46     public void test()
47     {
48         assertEquals( this.expected, tmp.check( p, q, r ) );
49     }
50 }

测试用例见:@Parameters部分。

可见覆盖率达到了100%。

				
时间: 2024-08-18 10:26:34

软件测试 覆盖部分作业的相关文章

软件测试第二周作业 wordcount

软件测试第二周作业 wordcount Github地址 https://github.com/mxz96102/word_count PSP2.1表格 PSP2.1 PSP 阶段 预估耗时 (分钟) 实际耗时 (分钟) Planning 计划 25 30 · Estimate · 估计这个任务需要多少时间 150 252 Development 开发     · Analysis · 需求分析 (包括学习新技术) 20 20 · Design Spec · 生成设计文档 0 0 · Desig

软件测试书上作业

/******************************************************* * Finds and prints n prime integers * Jeff Offutt, Spring 2003 ******************************************************/ public static void printPrimes (int n) { int curPrime; // Value currently

《高级软件测试》实践作业3学习记录12月16日

今天距离小组作业上交还有一周的时间,我们小组开始着手进行实践作业的探讨和分工工作 介于前两次的小组作业的完成度和得分都不尽人意,所以为了弥补我们和其他组的差距,我们决定,完成这次的附加作业. 此次作业的分工如下: 汪嘉珮:负责部分文档的编写工作 杨智超:负责实践作业的主要工作 何阳寅:负责附加题的主要工作 叶瑞:博客记录和协助何阳寅杨智超完成两个实践作业的内容.

《高级软件测试》实践作业3学习记录12月17日

我们根据老师的作业要求阶段,回忆课程的内容并熟悉白盒测试方法.简单学习了利用测试管理工具来录入设计的测试用例,由于时间较紧张,并未熟练利用测试管理工具导出测试用例,最终决定填写测试用例设计清单模板,利用白盒测试方法设计测试用例.

《高级软件测试》实践作业3学习记录12月19日

今天我们熟悉静态代码检查工具,通过自动化静态检查发现缺陷.我们选择的静态代码检查工具是阿里巴巴java审查手册里提供对应的审查插件,对整个客户关系管理系统的源代码进行扫描,统计发现的缺陷(包括错误和警告)并撰写静态代码检查报告. 汪佳佩同学查找了工具来源,基本特点与下载地址: 何阳寅同学使用该工具对整个管理系统进行扫描,按照作业要求进行截图,并像所有成员分析了该款静态代码检查工具的优缺点: 杨智超同学对扫描结果的缺陷进行统计,并将缺陷反馈给所有成员: 叶瑞同学收集整理每位成员对缺陷的看法与分析,

《高级软件测试》实践作业3学习记录12月23日

今天,四位小组成员在讨论组里开了一个简单的小会议,确定了我们的测试产品为爱课程网(https://www.icourse163.org)与竞品对象(清华大学的学堂在线--(https://www.xuetangx.com/).根据老师的提示,最终我们决定主要围绕课程公告.课程内容学习(含视频.文档.富文本文档等).课程随堂测验提交.单元作业(特别是互评作业)的提交.修改.评分等功能选取其中几种展开分析,考虑到要完成这次的附加作业,我们最终决定仅选择课程内容学习和课程随堂测验提交两种功能进行测试.

软件测试第二周作业 WordCounter

Github 项目地址 WordCounter in github PSP(Personal Software Process) PSP2.1 PSP阶段 预估耗时实际耗时(分钟) 实际耗时(分钟) Planning 计划 10 17 Estimate 估计这个任务需要多少时间 5 10 Development 开发 545 650 - Analysis - 需求分析(包括学习新技术) 120 160 - Design Spec - 生成设计文档 60 90 - Coding Standard

软件测试第四周作业 WordCount优化

Github地址 https://github.com/husterC/WordCountGroupwork PSP表格 PSP2.1 PSP阶段 预估耗时 (分钟) 实际耗时 (分钟) Planning 计划     · Estimate · 估计这个任务需要多少时间 540  780 Development 开发     · Analysis · 需求分析 (包括学习新技术)  60  120 · Design Spec · 生成设计文档  30  10 · Design Review ·

软件测试 第二次作业

一:把一个英语句子中的单词次序颠倒后输出.例如输入“how are you”,输出“you are how” #include<stdio.h> int main() { char sentence[100]; int len=0,j,wordlen=0; gets(sentence); while(sentence[len]) len++; for(j=len-1;j>=0;j--) { if(sentence[j]>='a'&&sentence[j]<='