Leap year judgment of software test instance

Source: Internet
Author: User

First, the demand

Test the input year for leap years and to prevent illegal input

Second, demand analysis

1. Display an input box for input and submit a button for input;

2. Filter illegal input, when and only if the input character Embox is a number and the number is not 0 (note: ad 00 does not exist) to do further processing, otherwise prompt input error;

Write with Html&javascript only:

function Checknum (value) {//value The    value passed in as input box var Reg =/^[0-9]*$/;     if return true   ;              Enter the    correct returnfalse; Illegal input}

3. Determine whether the Swiss year is based on the number entered:

A. The average year can be divisible by 4 and not divisible by 100 for leap years. (such as 2004 years is a leap year, 1900 is not a leap year) b. The century can be divisible by 400 is leap years. (as 2000 is a leap year, 1900 is not a leap year)
if((document.getElementById ("input"). value%4==0&&document.getelementbyid ("input"). value% -!=0)|| document.getElementById ("input"). value% -==0) document.getElementById ("Output"). innerhtml="enter years as leap year.";Elsedocument.getElementById ("Output"). innerhtml="Enter the year as common year.";

Third, test cases

Number Input Expected output
1 2008 Enter years as leap year.
2 2000 Enter years as leap year.
3 1900 Enter the year as common year.
4 Abcd Please check that the input is correct.
5 0 Please check that the input is correct.

Iv. Practical Testing

Five, Source: Html&javascript

  

<!DOCTYPE HTML><HTML><HeadLang= "en"><MetaCharSet= "GB2312"><style>Body{text-align:Center}</style><Body>Please enter the year:<inputtype= "text"ID= "Input"Autofocus= "Autofocus"/><inputtype= "Submit"value= "OK"onclick= "Test ()"/><PID= "Output"></P><Script>functionTest () {if(!Checknum (document.getElementById ("input"). Value)||document.getElementById ("input"). Value==0) document.getElementById ("Output"). InnerHTML="Please check that the input is correct."; Else if( (document.getElementById ("input"). Value%4==0&&document.getElementById ("input"). Value% -!=0)||document.getElementById ("input"). Value% -==0) document.getElementById ("Output"). InnerHTML="enter years as leap year."; Elsedocument.getElementById ("Output"). InnerHTML="Enter the year as common year.";}functionChecknum (value) {varReg= /^[0-9]*$/; if(Reg.test (value))return true; return false;}</Script></Body></HTML>

Leap year judgment of software test instance

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.