Software Testing Lab File
Software Testing Lab File
DELHI-42
SOFTWARE TESTING
Subject Code: SE302
Laboratory File
AIM:
Generate Test Case Matrix for the given code sample (Finding minimum in an Array).
CODE
TEST CASE MATRIX
TC SIZE INPUT ARRAY EXPECTED OBSERVED MATCH
OUTPUT OUTPUT
4 2 2,3 2 2 YES
5 1 2 2 2 YES
6 1 -2 -2 -2 YES
7 3 -1,-2,-3 -3 -3 YES
8 4 1, 2, 3, 4040404044 1 -1 NO
11 5 9,3,1,3,1 1 1 YES
12 5 -1,2,3,4,5 -1 -1 YES
14 6 0,0,0,0,0,0 0 0 YES
15 10 -1,-2,-3,-4,-5,-6,-7,-8,-9,10 -9 -9 YES
16 11 11,10,9,8,7,6,5,4,3,2,1 1 1 YES
19 6 99,100,98,99,97,100 97 97 YES
20 7 7,7,7,7,7,7,0 0 0 YES
OUTPUT
The Test cases were generated for the given sample code and bugs were found out in the
given sample code.
EXPERIMENT - 1
AIM:
Write a program to find the maximum in three numbers input by the user and generate
test cases for the program using Boundary Value Analysis.
SOURCE CODE
#include<iostream>
#include<vector>
using namespace std;
int main()
{
vector<vector<long int>> range(3,vector<long int>(0,0));
for(int i=1;i<=3;i++)
{
cout<<"Enter Min Range of Variable "<<i<<" :"<<endl;
long int minV, maxV, nom;
cin>>minV;
range[i-1].push_back(minV);
range[i-1].push_back(minV+1);
cout<<"Enter Max Range of Variable "<<i<<" :"<<endl;
cin>>maxV;
nom=minV+ (maxV-minV)/2;
range[i-1].push_back(nom);
range[i-1].push_back(maxV-1);
range[i-1].push_back(maxV);
}
OUTPUT
CONCLUSION
The Boundary Value Analysis was performed by generating Test cases based on the
ranges of the values entered by the user.
EXPERIMENT - 2(a)
AIM:
Write a program to find the maximum in three numbers input by the user and generate
test cases for the program using Boundary Value Analysis.
SOURCE CODE
#include<iostream>
#include<vector>
using namespace std;
int main()
{
vector<vector<long int>> range(3,vector<long int>(0,0));
for(int i=1;i<=3;i++)
{
cout<<"Enter Min Range of Variable "<<i<<" :"<<endl;
long int minV, maxV, nom;
cin>>minV;
range[i-1].push_back(minV);
range[i-1].push_back(minV+1);
cout<<"Enter Max Range of Variable "<<i<<" :"<<endl;
cin>>maxV;
nom=minV+ (maxV-minV)/2;
range[i-1].push_back(nom);
range[i-1].push_back(maxV-1);
range[i-1].push_back(maxV);
}
OUTPUT
CONCLUSION
The Boundary Value Analysis was performed by generating Test cases based on the
ranges of the values entered by the user.
EXPERIMENT - 2(b)
AIM:
Write a program to find the maximum in three numbers input by the user and generate
test cases for the program using Robust Approach.
THEORY:
Robustness is defined as the degree to which a system operates correctly in the presence
of exceptional inputs or stressful environmental conditions. In Robustness Testing out of
range values are also tested for the input test cases. In addition to the Boundary Value
Analysis test cases ,just above maximum and just below minimum are also tested . The
single fault assumption theory is valid in robustness testing.
SOURCE CODE
#include<iostream>
#include<vector>
using namespace std;
cout<<i+1<<"\t"<<range[0][i]<<"\t"<<range[1][2]<<"\t"<<rang
e[
2][2]<<"\t\t"<<max(max(range[0][i],range[1][2]),range[2][2]
)< <endl;
for(int i=0,count=8;i<7;i++)
if(i!=2)
cout<<count++<<"\t"<<range[0][2]<<"\t"<<range[1][i]<<"\t"<<
ra
nge[2][2]<<"\t\t"<<max(max(range[0][2],range[1][i]),range[2
][ 2])<<endl;
for(int i=0,count=14;i<7;i++)
if(i!=2)
cout<<count++<<"\t"<<range[0][2]<<"\t"<<range[1][2]<<"\t"<<
ra
nge[2][i]<<"\t\t"<<max(max(range[0][2],range[1][2]),range[2
][ i])<<endl;
int main()
{
int n=3;
range2[i-1].push_back(nom);
range2[i-1].push_back(maxV-1);
range2[i-1].push_back(maxV);
range2[i-1].push_back(maxV+1);
}
int x,y,z;
cout<<"\nEnter the three variables:";
cin>>x>>y>>z;
cout<<"The max is: "<<max(max(x,y),z)<<endl;
Robust(range2);
return 0;
}
OUTPUT
CONCLUSION
Robustness Testing was performed by generating Test cases based on the ranges of the
values entered by the user.
EXPERIMENT - 2(c)
AIM:
Write a program to find the maximum in three number input by the user and
generate test cases for the program using Worst Value Analysis.
THEORY:
Worst-Case boundary value analysis is a Black Box software testing
technique. In Worst case value testing, we make all combinations of each
value of one variable with each value of another variable.
The single fault assumption theory is rejected in worst case testing therefore
more than 1 variable is allowed to reach their extreme values.All combinations
are tested. The number of test cases are = 5n where n is the number of variables
SOURCE CODE
#include<iostream>
#include<vector>
using namespace std;
int count=1;
for(int i=0;i<5;i++)
{
for(int j=0;j<5;j++)
{
for(int k=0;k<5;k++)
{
cout<<count++<<"\t\t"<<range[0][i]<<"\t\t"<<range[1][j]
<<"\t\
t"<<range[2][k]<<"\t\t"<<max(max(range[0][i],range[1][j
]),ran ge[2][k])<<endl;
}
}
}
}
int main()
{
int n=3;
vector< vector<long int> >
range(n,vector<long int>(0,0)); // for BVA
for(int i=1;i<=3;i++)
{
cout<<"Enter Min Range of Variable
"<<i<<" :"; long int minV, maxV, nom;
cin>>minV;
range[i-1].push_back(minV);
range[i-1].push_back(minV+1);
cout<<"Enter Max Range of Variable
"<<i<<" :"; cin>>maxV;
nom=minV+ (maxV-minV)/2;
range[i-1].push_back(nom);
range[i-1].push_back(maxV-1);
range[i-1].push_back(maxV);
}
cout<<"Input the 3 variables:";
int x,y,z;
cin>>x>>y>>z;
cout<<"Maximum of the 3
is:"<<max(x,max(y,z))<<endl; Worst(range);
return 0;
}
OUTPUT
CONCLUSION
Worst Case Testing was performed by generating Test cases based on the ranges
of the values entered by the user.
EXPERIMENT - 2(d)
AIM:
Write a program to generate test cases for Robust Worst Case Testing.
THEORY:
Robust Worst-Case boundary value analysis is a Black Box software testing technique. In
Robust Worst case testing, we make all combinations of each value of one variable with
each value of another variable.
The single fault assumption theory is rejected in robust worst case testing
therefore more than 1 variable is allowed to reach their extreme values.All
combinations are tested.
The number of test cases are = 7n where n is the number of variables
SOURCE CODE
#include<iostream>
#include<vector>
using namespace std;
int count=1;
for(int i=0;i<5;i++)
{
for(int j=0;j<5;j++)
{
for(int k=0;k<5;k++)
{
cout<<count++<<"\t\t"<<range[0][i]<<"\t\t"<<range[1][j]<<"\
t\t"<<rang
e[2][k]<<"\t\t"<<max(max(range[0][i],range[1][j]),range[2][
k])<<endl; }
}
}
}
int main()
{
int n=3;
vector< vector<long int> > range(n,vector<long
int>(0,0)); // for BVA
for(int i=1;i<=3;i++)
{
cout<<"Enter Min Range of Variable "<<i<<" :";
long int minV, maxV, nom;
cin>>minV;
range[i-1].push_back(minV);
range[i-1].push_back(minV+1);
cout<<"Enter Max Range of Variable "<<i<<" :";
cin>>maxV;
nom=minV+ (maxV-minV)/2;
range[i-1].push_back(nom);
range[i-1].push_back(maxV-1);
range[i-1].push_back(maxV);
}
cout<<"Input the 3 variables:";
int x,y,z;
cin>>x>>y>>z;
cout<<"Maximum of the 3
is:"<<max(x,max(y,z))<<endl; Worst(range);
return 0;
OUTPUT
CONCLUSION
Robust Worst Case Testing was performed by generating Test cases based on the ranges
of the values entered by the user.
EXPERIMENT - 3
AIM:
Write a program to generate test cases using Equivalence Class Testing
THEORY:
A large number of test cases are generated for any program. It is neither feasible nor
desirable to execute all such test cases. We want to select a few test cases and still wish to
achieve a reasonable level of coverage. Many test cases do not test any new thing and
they just execute the same lines of source code again and again. We may divide input
domain into various categories with some relationship and expect that every test case
from a category exhibits the same behaviour. If categories are well selected, we may
assume that if one representative test case works correctly, others may also give the same
results. This assumption allows us to select exactly one test case from each category and
if there are four categories, four test cases may be selected. Each category is called an
equivalence class and this type of testing is known as equivalence class testing.
The entire input domain can be divided into at least two equivalence classes: one
containing all valid inputs and the other containing all invalid inputs. Each equivalence
class can further be sub-divided into equivalence classes on which the program is
required to behave differently.
SOURCE CODE
#include<iostream>
#include<vector>
using namespace std;
vector< vector<int> > ranges(3,vector<int>(3,0));
string inputClass[27], outputClass[2];
void testCase(int i,int j, int k)
{ int a=ranges[0][i];
int b=ranges[1][j];
int c=ranges[2][k];
if(i==0 || i==2 || j==0 || j==2 || k==0 || k==2)
{ cout<<"\t"<<a<<"\t|\t"<<b<<"\t|\t"<<c<<"\t| Input out of
Range"<<endl;
return;
}
cout<<"\t"<<a<<"\t|\t"<<b<<"\t|\t"<<c<<"\t|
"<<max(a,max(b,c))<<endl;
}
void generateClasses()
{
inputClass[0] = "{All inputs valid: xmin<=x<=xmax &&
ymin<=y<=ymax && zmin<=z<=zmax}";
inputClass[1] = "{x invalid, y,z valid: x<xmin &&
ymin<=y<=ymax && zmin<=z<=zmax}";
inputClass[2] = "{x invalid, y,z valid: x>max &&
ymin<=y<=ymax && zmin<=z<=zmax}";
inputClass[3] = "{y invalid, x,z valid: xmin<=x<=xmax &&
y<ymin && zmin<=z<=zmax}";
inputClass[4] = "{y invalid, x,z valid: xmin<=x<=xmax &&
y>ymax && zmin<=z<=zmax}";
inputClass[5] = "{z invalid, x,y valid: xmin<=x<=xmax &&
ymin<=y<=ymax && z<zmin }";
inputClass[6] = "{z invalid, x,y valid: xmin<=x<=xmax &&
ymin<=y<=ymax && z>zmax }";
inputClass[7] = "{x,y invalid, z valid: x<xmin && y<ymin
&& zmin<=z<=zmax}";
inputClass[8] = "{x,y invalid, z valid: x<xmin && y>ymax
&& zmin<=z<=zmax}";
inputClass[9] = "{x,y invalid, z valid: x>xmax && y<ymin
&& zmin<=z<=zmax}";
inputClass[10]= "{x,y invalid, z valid: x>xmax && y>ymax
&& zmin<=z<=zmax}";
inputClass[11]= "{y,z invalid, x valid: xmin<=x<=xmax &&
y<ymin && z<zmin }";
inputClass[12]= "{y,z invalid, x valid: xmin<=x<=xmax &&
y<ymin && z>zmax }";
inputClass[13]= "{y,z invalid, x valid: xmin<=x<=xmax &&
y>ymax && z<zmin }";
inputClass[14]= "{y,z invalid, x valid: xmin<=x<=xmax &&
y>ymax && z>zmax }";
inputClass[15]= "{x,z invalid, y valid: x<xmin &&
ymin<=y<=ymax && z<zmin }";
inputClass[16]= "{x,z invalid, y valid: x<xmin &&
ymin<=y<=ymax && z>zmax }";
inputClass[17]= "{x,z invalid, y valid: x>xmax &&
ymin<=y<=ymax && z<zmin }";
inputClass[18]= "{x,z invalid, y valid: x>xmax &&
ymin<=y<=ymax && z>zmax }";
inputClass[19]= "{ x , y , z invalid: x<xmin && y<ymin
&& z<zmin }";
inputClass[20]= "{ x , y , z invalid: x<xmin && y<ymin
&& z>zmax }";
inputClass[21]= "{ x , y , z invalid: x<xmin && y>ymax
&& z<zmin }";
inputClass[22]= "{ x , y , z invalid: x<xmin && y>ymax
&& z>zmax }";
inputClass[23]= "{ x , y , z invalid: x>xmax && y<ymin
&& z<zmin }";
inputClass[24]= "{ x , y , z invalid: x>xmax && y<ymin
&& z>zmax }";
inputClass[25]= "{ x , y , z invalid: x>xmax && y>ymax
&& z<zmin }";
inputClass[26]= "{ x , y , z invalid: x>xmax && y>ymax
&& z>zmax }";
int i=0;
cout<<"\nInput Classes...";
for(i=0;i<27;i++)
cout<<"\nI"<<i<<": "<<inputClass[i];
cout<<"\n\nOutput Classes...";
for(i=0;i<2;i++)
cout<<"\nO"<<i<<": "<<outputClass[i];
}
// To determine test cases in equivalenceTesting
void equivalenceTesting(int min[3], int max[3]) {
int expOut[24], testCases[24][3], i=0, x=0, y=0,
z=0; generateClasses();
cout<<"\n\nTest Cases...";
cout<<"\n+";
for(int i=0;i<71;i++)
cout<<"-"; cout<<"+";
//cout<<"\n|\t\t Input\t\t\t| Expected\t\t|";
cout<<"\n|Test Cases\ta\t\tb\t\tc\t|
Output\t\t|"; cout<<"\n+";
for(int i=0;i<76;i++)
cout<<"-";
cout<<"+\n";
cout<<"\n Input Cases.............\n";
// INput Test Cases
for(int i=0;i<3;i++) // 3 cases of x
{
for(int j=0;j<3;j++) // 3 cases of y {
for(int k=0;k<3;k++) // 3 cases of z {
int tc=i*3*3 + j*3 + k+1;
cout<<"\t"<<tc<<"|";
testCase(i,j,k);
}
}
}
cout<<"\n Output Cases.............\n";
for(int i=0;i<2;i++) // 3 cases of x
{ cout<<"\t"<<28+i<<"|";
testCase(0+i,0+i,0+i);
}
}
int main()
{ int min[3], max[3];
for(int i=0;i<3;i++)
{ cout<<"Enter min & max value of vertex "<<i+1<<" : ";
cin>>min[i]>>max[i];
ranges[i][0]=min[i]-1;
ranges[i][1]=(min[i]+max[i])/2+(i==0?0:i==1?20:-10);
ranges[i][2]=max[i]+1;
}
equivalenceTesting(min,max);
return 0;
}
OUTPUT
CONCLUSION
Equivalence Class Testing was performed by generating test cases based on the
ranges of the values entered by the user.
EXPERIMENT - 5
AIM:
Write a program to generate test cases (for types of triangle) using Decision Table
Testing.
THEORY:
An output may be dependent on many input conditions and decision tables give a
pictorial view of various combinations of input conditions. There are four portions of the
decision table The decision table provides a set of conditions and their corresponding
actions.
1. Condition Stubs
All the conditions are represented in this upper left section of the decision table.
These conditions are used to determine a particular action or set of actions.
2. Condition Entries
In the condition entries portion of the decision table, we have a number of
columns and each column represents a rule. Values entered in this upper right
portion of the table are known as inputs.
3. Action Stubs
All possible actions are listed in this lower left portion of the decision table.
4. Action Entries
Each entry in the action entries portion has some associated action or set of
actions in this lower right portion of the table. These values are known as outputs
and are dependent upon the functionality of the program.
SOURCE CODE
#include <iostream>
#include<vector>
using namespace std;
vector<vector<int> >sides(7,vector<int>(3,0));
int a, b, c;
string result(int a, int b, int c, vector<vector<int>
>arr) { string ans = "Not a Triangle";
if (a < arr[0][0] || a > arr[0][1] || b < arr[1][0] ||
b > arr[1][1] || c < arr[2][0] || c > arr[2][1]) {
ans = "Input values are out of range";
}
else if (a < b + c && b < a + c && c < a +
b) { if (a == b && b == c) {
ans = "Equilateral Triangle";
}
else if (a == b || b == c || a == c) {
ans = "Isosceles Triangle";
}
else {
ans = "Scalene Triangle";
}
}
return ans;
}
string Build_DT() {
cout<<"\nDECISION TABLE FOR TRIANGLE CLASSIFICATION
PROBLEM"<<endl;
string str = "
--------------------------------------------------------------
--\n"; str = str + " Decisions | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10| 11|\n";
str = str + "
--------------------------------------------------------------
--\n"; str = str + " C1: a < b + c? | F | T | T | T | T | T |
T | T | T | T | T |\n";
str = str + " C2: b < a + c? | - | F | T | T | T | T | T | T
| T | T | T |\n";
str = str + " C3: c < a + b? | - | - | F | T | T | T | T | T
| T | T | T |\n";
str = str + " C4: a = b ? | - | - | - | T | F | T | F | T | T
| F | F |\n";
str = str + " C5: a = c ? | - | - | - | T | F | F | T | T | F
| T | F |\n";
str = str + " C6: b = c ? | - | - | - | T | T | F | F | F | T
| T | F |\n";
str = str + "
--------------------------------------------------------------
--\n"; str = str + " Rule count |32 |16 | 8 | 1 | 1 | 1 | 1 |
1 | 1 | 1 | 1 |\n";
str = str + "
----------------------------------------------------------------
\n";
str = str + " A1: Not a triangle | X | X | X | | | | | | |
| |\n";
str = str + " A2: Scalene | | | | | | | | | | | X |\n";
str = str + " A3: Isosceles | | | | | X | X | X | | | |
|\n";
str = str + " A4: Equilateral | | | | X | | | | | | | |\n";
str = str + " A5: Impossible | | | | | | | | X | X | X |
|\n";
return str;
}
a = arr[0][1];
b = arr[1][2];
c = arr[2][2];
while (a < (b + c)) {
b = b / 2;
c = c / 2;
}
sides[0][0] = a;
sides[0][1] = b;
sides[0][2] = c;
ind++;
a = arr[0][2];
b = arr[1][1];
c = arr[2][2];
while (b < (a + c)) {
a = a / 2;
c = c / 2;
}
sides[1][0] = a;
sides[1][1] = b;
sides[1][2] = c;
ind++;
a = arr[0][2];
b = arr[1][2];
c = arr[2][1];
int main() {
vector<vector<int> >arr(3,vector<int>(3,0));
cout<< "Enter the sides of the Triangle:"<<endl;
CONCLUSION
Decision Table Testing for Triangle Classification Program was successfully
implemented.
EXPERIMENT - 6
AIM:
Write a program to find Cyclomatic complexity of a program(triangle
classification) .
THEORY:
Cyclomatic Complexity is the number of independent paths through a
program. To calculate cyclomatic complexity.
(V(G) = e – n + 2P
G : program graph
n : number of nodes
e : number of edges
SOURCE CODE
#include<iostream>
#include<string>
using namespace std;
int main()
{
string str=
"#include<stdio.h>;\n#include<conio.h>;\n#include<math.h>;\n1.
void main() //Main Begins\n2. {\n3. double a,b,c;\n4. double
a1,a2,a3;\n5. int valid=0;\n6. clrscr();\n7. printf("Enter
first side of the triangle:"); /*Enter the sides of
Triangle*/\n8. scanf("%lf",&a);\n9.
printf("Enter second side of the triangle:");\n10.
scanf("%lf",&b);\n11. printf("Enter third
side of the triangle:");\n12.
scanf("%lf",&c);\n/*Checks whether a triangle is
valid or not*/\n13.
if(a>0&&a<=100&&b>0&&b<=100&
amp;& amp;c>0&&am
p;c<=100) {\n14.
if((a+b)>c&&(b+c)>a&&(c+a)>b) {\n15.
valid=1;\n16. }\n17. else {\n18. valid=-1;\n19. }\n20. }\n21.
if(valid==1) {\n22. a1=(a*a+b*b)/(c*c);\n23.
a2=(b*b+c*c)/(a*a);\n24. a3=(c*c+a*a)/(b*b);\n25.
if(a1<1||a2<1||a3<1) {\n26. printf("Obtuse angled
triangle");\n27. }\n28. else if(a1==1||a2==1||a3==1) {\n29.
printf("Right angled triangle");\n30. }\n31. else
{\n32. printf("Acute angled triangle");\n33. }\n34.
}\n35. else if(valid==-1) {\n36. printf("\nInvalid
Triangle");\n37. }\n38. else {\n39. printf("\nInput
Values are Out of Range");\n40. }\n41. getch();\n42. }
//Main Ends";
int e=0;
int p=1;
int n=0;
for(int i=0;i<str.length()-1;i++)
{
if(str[i]=='\n')
{ e++;
n++;
continue;
}
string check="";
check+=str[i];
check+=str[i+1];
if(check=="if")
e++;
}
e--;
cout<<endl<<str<<endl<<"----------------------------------------
----- -----------------\nCyclomatic Complexity
is:"<<(e-n)+2*p<<endl; return 0;
}
OUTPUT
CONCLUSION
Cyclomatic complexity program for Triangle Classification Program was
successfully implemented.
EXPERIMENT - 7
AIM:
Write a program to input graph matrix and perform DD path testing(triangle
classification).
THEORY:
SOURCE CODE
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
class Edge{
public:
int wt;
int v;
Edge(int nb,int w)
{
v=nb;
wt=w;
}
};
dfs_printPaths(graph,e->v,vis,endNode,count,path+"N"+to_string(
src)+" -> ");
}
vis[src]=false;
cout<<endl<<endl;
}
int main()
{
cout<<"\n\n----------------------------------------------------
------
---------------------------------------------------------------
------ ----------------------------------------\n\n\t\t\t\tDD
Path Testing \n\n";
cout<<"Enter the numbe of Decicion nodes(Size of
Matrix):"; int n;
cin>> n;
cout<<"Plese input the graph matrix:\n";
vector<vector<int> > mat(n,vector<int> (n,0));
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
cin>>mat[i][j];
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
if(mat[i][j]==1)
{ graph[i].push_back(new Edge(j,1));
e++;
}
display_graph(graph);
vector<bool> vis(n,false);
int count=1;
cout<<"--------------------------------------------------------
------
---------------------------------------------------------------
------
--------------------------------------------------------\n";
cout<<"Cyclomatic Complexity is: "<<e-n+2*P<<endl;
cout<<"--------------------------------------------------------
------
---------------------------------------------------------------
------
--------------------------------------------------------\n";
cout<<"\nPaths are:\n";
cout<<"--------------------------------------------------------
------
---------------------------------------------------------------
------
--------------------------------------------------------\n\n";
dfs_printPaths(graph,0,vis,41,count,"");
cout<<endl;
return 0;
}
INPUT
42
0 1 0 00000000000000000000000000000000000
0 0 0 00010000000000000000000000000000000
0 0 0 00000000100000000000000000000000000
0 0 0 00000000000001000000000000000000000
0 0 0 00000000000000000010000000000000000
00000000000000000000000000100000000000
00000000000000000000000000000001000000
00000000000000000000000000000000000010
00000000000000000000000000000000000000
00010000000000000000000000000000000000
00000000100000000000000000000000000000
00000000000001000000000000000000000000
00000000000000000010000000000000000000
00000000000000000000000100000010000000
00000000000000000000000000001010000000
00000000000000000000000000000000010000
00000000000000000000000000000000000000
00010000000000000000000000000000000000
000001000000000000000000000000
00000000000000000010000000000000000000
00000000000000000000000100000000000000
00000000000000000000000000001000000000
00000000000000000000000000000000010000
00000000100000000000000000000000000000
10000000000000000000000000000000000000
00000100000000000000000000000000000000
00000000001000000000000000000000000000
00000000000000010100000000000000000000
00000000000000000000100000000000000000
00000000000000000000000000000001000000
00000000000000000000000000000010100000
00000000000000000000000000000000000100
00000000000000000000000000000000000000
00000100000000000000000000000000000000
00000001000000000000000000000000000000
00000000000010000000000000000000000000
00000000000000000100000000000000000000
00000000000000000000000000001000000000
00000000000000000000000000010100000000
00000000000000000000000000000000100000
00000000000000000000000000000000000000
00100000000000000000000000000000000000
00001000000000000000000000000000000000
00000000010000000000000000000000000000
00000000000000100000000000000000000000
00000000000000000001000000000000000000
000000000000000000000000
OUTPUT
CONCLUSION
DD path testing for Triangle Classification Program was successfully implemented.
EXPERIMENT - 8
AIM:
Write a program to perform an experiment on Mutation Testing.
THEORY:
Mutation testing is a popular technique to assess the effectiveness of a test suite. We may
have a large number of test cases for any program. We neither have time nor resources to
execute all of them. We may select a few test cases using any testing technique and
prepare a test suite. Mutation testing may help us to assess the effectiveness of a test suite
and may also enhance the test suite, if it is not adequate for a program.
The process of changing a program is known as mutation. This change may be limited to
one, two or very few changes in the program. We prepare a copy of the program under
test and make a change in a statement of the program. This changed version of the
program is known as a mutant of the original program. The behaviour of the mutant may
be different from the original program due to the introduction of a change.
The total number of mutants is equal to the number of killed mutants plus the number of
live mutants. The mutation score measures how sensitive the program is to the changes
and how accurate the test suite is. A mutation score is always between 0 and 1. A higher
value of mutation score indicates the effectiveness of the test suite although effectiveness
also depends on the types of faults that the mutation operators are designed to represent.
The purpose of mutation testing is not only to assess the capability of a test suite but also
to enhance the test suite.
SOURCE CODE
#include<iostream>
#include<vector>
using namespace std;
int killed=0;
int correct(vector<int> testCase)
{ int A=testCase[0];
int B=testCase[1];
int C=testCase[2];
if(A>B)
if(A>C)
return A ;
else
return C;
else
if(C>B)
return C;
else
return B;
return 0;
}
int M1_Code(vector<int>
testCase) {
int A=testCase[0];
int B=testCase[1];
int C=testCase[2];
if(A<B) // > changed to <
if(A>C)
return A ;
else
return C;
else
if(C>B)
return C;
else
return B;
return 0;
}
int M2_Code(vector<int>
testCase) { int
A=testCase[0];
int B=testCase[1];
int C=testCase[2];
if(A>(B+C)) // A>B changed to
A>(B+C) if(A>C)
return A ;
else
return C;
else
if(C>B)
return C;
else
return B;
return 0;
}
int M3_Code(vector<int>
testCase) {
int A=testCase[0];
int B=testCase[1];
int C=testCase[2];
if(A>B)
if(A<C) // > changed to <
return A ;
else
return C;
else
if(C>B)
return C;
else
return B;
return 0;
}
int M4_Code(vector<int> testCase)
{ int A=testCase[0];
int B=testCase[1];
int C=testCase[2];
if(A>B)
if(A>C)
return A ;
else
return C;
else
if(C=B)// C>B changed to C=B
return C;
else
return B;
return 0;
}
int M5_Code(vector<int> testCase)
{ int A=testCase[0];
int B=testCase[1];
int C=testCase[2];
if(A>B)
if(A>C)
return A ;
else
return C;
else
if(C>B)
return B; // Largest is B instead of C
else
return B;
return 0;
}
void M1(vector<vector< int> > testCases)
{
cout<<endl<<endl<<"---------------------------------------------------
---- --------------------------\n";
cout<<" Mutant 1"<<endl; cout<<"\t\t
A\tB\tC\tExpected\t Actual"<<endl;
bool flag=false;
for(int i=0;i<testCases.size();i++)
{ cout<<"Test Case "<<i+1<<" \t
"<<testCases[i][0]<<"\t"<<testCases[i][1]<<"\t"<<testCases[i][2]<<"\t
"<<co rrect(testCases[i])<<"\t\t"<<M1_Code(testCases[i])<<endl;
if(correct(testCases[i])!=M1_Code(testCases[i]) && flag==false) {
killed++;
flag=true;
}
}
if(flag==true)
cout<<endl<<"Mutant Killed";
else cout<<endl<<"Mutant not Killed";
}
cout<<endl<<endl<<"---------------------------------------------------
---- --------------------------\n";
cout<<" Mutant 3"<<endl; cout<<"\t\t
A\tB\tC\tExpected\t Actual"<<endl;
bool flag=false;
for(int i=0;i<testCases.size();i++)
{ cout<<"Test Case "<<i+1<<" \t
"<<testCases[i][0]<<"\t"<<testCases[i][1]<<"\t"<<testCases[i][2]<<"\t
"<<co rrect(testCases[i])<<"\t\t"<<M3_Code(testCases[i])<<endl;
if(correct(testCases[i])!=M3_Code(testCases[i]) && flag==false) {
killed++;
flag=true;
}
}
if(flag==true)
cout<<endl<<"Mutant Killed";
else cout<<endl<<"Mutant not Killed";
}
cout<<endl<<endl<<"---------------------------------------------------
---- --------------------------\n";
cout<<" Mutant 4"<<endl; cout<<"\t\t
A\tB\tC\tExpected\t Actual"<<endl;
bool flag=false;
for(int i=0;i<testCases.size();i++)
{ cout<<"Test Case "<<i+1<<" \t
"<<testCases[i][0]<<"\t"<<testCases[i][1]<<"\t"<<testCases[i][2]<<"\t
"<<co rrect(testCases[i])<<"\t\t"<<M4_Code(testCases[i])<<endl;
if(correct(testCases[i])!=M4_Code(testCases[i]) && flag==false) {
killed++;
flag=true;}}
if(flag==true)
cout<<endl<<"Mutant Killed";
else cout<<endl<<"Mutant not Killed";
}
void M5(vector<vector< int> > testCases)
{cout<<endl<<endl<<"--------------------------------------------------
----- --------------------------\n";
cout<<" Mutant 5"<<endl; cout<<"\t\t
A\tB\tC\tExpected\t Actual"<<endl;
bool flag=false;
for(int i=0;i<testCases.size();i++)
{ cout<<"Test Case "<<i+1<<" \t
"<<testCases[i][0]<<"\t"<<testCases[i][1]<<"\t"<<testCases[i][2]<<"\t
"<<co rrect(testCases[i])<<"\t\t"<<M5_Code(testCases[i])<<endl;
if(correct(testCases[i])!=M5_Code(testCases[i]) && flag==false) {
killed++;
flag=true; }}
if(flag==true)
cout<<endl<<"Mutant Killed";
else cout<<endl<<"Mutant not Killed";
}
int main()
{
cout<<endl<<endl<<"---------------------------------------------------
---- --------------------------\n";
cout<<" MUTATION TESTING"<<endl; cout<<"Enter number of
test cases:";
int N;
cin>>N;
vector<vector<int> > testCases(N,vector<int> (3,0));
for(int i=0;i<N;i++)
{
cout<<"Enter test case "<<i+1<<" : ";
cin>>testCases[i][0]>>testCases[i][1]>>testCases[i][2]; }
M1(testCases);
M2(testCases);
M3(testCases);
M4(testCases);
M5(testCases);
cout<<endl<<endl<<"---------------------------------------------------
---- --------------------------\n";
cout<<" MUTATION SCORE "<<endl;
cout<<"Total Mutants :"<<5<<endl;
cout<<"Mutants Killed :"<<killed<<endl;
cout<<"Mutation Score :"<<killed/5.0<<endl;
return 0;
}
OUTPUT
CONCLUSION
Mutation Testing for Largest of 3 Numbers Program was successfully done.
EXPERIMENT - 9
AIM:
Write a program to generate test cases using cause effect graph
THEORY:
This technique is effective only for small programs because, as the size of the program
increases, the number of causes and effects also increases and thus complexity of the
cause effect graph increases. For large-sized programs, a tool may help us to design the
cause-effect graph with the minimum possible complexity.
It has very limited applications in unit testing and hardly any application in integration
testing and system testing.
SOURCE CODE
#include<iostream>
#include<iomanip>
using namespace std;
string cause[6];
string effect[5];
char causeitionEntries[6][11];
char act[6][11];
void generateCauseAndEffect()
{
cause[0] = "c1: a<b+c?";
cause[1] = "c2: b<c+a?";
cause[2] = "c3: c<a+b?";
cause[3] = "c4: a^2=b^2+c^2";
cause[4] = "c5: a^2>b^2+c^2";
cause[5] = "c6: a^2<b^2+c^2";
effect[0] = "e1: Invalid Triangle";
effect[1] = "e2: Right Angle
Triangle"; effect[2] = "e3: Obtuse
Angled Triangle"; effect[3] = "e4:
Acute Angled Triangle"; effect[4] =
"e5: Impossible";
//generating causeition Entries for
a<b+c? int i=0;
causeitionEntries[0][i]='0';
for(i=1;i<11;i++)
causeitionEntries[0][i]='1';
//for b<c+a?
i=0;
causeitionEntries[1][i]='X';
i=1;
causeitionEntries[1][i]='0';
for(i=2;i<11;i++)
causeitionEntries[1][i]='1';
//for c<a+b?
i=0;
causeitionEntries[2][i]='X';
i=1;
causeitionEntries[2][i]='X';
i=2;
causeitionEntries[2][i]='0';
for(i=3;i<11;i++)
causeitionEntries[2][i]='1';
//for a^2=b^2+c^2
for(i=0;i<3;i++)
causeitionEntries[3][i]='X';
causeitionEntries[3][10]='0';
for(i=3;i<10;i++)
if(i<7)
causeitionEntries[3][i]='1';
else
causeitionEntries[3][i]='0';
//for a^2>b^2+c^2?
for(i=0;i<3;i++)
causeitionEntries[4][i]='X';
for(i=3;i<11;i++)
if(i==3||i==4|| (i>6&&i<9))
causeitionEntries[4][i]='1';
else
causeitionEntries[4][i]='0';
causeitionEntries[4][9]='0';
//for a^2>b^2+c^2
for(i=0;i<3;i++)
causeitionEntries[5][i]='X';
for(i=3;i<11;i++)
if(i==4||i==6)
causeitionEntries[5][i]='0';
else
causeitionEntries[5][i]='1';
causeitionEntries[5][8]='0';
//generating effect Entries
for(i=0;i<5;i++)
for(int j=0;j<11;j++)
act[i][j]=' ';
act[0][0]='1';
act[0][1]='1';
act[0][2]='1';
act[1][6]='1';
act[2][8]='1';
act[3][9]='1';
act[4][3]='1';
act[4][4]='1';
act[4][5]='1';
act[4][7]='1';
act[4][10]='1';
cout<<"\n\t\t\tCAUSE EFFECT GRAPH\n\nDecision
Table...\n"; for(i=0;i<77;i++) cout<<"-"; cout<<"\n";
for(i=0;i<6;i++)
{
cout<<"| "<<setw(30)<<left<<cause[i];
cout<<"| ";
for(int j=0;j<11;j++)
{
cout<<causeitionEntries[i][j]<<" | ";
}
cout<<endl;
}
for(i=0;i<5;i++)
{
cout<<"| "<<setw(30)<<left<<effect[i];
cout<<"| ";
for(int j=0;j<11;j++)
{
cout<<act[i][j]<<" | ";
}
cout<<endl;
}
for(i=0;i<77;i++) cout<<"-"; cout<<"\n";
void decisionTableTesting()
{
}
testCases[i][0]=x;testCases[i][1]=y;testCases[i][2]=z;
}
cout<<"\nTest Cases are: \n";
cout<<"\n"; for(int i=0;i<81;i++) cout<<"-";
cout<<"\n|\t\t Inputs\t\t\t\t|";
cout<<setw(30)<<left<<"\tExpected Output \t|"<<endl;
//
cout<<"---------------------------------------------------------------
---- --------------\n";
cout<<"|\tA\t\tB\t\tC \t|\t\t\t\t|\n";
for(int i=0;i<81;i++) cout<<"-"; cout<<"\n";
for(int i=0;i<6;i++)
{
for(int j=0;j<3;j++)
{
if(j==0) cout<<"|";
cout<<"\t"<<testCases[i][j]<<"\t|";
}
if(i<3){
cout<<setw(30)<<left<<effect[0]<<endl;
}
else{
cout<<setw(30)<<left<<effect[i-2]<<endl;
}
// cout<<"\t|"<<endl;
}
for(int i=0;i<81;i++) cout<<"-";
cout<<"\n Total No. of Test Cases = 6";
}
int main()
{
decisionTableTesting();
return 0;
}
OUTPUT
CONCLUSION
The test cases were generated using the causes effect technique.
EXPERIMENT - 10
AIM:
Execute static analysis tool cppcheck.
THEORY:
Cppcheck is a static code analysis tool for the C and C++ programming languages. It is a
versatile tool that can check non-standard code. it does not detect syntax errors in the
code. Cppcheck primarily detects the types of bugs that the compilers normally do not
detect. The goal is to detect only real errors in the code (i.e. have zero false positives).
SOURCE CODE
#include<iostream>
#include<vector>
using namespace std;
int main()
{
int a[5]={1,2,3,4,5,6};
a[7]=100;
cout<<a[2]/(a[0]-1);
int b;
string s="abc";
cout<<s[100];
int x =s;
int *y =s;
string str=123;
cout<<b<<endl;
return 0;
}
OUTPUT
Terminal Command executed :cppcheck exp10.cpp
CONCLUSION
Cppcheck Analysis Tool was successfully executed.
EXPERIMENT - 11
AIM:
Write a program for generating control flow graph and DD path graph and
generate graph matrix.
THEORY:
A graph matrix is a square matrix with one row and one column for every node of the
graph. The size of the matrix (number of rows and number of columns) is the number of
nodes of the graph.The graphs are commonly used in testing to find independent paths.
Cyclomatic complexity also gives us the number of independent paths in any graph.
When the size of the graph increases, it becomes difficult to identify those paths
manually. We may do so with the help of a software tool and graph matrices may become
the basis for designing such a tool.
SOURCE CODE
#include<iostream>
#include<fstream>
#include<stack>
#include<queue>
using namespace std;
class Node {
public:
int num;
static int node_count;
vector<Node*> next;
static Node* create_new_node(){
Node* new_node = new Node();
new_node->num = Node::node_count++;
return new_node;
}
};
int Node::node_count = 1;
class Stack_Node{
public:
Node* ptr;
int type;
Stack_Node(){
this->ptr = NULL;
this->type = NOTYPE;
}
Stack_Node(Node* ptr, int type){
this->ptr = ptr;
this->type = type;
}
};
stack<Stack_Node> mStack;
class Graph {
public:
Node* head;
void printGraph(){
queue<Node*> q;
q.push(head);
while(!q.empty()){
Node* travel_ptr = q.front();
q.pop();
cout<<travel_ptr->num<<" : ";
for (std::vector<Node*>::iterator
i=travel_ptr->next.begin();i!=travel_ptr->next.end();
++i){ cout<<(*i)->num<<" ";
q.push((*i));
}
cout<<endl;
}
}
};
OUTPUT
CONCLUSION