码迷,mamicode.com
首页 > 其他好文 > 详细

软件测试习题七

时间:2016-03-31 00:02:42      阅读:174      评论:0      收藏:0      [点我收藏+]

标签:

(A)控制流图

技术分享

(B)

在if(isDivisible(primes[i],curPrime))里去掉isPrime=false,即可使t2比t1更容易发现。

(C)

t=(n=1)

(D)

节点覆盖:

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

边覆盖:

{(1,2),(2,10),(2,3),(3,4),(4,5),(5,6),(6,4),(4,8),(5,7)

,(7,8),(8,2),(8,9),(9,2),(10,11),(10,12),(11,10)}

主路径:

{(2,3,4,5,7,8,9,2),(2,3,4,5,7,8,2),(4,5,6,4),(1,2,10,12),(10,11,12)}

 二、实现一个主路径覆盖

测试方法

技术分享
    public static String whatIsTriangle(double a,double b, double c){
        
        if(a <= 0 || b <= 0 || c <= 0)            
            return "wrong";    
        
        if(a + b > c && a + c > b && b + c > a){        
    
            if(a == b && a ==c)            
                return "equilateral";        
            else if(a==b || a==c || b==c)            
                return "isosceles";        
            else            
                return "scalene";
        }
        else{
            return "wrong";
        }
    }
技术分享

控制流图

技术分享

主路径:

{(1,2),(1,3,4),(1,3,5,6),(1,3,5,7),(1,3,5,8)}

测试用例:

技术分享
@RunWith(Parameterized.class)
public class TestTriangle1 {
    private double input1;
    private double input2;
    private double input3;
    private String expected;
    
    public TestTriangle1(double input1,double input2,double input3,String expected){
        this.input1 = input1;
        this.input2 = input2;
        this.input3 = input3;
        this.expected = expected;
    }
    
@Parameters
public static Collection<Object[]> getData(){
    return Arrays.asList(new Object[][]{
        {3,3,3,"equilateral"},
        {3,4,3,"isosceles"},
        {3,4,5,"scalene"},
        {0,0,0,"wrong"},
        {1,3,4,"wrong"}
    });
} 

@Test
public void test(){
    assertEquals(this.expected,Triangle.whatIsTriangle(input1,input2,input3));
}

}
技术分享

覆盖结果:

技术分享

软件测试习题七

标签:

原文地址:http://www.cnblogs.com/hillsblog/p/5339355.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!