Software Testing-Leap year

Source: Internet
Author: User

First, the software requirements

  about the A leap year (leap year) is a very simple decision. Given a year, if the year can be divisible by 4, but not divisible by 100, or can be divisible by 400, then we believe that year is a leap years, otherwise it will be common year.

For normal users, if you enter any year as required, we will be able to give you a leap years. However, for some illegal users, they may not enter as required. For example, it may be that the user is not the input year, but some string or non-positive integer, such as 2012abc,-1868,2015.5 and so on. For these illegal inputs, if we do not do the corresponding processing, it may cause the program to crash or even cause more harm.

Second, the test analysis

  For possible situations, I have done the following analysis:

Number Input Expected output
1 2012 was leap year
2 1900 1900 is nonleap year
3 2000 Nonleap year
4 2015 are nonleap year
5 2015abc Input Invalid
6 2015.5 Input Invalid
7 -2015 Input Invalid

Third, the test code

#include <iostream> #include <sstream>using namespace std;void checkleapyear (string year) {for    (int i = 0 ; I < year.size (); i++) {        if (year.at (i) > ' 9 ' | | year.at (i) < ' 0 ') {            cout << ' Input invalid! ' << Endl;            return;        }    }    StringStream SS;    int num;    SS << Year;    if (!ss.good ()) {        cout << "StringStream error!" << Endl;    }    SS >> Num;    if (num% 4 = = 0 && num%! = 0) | | num% = = 0)        cout << num << "is leap year!" << Endl;    else        cout << num << "is nonleap year!" << Endl;} int main () {    string year;    cout << "Please input a year:";    while (CIN >> year) {        checkleapyear (year);        cout << "\nplease input a year:";    }    return 0;}

  

Iv. test Results

Software Testing-Leap year

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.