软件测试作业三

Use the following method printPrimes() for questions a–d.

/******************************************************* 
     * 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
(a)

The meaning of these nodes are:

1: int curPrime;                              2:

   int numPrimes;                           3: curPrime++;

   boolean isPrime;                            isPrime = true;

   int [] primes = new int [MAXPRIMES];           int i=0;

   primes [0] = 2;                            4:

   numPrimes = 1;                           5:

   curPrime = 2;                             7:

6: isPrime = false;                             8: primes[numPrimes] = curPrime;

   break;                                      numPrimes++;

9: i++                 10: int i = 0;            11:

12: System.out.println ("Prime: " + primes[i]);       13:end

i++

(b) When MAXPRIMES=4, The t1 is running normally and the t2 has an array of cross-border errors.

(c) Input  n=1.

(d)

node : { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 }

node coverage : {1, 2, 3, 4, 5, 9, 4, 5, 9, 4, 5, 6, 7, 8, 2, 10, 11, 12, 11, 13 }

edge : { (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), (10,11), (11,12), (11,13), (12,11) }

edge coverage:  [1,2,3,4,5,9,4,7,2,10,11,12,11,13],  [1,2,3,4,5,6,7,8,2,10,11,13]

prime path :

[1,2,3,4,5,6,7,8], [1,2,3,4,5,9], [1,2,10,11,13], [1,2,10,11,12], [2,3,4,5,6,7,8,2], [2,3,4,5,6,7,2], [2,10,11,13], [2,10,11,12], [2,3,4,7,2], [2,3,4,7,8,2], [4,5,9,4], [5,9,4,5], [11,12,11], [12,11,13], [12,11,12]

prime path coverage :

[1, 2, 3, 4, 5, 9, 4, 7, 2, 10, 11, 12, 11, 13] , [1, 2, 3, 4, 5, 6, 7, 8, 2, 10, 11, 13] , [1, 2, 10, 11, 13] , [1, 2, 10, 11, 12, 11, 13] , [1, 2, 3, 4, 5, 6, 7, 2, 10, 11, 13] , [1, 2, 3, 4, 7, 2, 10, 11, 13], [1, 2, 3, 4, 7, 8, 2, 10, 11, 13] , [1, 2, 3, 4, 5, 9, 4, 5, 6, 7, 2, 10, 11, 12, 11, 12, 11, 13].

A testing for Prime Path Coverage

 


posted @ 2017-03-12 16:47  a_bird  阅读(152)  评论(0编辑  收藏  举报