Pair Programming 2

Source: Internet
Author: User

1. Statement of pairing

pairs of objects: Luo Chunyan Blog Address:http://www.cnblogs.com/chunchuner/

Contributions from both sides: 1:12. The topic requires a construction program, respectively: • Cannot trigger fault.        • Triggers fault, but does not trigger error. • Triggers an error, but does not produce failure. 3. Topic Overview

The user is prompted to enter two values, two values must be in [0,100], if the conditions do not meet their own prompt, if two values are less than 5, then output all input fewer than 5, the program exits. Otherwise, according to the input value to determine whether to use addition or subtraction, if the first number of input is less than the second number, then use subtraction calculation, the result is less than 0, or use addition, the result must be greater than 0.

4. Pairing photos 5. Source code
1  PackageCom.nanchen.jieduibiancheng;2 3 ImportJava.util.Scanner;4 5  Public classErrorfault {6     Private StaticScanner in =NewScanner (system.in);7     Private Static Final intRange_low = 0;//minimum value allowed for user input8     Private Static Final intRange_high = 100;//maximum value allowed for user input9     Private Static Final intLIMIT = 5;Ten     Private Static intResult//return Results One  A     /** - * Get user input, input value must be 0 to 100 integer -      *  the      * @return -      */ -      Public Static intGetuserinput () { -         intNumber =-1; +SYSTEM.OUT.PRINTLN ("Please input an integer number,range in [0,100]!"); -          while(true) { +             if(In.hasnextint ()) { ANumber =in.nextint (); at                 if(Number > Range_high | | number <Range_low) { -SYSTEM.OUT.PRINTLN ("The input integer number not in [0,100],please input again!"); -}Else { -                      Break; -                 } -}Else { inIn.nextline ();//Refresh input Stream -SYSTEM.OUT.PRINTLN ("Illegal input!!! The input must be a integer!please input again! "); to             } +         } -         returnNumber ; the     } *  $     /**Panax Notoginseng * Get back results -      *  the      * @paramNUM1 +      * @paramnum2 A      * @return the      */ +      Public Static intGetResult (intNUM1,intnum2) { -         if(Num1 <num2) { $             returnNUM1 + num2;//There is fault here, it should be subtraction $         } -         returnNUM1 +num2; -     } the     //as above, regardless of the input will perform the addition without performing the subtraction.  - Wuyi      Public Static voidMain (string[] args) { the         intOP1 =getuserinput (); -         intOP2 =getuserinput (); WuSystem.out.println ("******************************************************"); -System.out.println ("The user input num1 is" + OP1 + "The num2 is" +OP2); About         if(OP1 < LIMIT && OP2 <LIMIT) { $SYSTEM.OUT.PRINTLN ("All input less than 5!!!"); -             return; -         } -result =GetResult (OP1, OP2); A         if(Result > 0) { +             if(Result > 100) { theSystem.out.println ("illegal!"); -}Else { $SYSTEM.OUT.PRINTLN ("The system uses the Addition,and the result is" +result); the             } the}Else { the             if(Result <-50) { theSystem.out.println ("illegal!"); -}Else { inSYSTEM.OUT.PRINTLN ("The system uses Subtraction,and the result is" +result); the             } the         } About     } the  the}

6. Code description for the presence of fault
/*** Get back results *@paramNUM1 *@paramnum2 *@return     */     Public Static intGetResult (intNUM1,intnum2) {        if(Num1 <num2) {            returnNUM1 + num2;//There is fault here, it should be subtraction        }        returnNUM1 +num2; }    //as above, regardless of the input will perform the addition without performing the subtraction. 

As above, the addition calculation will be triggered regardless of the size of the first and second numbers entered by the user.

7. Test Case 1) exists fault but cannot trigger fault.

Because this program has branches, so long as not to enter the fault branch, you can not trigger fault!

2) trigger fault, but cannot trigger error.

As above, because the first value entered by the user is greater than the second value, the correct addition operation is triggered, so the fault is triggered, but no error is triggered.

3) trigger error, but cannot trigger failure.

As above, in fact the OPA < OpB, the subtraction should be performed, and the resulting result is less than-50, you should get a illegal output. However, the result of using the GetResult method is 101, triggering the fault, and generating the error, but the result of the output is also correct because the result is greater than 100. As above, the test case satisfies the trigger error, but does not trigger the Failure8. Summary

Now has entered the study of software testing, through the program, the software in the fault,error,failure has a very intuitive understanding and understanding, but also let us understand that testing has certain limitations, how to test effectively, how to test scientifically, how to get a higher rate of test, This is also the most important core learning content in this course. This is the beginning of this course, but also let us realize that software testing is interesting, and has a different understanding of the field of software testing.

Pair Programming 2

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.