您好,欢迎访问三七文档
实验二白盒测试一.实验目的能熟练应用白盒测试技术设计测试用例;二.实验内容计算生日是星期几已知公元1年1月1日是星期一。编写一个程序,只要输入年月日,就能回答那天是星期几。应用逻辑覆盖方法和基本路径测试方法为上面的问题设计测试用例。三.程序代码#includestdio.hintcheck(intyear,intmonth,intday){intpass=1;intleap=0;if((year%4==0&&year%100!=0)||year%400==0)leap=1;if(year1||day1)return0;switch(month){case1:case3:case5:case7:case8:case10:case12:if(day31)return0;break;case4:case6:case9:case11:if(day30)return0;break;case2:if(leap==1&&day29){return0;}if(leap==0&&day28){return0;}break;default:return0;break;}returnpass;}voidfun(){intyear,month,day,sumday;sumday=0;printf(inputyear,month,day:\n);scanf(%d%d%d,&year,&month,&day);if(check(year,month,day)==0){printf(输入的日期无效);return;}if(month==1||month==2){month+=12;year--;}sumday=(day+2*month+3*(month+1)/5+year+year/4-year/100+year/400)%7;if(month==13||month==14){month-=12;year++;}switch(sumday){case0:printf(%d-%d-%disMonday\n,year,month,day);break;case1:printf(%d-%d-%disTuesday\n,year,month,day);break;case2:printf(%d-%d-%disWednesday\n,year,month,day);break;case3:printf(%d-%d-%disThurday\n,year,month,day);break;case4:printf(%d-%d-%disFriday\n,year,month,day);break;case5:printf(%d-%d-%disSaturday\n,year,month,day);break;case6:printf(%d-%d-%disSunday\n,year,month,day);break;default:printf(dateerror);break;}}main(){for(inti=0;i14;i++)fun();}四.画出程序的控制流图1.程序流程图如下:month==13||month==14nomonth==1||month==2yesmonth+=12;year--;计算星期数sumday=公式(year,month,day)noyesMonth-=12;year++;5460123456其他sumday输出语句1输出语句2输出语句3输出语句4输出语句5输出语句6输出语句7输出语句0结束78910111213141515输入年月日year,month,day23endCheck(year,month,day)01Check()函数nononoyesyes得到year,month,dayyear1||day1no(year%4==0&&year%100!=0)||year%400==0135781012469112其他monthreturnpasspass=1;leap=0;leap=1;return0day31day30return0noyesreturn0yesleap==1&&day29leap==0&&day28return0161817192021222324252628292827313032332.程序控制流图如下:16191721222324313334end3.用基本路径的测试路径编号基本路径编号基本路径1⒃⒄⒆(21)(24)(31)(33)11(0)①2⒃⒆(34)12(0)②③④⑤⑥⑦⑧3⒃⒆(21)(34)13(0)②④⑤⑦⑨4⒃⒆(21)(22)(34)14(0)②④⑤⑦⑩5⒃⒆(21)(23)(34)15(0)②④⑤⑦(11)6⒃⒆(21)(24)(34)16(0)②④⑤⑦(12)7⒃⒆(21)(31)(34)17(0)②④⑤⑦(13)8⒃⒆(21)(22)(33)18(0)②④⑤⑦(14)9⒃⒆(21)(23)(33)10⒃⒆(21)(31)(33)15243587612end910111314条件:编号条件编号编号T1month==1T13year%100!=0T25month==2T2month==2T14year%100!=0T26month==3T3month==13T15year%400==0T27month==4T4month==14T16year1T28month==5T5sumday==0T17day1T29month==6T6sumday==1T18month==1T30month==7T7sumday==2T19day31T31month==8T8sumday==3T20day30T32month==9T9sumday==4T21leap==1T33month==10T10sumday==5T22leap==0T34month==11T11sumday==6T23day29T35month==12T12year%4==0T24day284.测试用例用例编号输入的数据预期的输出实际的输出执行的路径覆盖的条件1201221WednesdayWednesday(0)②③④⑤⑥⑦⑧T12,T13,T25,T21,T2,T4,T72201231ThurdayThurday(0)②④⑤⑦⑨T12,T13,T26,T83201246FridayFriday(0)②④⑤⑦⑩T12,T13,T27,T94201255SaturdaySaturday(0)②④⑤⑦(11)T12,T13,T28,T105201263SundaySunday(0)②④⑤⑦(12)T12,T13,T29,T1162012730MondayMonday(0)②④⑤⑦(13)T12,T13,T30,T572000815TuesdayTuesday(0)②④⑤⑦(14)T12,T15,T31,T682012931错误提示错误提示(0)①T12,T13,T20,T329201328WednesdayWednesday⒃⒄⒆(21)(24)(31)(33)T25,T22,T2,T4,T7102013012错误提示错误提示⒃⒆(34)T17112013126SaturdaySaturday⒃⒆(21)(34)T18,T1,T3,T101220131033错误提示错误提示⒃⒆(21)(22)(34)T33,T191320131131错误提示错误提示⒃⒆(21)(23)(34)T34,T20142012230错误提示错误提示⒃⒆(21)(24)(34)T12,T13,T25,T21,T23152013229错误提示错误提示⒃⒆(21)(31)(34)T25,T241620131231SaturdaySaturday⒃⒆(21)(22)(33)T35,T10172013630SundaySunday⒃⒆(21)(23)(33)T29,T11182013215FridayFriday⒃⒆(21)(24)(31)(33)T25,T22,T2,T4,T91901212错误提示错误提示⒃⒆(34)T16
本文标题:白盒测试
链接地址:https://www.777doc.com/doc-6275305 .html