You are on page 1of 6

Software Quality Engineering

BSSE- 8th semester


White box testing techniques
Practice activity
Aneeza Rana 2312

Question 1:
Create Test cases to satisfy statement coverage and branch coverage
// Program to print positive number entered by the user
// If the user enters a negative number, it is skipped
#include <iostream>
using namespace std;
int main() {
int number;
cout << "Enter an integer: ";
cin >> number;
// checks if the number is positive
if (number > 0) {
cout << "You entered a positive integer: " << number << endl;
}
cout << "This statement is always executed.";
return 0;
}

Number of Nodes Statements


n0 Int number
Cin , cout
n1 (number>0)
n2 Cout<<”You entered a positive integer:……
n3 Cout<< “This statement is always executes…
Return 0
Control Flow Graph
int number;
cout << Enter an integer:
n0 cin >> number;

number > 0
n1

T F

cout << "This statement is


cout << "You entered a positive always executed.";
n2 n3
integer: " << number return 0;

Exit
Test Cases:
Statement Coverage:
Test Cases Input Expected Actual

1 number=1 You entered a positive integer: 1 You entered a positive integer: 1


This statement is always executed. This statement is always executed.

Branch Coverage:
Test Cases Input Expected Actual

1-Yes number=1 You entered a positive integer: 1 You entered a positive integer: 1
This statement is always executed. This statement is always executed.

2-No number=-2 This statement is always executed. This statement is always executed.

Question 2:
Create Test cases to satisfy condition coverage and multiple condition
coverage
Logical operators
#include <iostream>
#include <string>
using namespace std;
 int main()
{
  int a=10, b=8,c=12,d=14;
   if(!(a==0))
     cout<<"a is not zero"<<endl;
  else
    cout<<"a is zero"<<endl;
if((a>b)&&(c<d))
        cout<<"Logical AND is true"<<endl;
  else
       cout<<"Logical AND is false"<<endl;
  if((a<c)||(b<d))
     cout<<"Logical OR is true"<<endl;
 else
     cout<<"Logical OR is false"<<endl;}

Number of Nodes Statements


n0 int a=10, b=8,c=12,d=14;
n1 !(a==0)
n2 cout<<"a is not zero"
n3 cout<<"a is zero"
n4 ((a>b)&&(c<d))
n5 cout<<"Logical AND is true"
n6 cout<<"Logical AND is false"
n7 ((a<c)||(b<d))
n8 cout<<"Logical OR is true"
n9 cout<<"Logical OR is false"
Control
T Flow Graph

a=10, b=8,c=12,d=14
n0
!
n1 (a==0)
T F
a is not zero a is zero
n2 n3

((a>b)&&(c<d) n4
)
T F
Logical AND is true n5 n6 Logical AND is false

n7 ((a<c)||
(b<d))
T F

Logical OR is true n8 n9 Logical OR is false

Test Cases:
Statement Coverage:
Test Cases Input Expected Actual
1 a=10, b=8, a is not zero a is not zero
c=12,d=14 Logical AND is true Logical AND is true
Logical OR is true Logical OR is true

2 a=0, b=4, a is zero a is zero


c=16,d=20 Logical AND is false Logical AND is false
Logical OR is true Logical OR is true

Conditional Coverage:
FOR LOGICAL AND
Test Cases Input Expected Actual

1 a>b c<d Logical AND false Logical And false.


T F
2 a>b c<d Logical AND false Logical And false.
F T
3 a>b c<d Logical AND false Logical And True.
F F
4 a>b c<d Logical AND True Logical And True.
T T

FOR LOGICAL OR
Test Cases Input Expected Actual

1 a<c b<d Logical OR false Logical OR false.


T F
2 a<c b<d Logical OR true Logical OR true
F T
3 a<c b<d Logical OR true Logical OR true.
F F
4 a<c b<d Logical OR true Logical OR true
T T

You might also like