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