1. The following code is a test case for judging whether the input year is a leap year and designing judgment coverage and condition coverage.
if (year<0)
return -1;
if ((year%4==0&&year%100!=0)||(year%400==0))
return 1;
else
return 0;
2. The following code is used to judge leap year and is written in C language. The corresponding control flow diagram is shown in Figure 7-14 on page 207 of the book. Please answer the questions as required.
int isLeap(int year)
{ int leap;
if (year % 4 == 0)
{
if (year % 100 == 0)
{
if(year % 100 == 0)
leap = 1;
else
leap = 0;
}
else
leap = 1;
}
else
leap = 0;
return leap;
}
(1) Please calculate the cyclomatic complexity V(G) of the above control flow graph.
Answer: P=3+1=4 (P is the judgment node)
V(G)=P+1=5
(2) Find the independent path.
Answer: path1: 1 - 2 - 10 - 11 - 12
path2:1 - 2 - 3 - 8 - 9 - 11 - 12
path3:1 - 2 - 3 - 4 - 6 - 7 - 9 - 11 - 12
path4:1 - 2 - 3 - 4 - 5 - 7 - 9 - 11 - 12
(3) Assuming that the input value range is 1000<year<2001, please use the basic path test method to design a test case for the variable year to meet the requirements of basic path coverage.
3. A company recruits personnel with a bachelor's degree or above, majoring in computer, communication, and automation, aged 22 to 30 years old. Please divide the valid equivalence class and invalid equivalence class for each condition.