Work on software test books

Source: Internet
Author: User

/******************************************************* * Finds and prints n prime integers * Jeff Offutt, SPR ING 2003 ******************************************************/      Public Static voidPrintprimes (intN) {intCurprime;//Value currently considered for primeness        intNumprimes;//Number of primes found so far.        BooleanIsPrime;//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(inti = 0; I <= numPrimes-1; i++)             { //For each previous prime.                if(curprime%primes[i]==0)                 { //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(inti = 0; I <= numPrimes-1; i++) {System.out.println ("Prime:" +Primes[i]); }     } //End Printprimes

Problem one: Draw the control flow graph:

Problem two: Design a t2= (n=5) can find but t1= (n=3) can't find the error

Problem three: Looking for a set of test cases that do not pass through while loops

You can meet your requirements when you n=1.

Question four: All TR required to find the point overlay, Edge overlay, and master path coverage

Point overlay:

{(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15)}

Side overrides {(0,1), (2,3), (3,4), (4,5), (5,6), (6,7), (7,8), (8,5), (5,9) (9,2), (9,10), (10,2), (2,11), (2,12), (12,13), (13, 14) (14,12) (12,15)} main path overrides: {(0,1,2,3,4,5,6,7,8)), (0,1,11,12,13,14), (0,1,11,12,15), (0,1,2,3,4,5,9,10), (5,6,7,8,5), (2,3,4,5,9,2), (2,3,4,5,9,10,2)} question five test cases covered by any programming master path
 Public classTriangle {protected LongLbordera = 0; protected LongLborderb = 0; protected LongLBORDERC = 0; //Constructor     PublicTriangle (LongLbordera,LongLborderb,LongLborderc) {         This. Lbordera =Lbordera;  This. Lborderb =Lborderb;  This. Lborderc =Lborderc; }    /*** Check if it is a triangle * *@returntrue for triangle and false not*/     Public BooleanIstriangle (Triangle Triangle) {BooleanIstriangle =false; //Check Boundary        if((Triangle.lbordera > 0 && triangle.lbordera <=long.max_value)&& (Triangle.lborderb > 0 && triangle.lborderb <=long.max_value)&& (Triangle.lborderc > 0 && triangle.lborderc <=long.max_value)) {            //Check if subtraction of border larger than the third            if(Diffofborders (Triangle.lbordera, Triangle.lborderb) <Triangle.lborderc&& diffofborders (Triangle.lborderb, TRIANGLE.LBORDERC) <Triangle.lbordera&& diffofborders (TRIANGLE.LBORDERC, Triangle.lbordera) <triangle.lborderb) {Istriangle=true; }        }        returnIstriangle; }    /*** Check the type of triangle * * consists of "illegal", "Regular", "Scalene", "Isosceles"*/     Publicstring GetType (Triangle Triangle) {string Strtype= "illegal"; if(Istriangle (triangle)) {//is Regular            if(Triangle.lbordera = =Triangle.lborderb&& Triangle.lborderb = =Triangle.lborderc) {strtype= "Regular"; }            //If Scalene            Else if((Triangle.lbordera! =Triangle.lborderb)&& (Triangle.lborderb! =Triangle.lborderc)&& (Triangle.lbordera! =Triangle.lborderc)) {strtype= "Scalene"; }            //if Isosceles            Else{strtype= "Isosceles"; }        }        returnstrtype; }    /*** Calculate the diff between borders * **/     Public LongDiffofborders (LongALongb) {return(A > B)? (a): (B-a); }    /*** Get length of borders*/     Public Long[] GetBorders () {Long[] borders =New Long[3]; borders[0] = This. Lbordera; borders[1] = This. Lborderb; borders[2] = This. Lborderc; returnborders; }}
Import Staticorg.junit.assert.*;ImportOrg.junit.AfterClass;Importorg.junit.Test; Public classtriangletest {@Test Public voidTest () {Long[]str={2,2,3}; Triangle T=NewTriangle (2, 2, 3); Triangle T1=NewTriangle (2, 2, 2); Triangle T2=NewTriangle (2, 3, 4); Triangle T3=NewTriangle (2, 2, 4); Assertequals (T.istriangle (t),true); Assertequals (T.gettype (t),"Isosceles" ); Assertequals (T1.gettype (t1),"Regular"); Assertequals (T2.gettype (T2),"Scalene" ); Assertequals (T3.gettype (T3),"Illegal" ); Assertequals (T.diffofborders (2, 3), 1);    Assertarrayequals (T.getborders (), str); }}

Work on software test books

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.