Job 8 Unit Test exercise

Source: Internet
Author: User

Test Cases

Serial number Test input: Three edges (a,b,c) Test Prophecy (Oracle: Right angle, isosceles, equilateral triangle)
1 Input (1,1,1) Equilateral triangle
2 Input (3, 4,5) Right triangle
3 Input (2, 2,1) Isosceles Triangle
4 Input (3, 3,6) Not a triangle.
5 Input (3, -3,6) Illegal
6 Input (-3, 3,6) Illegal

Sentiment: Equivalence class partitioning is a typical, important black-box test method that divides all possible input data (valid and invalid) into a number of equivalence classes. Then select representative data from each section as a reasonable classification of test cases. Reasonable use of good equivalence class partitioning method can save the test time.

GitHub Account: HTTPS://GITHUB.COM/HJS12

 Public classTriangle {//defining the triangular sides of a triangle        protected LongLbordera =0; protected LongLborderb =0; protected LongLBORDERC =0; //constructor Function     PublicTriangle (LongLbordera,LongLborderb,LongLborderc) {     This. Lbordera =Lbordera;  This. Lborderb =Lborderb;  This. Lborderc =Lborderc; }    /** * determine if the triangle is * * is return true; not return false*/     Publicboolean istriangle (Triangle Triangle) {Boolean istriangle=false; //judgment bounds, greater than 0 less than or equal to Long.max_value, false on out of bounds       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)) {        //Judging the difference between the two sides is less than the third side        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; }    /** * Judging triangle type * * Only two triangles with equal triangle return the string "isosceles triangle"; triangles with equal three sides return the string "equilateral triangle"; triangle with unequal triangular return string "not equilateral triangle";*/     Publicstring GetType (Triangle Triangle) {string Strtype="illegal"; //Judging if it's a triangle       if(Istriangle (triangle)) {//Judging whether it's equilateral triangle          if(Triangle.lbordera = =Triangle.lborderb&& Triangle.lborderb = =Triangle.lborderc) {strtype="Regular"; }          //Judging whether it is not equilateral triangle          Else if((Triangle.lbordera! =Triangle.lborderb)&& (Triangle.lborderb! =Triangle.lborderc)&& (Triangle.lbordera! =Triangle.lborderc)) {strtype="Scalene"; }          //The triangle is not all equal to all three sides, but not all of them, but only partially equal or isosceles triangle.          Else{strtype="Isoceles"; }        }       returnstrtype; }    /** * calculates the absolute value of the difference between the two sides * **/     Public LongDiffofborders (LongALongb) {return(A > B)? (a): (B-a); } @Test Public voidTestIsTriangle1 () {Triangle T=NewTriangle (1,1,1);        Assertfalse (T.istriangle (t)); } @Test Public voidTestIsTriangle2 () {//according to the mutant, this test case should failTriangle T =NewTriangle (3,4,5);        Assertfalse (T.istriangle (t)); } @Test Public voidTestIsTriangle3 () {Triangle T=NewTriangle (2,2,1);        Assertfalse (T.istriangle (t)); } @Test Public voidtestIsTriangle4 () {Triangle T=NewTriangle (3,3,6);        Assertfalse (T.istriangle (t)); } @Test Public voidtestIsTriangle5 () {Triangle T=NewTriangle (3,-3,6);        Assertfalse (T.istriangle (t)); } @Test Public voidTestIsTriangle6 () {Triangle T=NewTriangle (-3,3,6);        Assertfalse (T.istriangle (t)); }    /** * Used to get the side length of triangles*/     Public Long[] GetBorders () {Long[] borders =New Long[3]; borders[0] = This. Lbordera; borders[1] = This. Lborderb; borders[2] = This. Lborderc; returnborders; }    

Job 8 Unit Test exercise

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.