码迷,mamicode.com
首页 > 其他好文 > 详细

软件测试作业三-printPrimes()

时间:2017-03-13 23:51:16      阅读:228      评论:0      收藏:0      [点我收藏+]

标签:boolean   软件测试   bool   节点   out   pack   new   imp   org   

作业内容:
private static void printPrimes(int n) { int curPrime; int numPrimes; boolean isPrime; int MAXPRIMES=50; 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++; } } for (int i = 0; i <= numPrimes-1; i++) { System.out.println ("Prime: " + primes[i]); } }

a)控制流图:

 

技术分享

b)令MAXPRIMES=50

c)测试用例r=(n=1)

d)节点覆盖

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

边覆盖

TR={(1,2),(2,3),(2,4),(3,5),(4,11),(5,6),(6,7),(6,8),(7,9),(7,10),(8,5),(9,10),(10,2),(11,12),(11,13),(12,11)}

主路径覆盖

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

e)Juint

完整代码

package printPrimes;

public class prime {
     
     public static String printPrimes(int n)
     {
         int curPrime;
         int numPrimes;  
         boolean isPrime; 
         int MAXPRIMES=50;
         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 re="";
         for (int i = 0; i <= numPrimes-1; i++) 
         { 
             re=re+primes[i]; 
             System.out.print(primes[i]);
         }
         
         return re;
     }
}

生成测试类

package printPrimes;

import static org.junit.Assert.*;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class primeTest {
    prime p;
    @Before
    public void setUp() throws Exception {
        p=new prime();
    }

    @After
    public void tearDown() throws Exception {
    }

    @Test
    public void testPrintPrimes() {
        String rel=p.printPrimes(8);
        assertEquals("wrong",rel,"235711131719");
    }

}

 技术分享

f)Eclemma

技术分享

软件测试作业三-printPrimes()

标签:boolean   软件测试   bool   节点   out   pack   new   imp   org   

原文地址:http://www.cnblogs.com/xzbwx/p/6545610.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!