软件测试习题七

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了软件测试习题七相关的知识,希望对你有一定的参考价值。

(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));
}

}
技术分享

覆盖结果:

技术分享

以上是关于软件测试习题七的主要内容,如果未能解决你的问题,请参考以下文章

AMD正式公布第七代桌面级APU AM4新接口

从阿里云七代云服务器,谈云计算四大趋势

三分钟了解阿里云第七代高主频云服务器性能以及优势

Android SMS Verification API 结果码始终为 0

阿里云服务器ECS第七代c7/g7/r7/c7t/g7ne/g7t/r7t参数性能详解!

阿里云服务器ECS第七代c7/g7/r7/c7t/g7ne/g7t/r7t参数性能详解!