软件测试技术 作业3

A。控制流图

 

B。将MAXPRIMES设为4,这样t2=(n=5)就会出现数组越界的错误,但t1=(n=3)无影响。

C。n=1的时候不满足numPrimes < n,故不经过while循环

D。

点覆盖:{1,2,3,4,5,6,7,5,6,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)}

 

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

(3,4,5,6,8,9,11,2,12,13,14,15),(3,4,5,6,8,9,10,11,2,12,13,16),(3,4,5,6,8,9,11,2,12,13,16),(3,4,5,9,10,11,2,12,13,14,15),(3,4,5,9,11,2,12,13,14,15),(3,4,5,9,10,11,2,12,13,16),

(3,4,5,9,11,2,12,13,16),(6,7,5,9,10,11,2,12,13,14,15),(6,7,5,9,11,2,12,13,14,15),(6,7,5,9,10,11,2,12,13,16),(6,7,5,9,11,2,12,13,16),(14,15,13,16),(13,14,15,13),(5,6,7,5),

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

 

 

 

设计主路径覆盖测试用例。

 

 

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<Object[]> 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));

}

}

测试结果

posted @ 2016-03-30 18:46  燃烧灬  阅读(249)  评论(0编辑  收藏  举报