标签:
(a)
(b) when MAXPRIMES = 4, array will out of bound
(c) n = 1
(d) node coverage:
TR = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}
Test Paths: [1,2,3,4,5,6,7,8,5,9,10,11,12,2,13,14,15,16]
edge coverage:
TR = {(1,2),(2,3),(3,4),(4,5),(5,6),(6,7),(6,8),(7,8),(8,5),(5,9),(9,10),(10,11),(11,12),(10,12),(12,2),(2,13),(13,14),(14,15),(15,14),(14,16)}
prime path coverage:
TR = {[1,2,13,14,16],[1,2,13,14,15],[1,2,3,4,5,6,7,8],[1,2,3,4,5,6,8],[1,2,3,4,5,9,10,11,12],[1,2,3,4,5,9,10,12]}
全路径覆盖的例子:
判断三角形是等边,等腰,还是普通三角形。
判断三角形代码:
public class triangle { private static int result = -1; public void triangle(int a,int b,int c) { if(a<=0 || b<=0 || c<=0) { result = -1; } else { if(((a+b)>c) && ((a+c)>b && (b+c)>a)) { if((a == b) &&(a == c)) { result = 3; } if((a==b && a!=c)||(a==c && a!=b)||(b==c && a!=b)) { result = 2; } if(a!=b && a!=c && b!=c) { result = 1; } } else { result = -1; } } } public int getResult(){ return result; } public void clear(){ result = -1; } }
测试代码:
import static org.junit.Assert.*; import org.junit.Test; public class test { private static triangle cal = new triangle(); @Test public void testTriangle(){ cal.triangle(3, 4, 5); assertEquals(1, cal.getResult()); cal.triangle(3, 3, 5); assertEquals(2, cal.getResult()); cal.triangle(6, 6, 6); assertEquals(3, cal.getResult()); cal.triangle(10, 4, 4); assertEquals(-1, cal.getResult()); cal.triangle(-1, 3, 4); assertEquals(-1, cal.getResult()); } }
这是代码的结构:
测试结果的截图:
标签:
原文地址:http://www.cnblogs.com/WentaiLi/p/5342803.html