Software Testing Technology HW3

Source: Internet
Author: User

Job Title: Textbook 49 page 7th A to D, and implement a master path overlay test based on JUnit and Eclemma
One, use the following method Printprimes () for questions a-f below

1 1./** *****************************************************2 2. * Finds and Prints n prime integers3 3. * Jeff Offutt, Spring 20034 4. **********************************************************/5 5.Private Static voidPrintprimes (intN)6 6. {7 7.intCurprime;//Value currently considered for primeness8 8.intNumprimes;//Number of primes found so far.9 9. Boolean isprime;//Is curprime prime?Ten Ten.int[] primes =New int[Maxprimes];//The list of prime numbers. One  One. A  A.//Initialize 2 into the list of primes. -  -. primes [0] =2; -  -. Numprimes =1; the  the. Curprime =2; -  -. while(Numprimes <N) -  -. { -  -. curprime++;//next number to consider ... +  +. IsPrime =true; -  -. for(inti =0; I <= numprimes-1; i++) +  +. {//For each previous prime. A  A.if(Isdivisible (primes[i], curprime)) at  at. {//Found a divisor, curprime is not prime. -  -. IsPrime =false; -  -. Break;//Out of loop through primes. -  -. } -  -. } -  -.if(IsPrime) in  in. {//Save It! -  -. Primes[numprimes] =Curprime; to  to. numprimes++; +  +. } -  -. }//End while the  the. *  *.//Print all the primes out. $  $. for(inti =0; I <= numprimes-1; i++)Panax Notoginseng Panax Notoginseng. { -  -. System. out. println ("Prime:"+primes[i]); the  the. } +  +. }//End Printprime

A. Draw a control flow chart
Answer:

B. Design a t2= (n=5) than t1= (n=3) easy to find errors found

Solution: Array Out of bounds

C. Write a test case so that the corresponding test path access connection While statement starts to the edge of the FOT statement without passing through the loop body of the while

Answer: T:n=1

D. Example of each node overlay, Edge overlay and master path covered TR

Answer:

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

Side coverage Requirements: {(a), (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)}

Main PATH Coverage requirements:

{

(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)

}

Two. Implement a Master path overlay test

Use the first on-Machine judgment Triangle Program:

Package ZJZ; Public classTriangle {Private Static intresult=0;  Public voidTypeoftriangle (intAintBintc) {if(A + b <= C | | A + c <= B | | + C <= a && a<=0&& b <=0&& C <=0) {result=1;//not a triangle .                        if(A = = b && a = =c) Result=2;//isosceles                        if(A = = B | | b = = c | | a = =c) Result=3;//Equilateral            Elseresult=4;//Normal        }            }         Public intGetResult () {returnresult; }        Public voidClear () {result=0; }

Test the class use case:

Package Zjz;importStaticorg.junit.assert.*; import org.junit.Test; Public classTestcalculator {Private StaticCalculator cal =NewCalculator (); @Test Public voidTesttriangle () {Cal.triangle (2,2,2); Assertequals (3, Cal.getreuslt ());//equilateral triangleCal.triangle (3,3,5); Assertequals (2, Cal.getreuslt ());//isosceles TriangleCal.triangle (3,4,5); Assertequals (1, Cal.getreuslt ());//Common TrianglesCal.triangle (1,2,3); Assertequals (0, Cal.getreuslt ());//cannot form a triangle    }}

Coverage:

Software Testing Technology HW3

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.