Software Testing HW03

Question a(control flow graph):

 

 

Question b:  令MAXPRIMES=4,这样t2会测试出越界错误,t1不会。

Question c:  n=1;

Question d:

  1. node coverage:

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

  1. edge coverage

{1,2},{2,3},{2,11},{3,4},{4,5},{5,6},{5,9},{6,7},{6,8},{7,9},{8,5},{9,10},{9,2},{10,2},{11,12},{12,13},{12,14},{13,14}。

  1. prime path coverage:

{1,2,3,4,5,6,7,9,10},{1,2,3,4,5,9,10},{1,2,3,4,5,6,8},{1,2,11,12,13,14},{1,2,11,12,14},{2,3,4,5,9,2},{2,3,4,5,6,7,9,2},{2,3,4,5,9,10,2},{2,3,4,5,6,7,9,10,2},{3,4,5,9,2,11,12,13,14},{3,4,5,9,2,11,12,14},{3,4,5,6,7,9,2,11,12,14},{3,4,5,6,7,9,2,11,12,13,14},{3,4,5,9,10,2,11,12,13,14},{3,4,5,9,10,2,11,12,14},{3,4,5,6,7,9,10,2,11,12,13,14},{3,4,5,6,7,9,10,2,11,12,14},{5,6,8,5},{6,8,5,9,2,11,12,13,14},{6,8,5,9,2,11,12,14},{6,8,5,9,10,2,11,12,13,14},{6,8,5,9,10,2,11,12,14},{6,8,5,9,2,3,4,5,6}

 

实现主路径覆盖的例子:

Triangle.java

package triangletest;

public class Triangle {
 
    private int a=0; 
    private int b=0; 
    private int c=0; 
    private String s;
    public Triangle()
    {
        this.a=0;
        this.b=0;
        this.c=0;
    }
    
    public Triangle(int x, int y, int z )
    {
        this.a=x;
        this.b=y;
        this.c=z;
    }
    
    public void calculate()
    {
        if ((a+b>c)&(a+c>b)&(b+c>a)) {
        if ((a==b)&(b==c)) {s="equilateral";}
        else if ((a==b)|(b==c)|(a==c)) {s="isosceles";}
        else {s="scalene";}  }
        
        else {
                 s="not a triangle";
             }

    }
    
    public String getresult()
    {
       return s;    
    }
}
View Code

TriangleTest.java

package test;

import triangletest.*;
import static org.junit.Assert.*;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;



public class TriangleTest {
    
    public Triangle t;

    @Before
    public void setUp() throws Exception {
        System.out.println("start!");
        t=new Triangle();
    }

    @After
    public void tearDown() throws Exception {
        System.out.println("end!");
    }


    @Test
    public void testCalculate() {
        t = new Triangle(1,1,1);
        t.calculate();
        assertEquals("equilateral",t.getresult());
        
        t = new Triangle(1,2,2);
        t.calculate();
        assertEquals("isosceles",t.getresult());
        
        t = new Triangle(2,1,2);
        t.calculate();
        assertEquals("isosceles",t.getresult());
        
        t = new Triangle(2,2,1);
        t.calculate();
        assertEquals("isosceles",t.getresult());
        
        t = new Triangle(3,2,1);
        t.calculate();
        assertEquals("not a triangle",t.getresult());
        
        t = new Triangle(2,3,1);
        t.calculate();
        assertEquals("not a triangle",t.getresult());
        
        t = new Triangle(1,2,3);
        t.calculate();
        assertEquals("not a triangle",t.getresult());
        
        
        t = new Triangle(3,4,5);
        t.calculate();
        assertEquals("scalene",t.getresult());
    }



}
View Code

 运行结果截图:

 

转载于:https://www.cnblogs.com/dyz1022/p/6544528.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值