标签:
(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