1.控制流图
2.令MAXPRIME=4,这样t1=(n=3)不会越界,而t2=(n=5)会越界。
3.令n=1即可
4.节点覆盖:TR={1,2,3,4,5,6,7,8,9,10}
边覆盖:TR={(1,2),(2,3),(2,10),(3,4),(4,5),(4,7),(5,6),(5,9),(6,7),(7,8),(7,2),(8,2),(9,4)}
主路径覆盖:TR={(1,2,3,4,5,6,7,8),(2,3,4,5,6,7,8,2),(4,5,9,4),(4,5,6,7,8,2,3,4),(4,5,6,7,2,3,4)
(1,2,10),(3,4,5,6,7,8,2,10),(3,4,5,6,7,2,10)}
测试代码
1 package printPrime; 2 3 4 5 import static org.junit.Assert.*; 6 7 8 9 import java.io.ByteArrayOutputStream;10 11 import java.io.PrintStream;12 13 14 15 import org.junit.Before;16 17 import org.junit.Test;18 19 20 21 public class primeTest {22 23 prime p;24 25 ByteArrayOutputStream str;26 27 28 29 @Before30 31 public void setup() throws Exception{32 33 p = new prime();34 35 str = new ByteArrayOutputStream();36 37 System.setOut(new PrintStream(str));38 39 }40 41 42 43 @Test44 45 public void test() {46 47 String output = new String("Prime: 2\r\nPrime: 3\r\nPrime: 5\r\nPrime: 7\r\nPrime: 11\r\n");48 49 p.printPrimes(5);50 51 assertEquals(output, str.toString());52 53 }54 55 56 57 }