软测第三次作业
知识点:画出控制流图,并涉及计边覆盖,点覆盖,主路径
2.若MAXPRIMES为2,n=5时质数有2,3,5质数数量超出,n=3时质数只有2,3质数数量合法。
3.t=(n=1)
4.点覆盖{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 }
边覆盖{(1,2),(2,3),(3,4),(4,5),(5,6),(5,7),(6,9),(9,5),(7,8),(7,2),(8,2),(2,11),(6,10),(10,11),(11,12),(12,13),(13,14),(14,12),(12,15)}
主路径覆盖 {(1,2,11,12,15),
(1,2,11,12,13,14,15),
(12,13,14),
(1,2,3,4,5,6,10,11,12,15),
(1,2,3,4,5,6,10,11,12,13,14,15),
(1,2,3,4,5,6,9,5,6,10,11,12,15) ,
(5,6,9),
(1,2,3,4,5,7,8,2,3,4,5,6,10,11,12,15),
(1,2,3,4,5,7,8,2,3,4,5,6,10,11,12,13,14,15),
(1,2,3,4,5,7,8,2,3,4,5,6,9,5,6,10,11,12,15),
(1,2,3,4,5,7,8,2,3,4,5,6,9,5,6,10,11,12,13,14,15),
(1,2,3,4,5,7,2,3,4,5,6,10,11,12,15),
(1,2,3,4,5,7,2,3,4,5,6,10,11,12,13,14,15),
(1,2,3,4,5,7,2,3,4,5,6,9,5,6,10,11,12,15),
(1,2,3,4,5,7,2,3,4,5,6,9,5,6,10,11,12,13,14,15),
(1,2,3,4,5,7,2,11,12,13,14,15),
(1,2,3,4,5,7,2,11,12,13,14,15),
(1,2,3,4,5,7,2,11,12,13,14,15),
(1,2,3,4,5,7,2,11,12,13,14,15),
(1,2,3,4,5,7,2,11,12,15),
(1,2,3,4,5,7,2,11,12,15),
(1,2,3,4,5,7,2,11,12,15),
(1,2,3,4,5,7,2,11,12,15),
(2,3,4,5,7,2),
(2,3,4,5,7,8,2)}
5.Junit测试和路径覆盖
package LKW;
public class Primes {
public static String printPrimes (int n)
{
int MAXPRIMES = 10;
int curPrime;
int numPrimes;
boolean isPrime;
int [] primes = new int [MAXPRIMES];
primes [0] = 2;
numPrimes = 1;
curPrime = 2;
while (numPrimes < n)
{
curPrime++;
isPrime = true;
for (int i = 0; i <= numPrimes-1; i++)
{
if (curPrime%primes[i]==0)
{
isPrime = false;
break;
}
}
if (isPrime)
{
primes[numPrimes] = curPrime;
numPrimes++;
}
}
String s = null;
for (int i = 0; i <= numPrimes-1; i++)
{
System.out.println ("Prime: " + primes[i]);
s += primes[i];
}
return s;
}
}
package LKW;
import LKW.Primes;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
public class PrimesTest {
public Primes cal;
@Before
public void setUp() throws Exception {
cal = new Primes();
}
@Test
public void test() {
assertEquals("null235711", Primes.printPrimes(5));
}
}


覆盖测试



浙公网安备 33010602011771号