Software testing------The input box for judging leap years

Source: Internet
Author: User

1. Topic Requirements

Sitting in the last row to see is not very clear, looks like the teacher gave a can judge leap year input box, and then asked everyone input ABCD will be what, the result is an error.

Our task is to make this input box that determines leap years and allow the system to handle illegal input.

2. Implementation methods

Implementation method re-html+servlet, the key code is as follows:

1PrintWriter out =Response.getwriter ();2String tmp = Request.getparameter ("Year");3Out.println ("<! DOCTYPE HTML public \ "-//W3C//DTD HTML 4.01 transitional//en\" > ");4Out.println (");5Out.println (");6OUT.PRINTLN ("<title> Inspection results </title>");7Out.println (");8Out.println ("<body>");9         if(Checkinput (tmp)) {Ten             if(Isleapyear (Integer.parseint (TMP))) { OneOut.println (tmp+ "is a leap year"); A}Else{Out.println (tmp+ "is not a leap year");} -}Else{out.println ("input is not valid, please click Back to retry");} -Out.println ("<button><a href=\"/userform/leapyear.jsp\ "> Back </a></button>"); theOut.println ("</body>"); -Out.println ("); - Out.flush (); -  +  Public Booleancheckinput (String tmp) { -Pattern pattern = Pattern.compile ("([0-9]) {4}");  +Matcher Matcher =Pattern.matcher (TMP);  A         BooleanOK = matcher.matches ();//returns True when the condition is satisfied, otherwise false at         returnOK; -     } -      -  Public BooleanIsleapyear (intYear ) { -         return(Year% 400 = = 0) | | (year% 4 = = 0 && Year% 100! = 0); -}

3. Testing

First to complete the requirements of the topic, read the above code can be known, pattern matching can accurately filter out the illegal input, such as the problem of ABCD,

In this way, when the leap year is called parseint () there will be no conversions, and no exception will be reported.

    

Next, for the sake of consideration, give some test cases

1. Null input present

The user is prompted for the year input

2. The input is the number but the length is not suitable

3. When a non-digital input is present, the "ABCD" example

4. Year that can be divisible by 400

    

5. Year that cannot be divisible by 400, divisible by 4 , but not divisible by 100

    

6. Year that cannot be divisible by 400 and not divisible by 4

    

7. Year that cannot be divisible by 400, divisible by 4, and divisible by 100

    

4. Results analysis

Test using the White box test path coverage, sensory system learning software testing can make the test more orderly, reduce omissions.

Software testing------The input box for judging leap years

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.