一、數組
二、測試
一個最直觀的錯誤就是數組越界,n取的值越大,數組越界就越有可能發生ui
三、當n=1時候知足this
第四問要求找出點覆蓋、邊覆蓋和主路徑覆蓋的全部TR(測試需求)spa
點覆蓋:{1,2,3,4,5,6,7,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)}code
主路徑覆蓋:{(1,2,3,4,5,6,7),blog
(1,2,3,4,5,6,8,9,10,11),it
(1,2,3,4,5,6,8,9,11),io
(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 cn.tju.st; public class Triangle { public int a; public int b; public int c; public Triangle(int a,int b,int c) { this.a=a; this.b=b; this.c=c; } public String judge() { if(a==b&&b==c) return "equilateral"; else if(a==b||b==c||c==a) return "isosceles"; else { return "scalene"; } } }
package cn.tju.st; import static org.junit.Assert.*; import org.junit.After; import org.junit.Before; import org.junit.Test; public class TestTriangle { Triangle tri =null; @Before public void setUp() throws Exception { //System.out.println("This is before test"); } @After public void tearDown() throws Exception { System.out.println("This is after test"); } @Test public void test() { tri = new Triangle(3,3,3); assertEquals("equilateral",tri.judge()); tri = new Triangle(2,3,3); assertEquals("isosceles",tri.judge()); tri = new Triangle(3,4,5); assertEquals("scalene",tri.judge()); } }
三組測試用例(3,3,3),(2,3,3),(3,4,5)便可完成主路徑覆蓋