(A)控制流图
(B)
在if(isDivisible(primes[i],curPrime))里设置一个错误,即可使t2比t1更容易发现。
(C)
t=(n=1)
(D)
节点覆盖:
{0,1,2,3,4,5,6,7,8,9,10,11,12}
边覆盖:
{(0,1),(1,2),(1,9),(2,3),(3,4),(3,7),(4,5),(4,6),(5,3),(6,7)
,(7,8),(7,1),(8,1),(9,10),(10,11),(10,12),(11,10)}
主路径:
{(0,1,2,3,4,5),
(0,1,2,3,4,5,7,8),
(0,1,2,3,7,8),
(0,1,9,10,11),
(0,1,9,10,12),
(3,4,5,3),
(4,5,3,4),
(5,3,4,5),
(5,3,4,6,7,8,1,2),
(5,3,4,6,7,8,1,9,10,11),
(5,3,4,6,7,8,1,9,10,12),
(5,3,7,8,1,2),
(5,3,7,8,1,9,10,11),
(5,3,7,8,1,9,10,12),
(10,11,10),
(11,10,11)}
二、实现一个主路径覆盖
测试方法
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,3),(1,2,5),(1,2,4,6),(1,2,4,7),(1,2,4,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)); } }
覆盖结果: