这次作业主要是根据代码,画出控制流图,并涉及计边覆盖,点覆盖,主路径的知识。
具体作业内容如下
/*******************************************************
* Finds and prints n prime integers
* Jeff Offutt, Spring 2003
******************************************************/
public static void printPrimes (int n)
{
int curPrime; // Value currently considered for primeness
int numPrimes; // Number of primes found so far.
boolean isPrime; // Is curPrime prime?
int [] primes = new int [MAXPRIMES]; // The list of prime numbers.
// Initialize 2 into the list of primes.
primes [0] = 2;
numPrimes = 1;
curPrime = 2;
while (numPrimes < n)
{
curPrime++; // next number to consider ...
isPrime = true;
for (int i = 0; i <= numPrimes-1; i++)
{ // for each previous prime.
if (curPrime%primes[i]==0)
{ // Found a divisor, curPrime is not prime.
isPrime = false;
break; // out of loop through primes.
}
}
if (isPrime)
{ // save it!
primes[numPrimes] = curPrime;
numPrimes++;
}
} // End while
// Print all the primes out.
for (int i = 0; i <= numPrimes-1; i++)
{
System.out.println ("Prime: " + primes[i]);
}
} // end printPrimes
一 画出控制流图
二、设计一个t2=(n=5)比t1=(n=3)容易发现发现的错误
三、写一个测试用例,使相应的测试路径访问连接while语句开始到fot语句得边,而不用通过while的循环体
t:n=1
四、例举每个节点覆盖,边覆盖和主路径覆盖的TR
节点覆盖需求:{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}
边覆盖需求:{(1,2),(2,11),(2,3),(3,4),(4,5),(5,6),(5,7),(6,5),(6,9),(7,8),(7,2),(8,2),(9,10),(10,7),(11,12),(12,13),(12,15),(13,14),(14,12)}
主路径覆盖需求: