A。控制流圖java
B。將MAXPRIMES設爲4,這樣t2=(n=5)就會出現數組越界的錯誤,但t1=(n=3)無影響。數組
C。n=1的時候不知足numPrimes < n,故不通過while循環測試
D。ui
點覆蓋:{1,2,3,4,5,6,7,5,6,8,9,10,11,12,13,14,15,16}this
邊覆蓋:{(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)}spa
主路徑覆蓋:{(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),code
(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),blog
(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)}it
設計主路徑覆蓋測試用例。
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)); } }
測試結果