Software Testing covers some jobs

Source: Internet
Author: User

The title code is as follows:

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

A. The control flow graph is as follows:

B. Design an error that t2= (n=5) is more likely to find than t1= (n=3). It is easy to think of the array out of bounds, that is, when maxprimes = 3 or 4 o'clock, T1 normal passage, and T2 will be due to cross the error.

C. obviously when n = 1 o'clock does not pass through the while loop.

D. Find all the point overlays, edge overlays, and the master path covered tr.

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

Side overlays: {(2,3), (2,10), (3,4), (4,5), (4,8), (5,6), (5,7), (7,4), (6,8), (8,9), (8,2), (9,2), (10,11), (11,12), (11, 13 ), (12,11)}

Main path overrides: {(1,2,3,4,8,2,10,11,13), (1,2,3,4,8,2,10,11,12,11,13), (1,2,3,4,8,9,2,10,11,13), ( 1,2,3,4,8,9,2,10,11,12,11,13),

(1,2,3,4,5,6,8,2,10,11,13), (1,2,3,4,5,6,8,2,10,11,12,11,13), (1,2,3,4,5,6,8,9,2,10,11,13), ( 1,2,3,4,5,6,8,9,2,10,11,12,11,13),

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

(2,3,4,5,6,8,9,2) ...}

E. The test case that overrides the main path of the last Triangle decision programming.

1 //Triangle.java2 Importjava.util.Arrays;3 4  Public classTriangle5 {6      Publicstring Check (string p, String q, String R)7     {8         int[] A =New int[3];9A[0] =Integer.parseint (p);TenD[T] =Integer.parseint (q); OneC[P] =Integer.parseint (r); A Arrays.sort (a); -         if(A[0] + a[1] > a[2] ) -         { the             if(A[0] = = a[2] ) -             { -                 return"Equilateral"; -             } +             Else -             { +                 if(A[0] = = A[1] | | a[1] = = a[2] ) A                 { at                     return"Isosceles"; -                 } -                 Else -                 { -                     return"Scalene"; -                 } in             } -         } to         Else +         { -             return"Not a triangle"; the         } *     } $}
1 Import Staticorg.junit.assert.*;2 Importjava.util.Arrays;3 Importjava.util.Collection;4 ImportOrg.junit.Before;5 Importorg.junit.Test;6 ImportOrg.junit.runner.RunWith;7 Importorg.junit.runners.Parameterized;8 Importorg.junit.runners.Parameterized.Parameters;9 Ten@RunWith (parameterized.class) One  Public classtriangletest A { -     PrivateString p; -     PrivateString Q; the     PrivateString R; -     PrivateString expected; -     PrivateTriangle tmp; -      +      Publictriangletest (string p, String q, String r, string expected) -     { +          This. P =p; A          This. Q =Q; at          This. R =R; -          This. Expected =expected; -     } -  - @Before -      Public voidsetUp () in     { -TMP =NewTriangle (); to     } +      - @Parameters the      Public StaticCollection<string[]>GetData () *     { $         returnArrays.aslist (Newstring[][]Panax Notoginseng         { -{"3", "3", "3", "equilateral" }, the{"3", "4", "4", "Isosceles" }, +{"3", "4", "5", "Scalene" }, A{"3", "4", "7", "Not a triangle" }, the         }); +     } -  $ @Test $      Public voidTest () -     { -Assertequals ( This. Expected, Tmp.check (p, Q, R)); the     } -}

For the test case see: @Parameters section.

Visible coverage reached 100%.

Software Testing covers some jobs

Related Article

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.