有效等价类

软件测试上机
1、实验内容

在这里插入图片描述
2、实验目的
1、 初步了解软件测试的设计过程
2、 熟悉掌握设计思想,等价类划分,NextDate函数等等知识点
3、 代码设计思想(代码片段)
判断是否是闰年:(是的话就返回1,不是的话就返回0)
int is_leap(int q){
if(q%40&&q%100!=0) return 1;
if(q%400
0) return 1;
else return 0;
}
用NextDate函数,x、y、z分别赋值给Date1的年月日,来达到日期增加三天的目的。细则是2月份和12月份是比较特殊的:二月份他有可能是有28天,也有可能有29天;12月份,它一过去就要跳转到下一年。最后1.每个月31天的有 1月、3月、5月、7月、8月、10月、12月,一共是七个月,除去12月的,30号的第三天是下个月的一号,31号的第三天是下个月的二号;2.每月30天的有 4月、6月、9月、11月共四个月,29号的第三天是下个月的一号,30号的第三天是下个月的二号。
struct Date{
int year;
int month;
int day;
};
struct Date NextDate(int x,int y,int z){
struct Date Date1;
Date1.year=x;
Date1.month=y;
Date1.day=z;
if(y12){
if(z
30){
Date1.year=Date1.year+1;
Date1.month=1;
Date1.day=1;
}
else if(z==31){
Date1.year=Date1.year+1;
Date1.month=1;
Date1.day=2;
}
else{
Date1.day=Date1.day+2;
}
}
……………后面2月,30天的月份,31天的月份都是这样子的
return Date1;
}

覆盖等价类根据下面那个表输出等价类。无效的话是legal函数返回0,则为无效等价类,legal的二月份要考虑到闰年问题,调用上述的is_leap函数,其它的无效等价类自然而解。

在这里插入图片描述

	if(1<=day&&day<=26) day1=1;
	else if(day==27) day1=2;
	else if(day==28) day1=3;
	else if(day==29) day1=4;
	else if(day==30) day1=5;
	else if(day==31) day1=6;
	else day1=13;
	if(month==4||month==6||month==9||month==11) month1=7;
	else if(month==1||month==3||month==5||month==7||month==8||month==10) month1=8;
	else if(month==2) month1=9;
	else if(month==12) month1=10;
	else month1=14;
	if((year%4==0&&year%100!=0)||year%400==0) 
		year1=11;
	else year1=12;   

4、实验效果
4.1 有效等价类
1测试用例

测试用例 输入
期望输出
year month day
1 2000 2 2 2000月2月4号
2 2019 2 28 2019月3月1号
3 2018 12 30 2019月1月1号
4 2015 1 30 2015月2月1号

2代码效果
在这里插入图片描述

4.2 无效等价类
1测试用例

测试用例 输入
期望输出
year month day
1 2200 2 2 year不在2000-2100中
2 2018 13 13 month不在1-12中
3 2018 12 33 无效日期

2代码效果

在这里插入图片描述
https://blog.csdn.net/weixin_43206161

发布了68 篇原创文章 · 获赞 57 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/weixin_43206161/article/details/103935866