nextday 软件测试.doc
- 格式:doc
- 大小:1.82 MB
- 文档页数:13
吉林大学应用技术学院
实验(训)报告单(电子版)
实验编号 2 实验班级
实验名称 测试nextdate
任务书编号 1 实验组别
实验组成员 报告人 指导教师
实 验 报 告
代码: #ifndef _Date_H
#define _Date_H
#include
class Date
{
public:
Date(){}
Date(int,int,int);
Date(Date &);
~Date(){}
void setDate(int,int,int);
bool IsLeapYear() const;
int TimeElapsed() const;
void NextDate();
void print();
private:
int year;
int month;
int day;
};
#endif
#include
#include "stdlib.h"
Date::Date(int y,int m,int d)
{
year=y; month=m;
day=d;
}
Date::Date(Date &a)
{
year=a.year;
month=a.month;
day=a.day;
}
void Date::setDate(int y,int m,int d)
{
year=y;
month=m;
day=d;
int tof;
if((year>1919&&year<2051)&&(month>0&&month<13))
{
switch(month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
{
if(day>0&&day<32)
{
tof=1;
break;
}
else
{
tof=0; break;
}
}
case 4:
case 6:
case 9:
case 11:
{
if(day>0&&day<31)
{
tof=1;
break;
}
else
{
tof=0;
break;
}
}
case 2:
{
if((IsLeapYear()&&day>0&&day<30)||(!IsLeapYear()&&day>0&&day<29))
{
tof=1;
break;
}
else
{
tof=0;
break;
}
}
default:
{
tof=0; break;
}
}
}
else
{
tof=0;
}
if(tof==0)
{
cout<<"请输入正确的年月日"<
exit(1);
}
}
bool Date::IsLeapYear() const
{
return (year%400==0)||(year%100!=0)&&(year%4==0);
}
int Date::TimeElapsed() const
{
int sum=0;
int b;
if(IsLeapYear())
b=29;
else
b=28;
return 0;
}
void Date::NextDate()
{
if((year>1900&&year<2050)&&(month>0&&month<13))
{
switch(month)
{ case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
{
if(day==31)
{
month+=1;
day=1;
break;
}
else
{
day+=1;
break;
}
}
case 4:
case 6:
case 9:
case 11:
{
if(day==30)
{
month+=1;
day=1;
break;
}
else
{
day+=1;
break;
} }
case 12:
{
if(day==31)
{
year+=1;
month=1;
day=1;
break;
}
else
{
day+=1;
break;
}
}
case 2:
{
if((IsLeapYear()&&day==29)||(!IsLeapYear()&&day==28))
{
month+=1;
day=1;
break;
}
else
{
day+=1;
break;
}
}
default:
{
cout<<"无效输入!!"<
}
} }
}
void Date::print()
{
cout<<"日期为:"
<
<
<
}
#include
int y,m,d;
int inputYear()
{
int y;
cout<<"年:";
cin>>y;
if(y>1900&&y<2050)
return y;
else
{
cout<<"无效输入!"<
return y;
}
}
int inputMonth()
{
cout<<"月:";
cin>>m;
if(m>0&&m<13)
return m;
else
{
cout<<"无效输入!"<
}
}
int inputDay()
{
cout<<"日:";
cin>>d;
if(d>0&&d<32)
return d;
else
{
cout<<"无效输入!"<
return d;
}
}
void main()
{
While(1)
{
Date NowDate;
cout<<"请输入"<
int Y=inputYear();
int M=inputMonth();
int D=inputDay();
NowDate.setDate(Y,M,D);
NowDate.print();
NowDate.TimeElapsed();
NowDate.NextDate();
cout<<"下一天的";
NowDate.print();
cout<
}
}
Nextdate测试用例 :
输入条件 有效等价类 无效等价类
日期范围 1 1≤日期≤27
2 日期=28
3 日期=29
4 日期=30
5 日期=31 6 日期<1
7 日期>31
8 日期=29
9 日期=30
10 日期=31
11 非数字字符
月份范围 12 月份=4,6,9,11
13 月份= 1,3,5,7,8,10
14 月份=2
15 月份=12 16 月份<1
17月份>12
18非数字字符
年范围 19 1900<=年<=2050的闰年
20 1900<=年<=2050的非闰年 21 年<1900
22 年>2050
23 非数字字符
Nextdate测试用例:
序号 日期 月份 年 预期结果
1 0 0 0 无效输入!
2 0 5 1999 无效输入!
3 25 0 1999 无效输入!
4 25 5 0 无效输入!
5 32 5 1999 无效输入!
6 25 13 1999 无效输入!
7 25 5 1890 无效输入!
8 25 5 2051 无效输入!
9 28 12 2000 2000 12 29
10 28 2 1999 1999 3 1
11 28 12 1999 1999 12 29