软件测试作业三

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

 

 

转载于:https://www.cnblogs.com/flying-sky/p/6538362.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值