0% found this document useful (0 votes)
68 views

STUDENT ID: 25211207696: Exercise (Lab) 6

The student designed test cases for two problems using white-box testing techniques. For problem 1, the student used condition coverage criteria to determine 5 test paths for a method that returns the maximum number of days in a month. Test cases were then designed to execute each path. For problem 2, the student used basic path coverage to determine 5 basis paths for a method that counts characters in a string, and test cases were designed to execute each basis path.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
68 views

STUDENT ID: 25211207696: Exercise (Lab) 6

The student designed test cases for two problems using white-box testing techniques. For problem 1, the student used condition coverage criteria to determine 5 test paths for a method that returns the maximum number of days in a month. Test cases were then designed to execute each path. For problem 2, the student used basic path coverage to determine 5 basis paths for a method that counts characters in a string, and test cases were designed to execute each basis path.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

EXERCISE (LAB) 6

STUDENT ID: 25211207696


STUDENT FULL-NAME:Trần Hoàng Long

White-box Testing
1. Problem 1: Let’s design the set of TCs for the problem (see the code below) by using
the "Condition Coverage Criteria"!

internal static int GetMaxDay(int month, int day, int year)


{
int maxDay = 0; 1
if (!IsInvalidDate(month, day, year)) 2
{
if (IsThirtyOneDayMonth(month)) { 3
maxDay = 31; 4
}
else if (IsThirtyDayMonth(month)) { 5
maxDay = 30; 6
}
else {
maxDay = 28; 7
if (IsLeapYear(year)) { 8
maxDay = 29; 9
}
}
return maxDay; 10
} Ne

2. Problem 2: Let’s design the set of TCs for the problem (see the code below) by using
the "Basic-Path Coverage"!
static int CountC(string s)
{
int index = 0; int i = 0; int j = 0; int k = 0; 1
char[] strArray = s.ToCharArray();
if (strArray[index] == 'A') 2
{
while (++index < strArray.Length) 3
{
if (strArray[index] == 'B') 4
{
j = j + 1; 5
k = 0;
}
else if (strArray[index] == 'C') 6
{
i = i + j; 7
k = k + 1;
j = 0;
}
}
i = i + j; 8
}
else
{
return -1; 9
}
return i; 10
} Ne

*Note: The steps are follows:


1. Determine the nodes and construct a control flow graph.
2. Compute Cyclomatic Complexity of the control flow graph.
3. Determine all paths.
4. Identify and eliminate unreasonable paths.
5. Determine basis paths.
6. Design test scenarios to go through these basis paths

SOLUTION
Problem 1.
1. Determine the nodes and construct a control flow graph.

2. Compute Cyclomatic Complexity of the control flow graph.


1/ Number of closed regions including the surrounding rectangle + 1 = 4 + 1 =5
2/ Number of binary predicate + 1 = 4 + 1=5
3/ Number of edges - Number of Nodes +2 =14 - 11 + 2=5

3. Determine all paths.


1-2-10-ne
1-2-3-4-ne
1-2-3-5-6-10-ne
1-2-3-5-7-10-ne
1-2-3-4-5-7-8-9-10-ne
4. Identify and eliminate unreasonable paths (if any).

5. Determine the minimum number of paths that satisfy condition coverage criteria.
1-2-10-ne
1-2-3-4-ne
1-2-3-5-6-10-ne
1-2-3-5-7-10-ne
1-2-3-4-5-7-8-9-10-ne

6. Design test scenarios to go through these paths.


1-2-10-ne
Input: 25/06/2001
Output: MaxDay=0
1-2-3-4-ne
Input: 07/06/2001
Output: MaxDay=31
1-2-3-5-6-10-ne
Input: 06/06/2001
Output: MaxDay=30
1-2-3-5-7-10-ne
Input: 02/06/2001
Output: MaxDay=28
1-2-3-4-5-7-8-9-10-ne
Input: 02/06/2000
Output: MaxDay=29

Problem 2.
1. Determine the nodes and construct a control flow graph.
2. Compute Cyclomatic Complexity of the control flow graph.

1/ Number of closed regions including the surrounding rectangle + 1 = 4 + 1 =5


2/ Number of binary predicate + 1 = 4 + 1=5
3/ Number of edges - Number of Nodes +2 =14 - 11 + 2=5

3. Determine all paths.

1-2-9-10-Ne
1-2-3-8-10-Ne
1-2-3-4-5-3-8-10-Ne
1-2-3-4-6-3-8-10-Ne
1-2-3-4-6-7-3-8-10-Ne

4. Identify and eliminate unreasonable paths.

5. Determine basis paths.


1-2-9-10-Ne
1-2-3-8-10-Ne
1-2-3-4-5-3-8-10-Ne
1-2-3-4-6-3-8-10-Ne
1-2-3-4-6-7-3-8-10-Ne
6. Design test scenarios to go through these basis paths
1-2-9-10-Ne.Expected results: i;
1-2-3-8-10-Ne.Expected results: i;
1-2-3-4-5-3-8-10-Ne.Expected results: i;
1-2-3-4-6-3-8-10-Ne.Expected results: i;
1-2-3-4-6-7-3-8-10-Ne.Expected results: i;

You might also like