Design the test cases
TAG:
- 引用 删除 非常夏日 / 2011-09-15 19:01:17
-
Design the test cases to make sure that all the following statements will be executed at least one time.
int IsLeap (int year)
{
if (year %4 == 0)
{
if( year % 100 == 0)
{
if (year % 400 ==0)
Leap = 1
else
Leap = 0;
}
Leap = 1;
}
Leap = 0;
return leap;
}
Answer:
Case1: year =?
Case2: year =?
Case3: year =?
Case4: year =?
zhengyuhui KF49763(zkf49763) 2011-09-15 16:13:01
//1.能被4 整队,但不能被100 整除的年份都是闰年。 2.能被100 整除,又能被400 整除的年份是闰年。
//0表示闰年,1表示非闰年
int IsLeap(int year)
{
int leap = 1;
if (year % 4 == 0)
{
if (year % 100 == 0)
{
if (year % 400 == 0)
{
//能被100 整除,又能被400 整除的年份是闰年
leap = 0;
}
else
{
//不是闰年
leap = 1;
}
}
else
{
//闰年 能被4 整队,但不能被100 整除的年份都是闰年
leap = 0;
}
}
return leap;
}