軟體測試技術 hw3

來源:互聯網
上載者:User

標籤:

作業題目:教材49頁第7題a到d,並基於Junit及Eclemma實現一個主路徑覆蓋的測試
一、Use the following method printPrimes() for questions a-f below

 1 1./** ***************************************************** 2 2. * Finds and prints n prime integers 3 3. * Jeff Offutt, Spring 2003 4 4. ********************************************************* */ 5 5. private static void printPrimes (int n) 6 6. { 7 7. int curPrime; // Value currently considered for primeness 8 8. int numPrimes; // Number of primes found so far. 9 9. boolean isPrime; // Is curPrime prime?10 10. int [] primes = new int [MAXPRIMES]; // The list of prime numbers.11 11.12 12. // Initialize 2 into the list of primes.13 13. primes [0] = 2;14 14. numPrimes = 1;15 15. curPrime = 2;16 16. while (numPrimes < n)17 17. {18 18. curPrime++; // next number to consider ...19 19. isPrime = true;20 20. for (int i = 0; i <= numPrimes-1; i++)21 21. { // for each previous prime.22 22. if (isDivisible (primes[i], curPrime))23 23. { // Found a divisor, curPrime is not prime.24 24. isPrime = false;25 25. break; // out of loop through primes.26 26. }27 27. }28 28. if (isPrime)29 29. { // save it!30 30. primes[numPrimes] = curPrime;31 31. numPrimes++;32 32. }33 33. } // End while34 34.35 35. // Print all the primes out.36 36. for (int i = 0; i <= numPrimes-1; i++)37 37. {38 38. System.out.println ("Prime: " + primes[i]);39 39. }40 40. } // end printPrime

a.畫出控制流程圖
解答:

b.設計一個t2=(n=5)比t1=(n=3)容易發現發現的錯誤

解答:數組越界

c.寫一個測試案例,使相應的測試路徑訪問串連while語句開始到fot語句得邊,而不用通過while的迴圈體

解答:t:n=1

d.例舉每個節點覆蓋,邊覆蓋和主路徑覆蓋的TR

解答:

節點覆蓋需求:{1,2,3,4,5,6,7,8,9,10,11,12,13}

 

邊覆蓋需求:{(1,2),(2,3),(2,10),(3,4),(4,5),(4,8),(5,6),(5,7),(6,8),(7,4),(8,2),(8,9),(9,2),(10,11),(11,12),(11,13),(12,11)}

 

主路徑覆蓋需求:

 

{

 

(4,5,6,4)

 

(6,4,5,6)

 

(5,6,4,5)

 

(5,6,4,,8,,2,3)

 

(5,6,4,8,2,10,11,12,11)

 

(5,6,4,8,2,10,11,13)

 

 

 

(3,4,5,7,8,9,2,3)

 

(3,4,5,7,8,2,3)

 

(3,4,8,9,2,3)

 

(3,4,8,2,3)

 

(3,4,5,7,8,9,2,10,11,12)

 

(3,4,5,7,8,9,2,10,11,13)

 

(3,4,5,7,8,2,10,11,12)

 

(3,4,5,7,8,2,10,11,13)

 

(3,4,8,2,10,11,13)

 

(3,4,8,2,10,11,12)

 

(4,5,7,8,9,2,3,4)

 

(4,5,7,8,2,3,4)

 

(4,8,9,2,3,4)

 

(4,8,2,3,4)

 

(1,2,3,4,8)

 

(1,2,3,4,5,6)

 

(1,2,3,4,5,7,8,9)

 

(1,2,10,11,12)

 

(1,2,10,11,13)

 

(11,12,11)

 

(12,11,12)

 

(12,11,13)

 

}

二.實現一個主路徑覆蓋的測試

使用第一次上機判斷三角形的程式:

 

package zjz;public class triangle {        private static int result=0;    public void TypeOfTriangle(int a,int b,int c) {        if(a + b <= c || a + c <= b || b+ c <= a && a<=0 && b <= 0 && c <=0){            result = 1; //不是三角形                        if(a == b && a == c)                result = 2;//等腰                        if(a == b || b == c || a == c)                result = 3;//等邊            else                result = 4;//普通        }            }        public int getResult(){        return result;    }       public void clear(){         result = 0;    }

測試類別用例:

 

package zjz;import static org.junit.Assert.*;import org.junit.Test;public class TestCalculator {    private static Calculator cal = new Calculator();    @Test    public void testTriangle(){            cal.triangle(2, 2, 2);    assertEquals(3, cal.getReuslt());//等邊三角形    cal.triangle(3, 3, 5);    assertEquals(2, cal.getReuslt());//等腰三角形    cal.triangle(3, 4, 5);    assertEquals(1, cal.getReuslt());//普通三角形    cal.triangle(1, 2, 3);    assertEquals(0, cal.getReuslt());//不能構成三角形    }}

 

覆蓋率:

 

軟體測試技術 hw3

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.