标签:logs ... *** void highlight isa div while循环 currently
首先,书上给的代码如下:
/*******************************************************
* 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 (isDivisable(primes[i],curPrime))
{ // 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
问题1:画出该方法的控制流图
(待续
问题2:考虑测试用例t1=(n=3)和t2=(n=5)。即使这些测试用例经过printfPrimes()方法中相同的主路径,他们不一定找出相同的错误。设计一个简单的错误,使得t2比t1
更容易发现。
答:数组越界时可能会发生错误。
问题3:找到一个测试用例,使得测试路径不用通过while循环体。
答:令初始条件n=1。
问题4:列举每个节点覆盖,边覆盖和主路径覆盖的测试需求。
(待续)
问题5:基于Junit及Eclemma( jacoco)实现一个主路径覆盖的测试。
可以用上次实验一的三角形程序进行主路径覆盖测试。
(待续)
标签:logs ... *** void highlight isa div while循环 currently
原文地址:http://www.cnblogs.com/cricketvaxes/p/6545256.html