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

Software Testing Lab File

The document provides details of a pre-lab experiment on software testing conducted at Delhi Technological University. It involves generating a test case matrix for finding the minimum value in an array. The test case matrix contains 20 test cases with inputs of varying array sizes and values. It checks the expected and observed outputs and whether they match.

Uploaded by

Carl Johnson
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
87 views

Software Testing Lab File

The document provides details of a pre-lab experiment on software testing conducted at Delhi Technological University. It involves generating a test case matrix for finding the minimum value in an array. The test case matrix contains 20 test cases with inputs of varying array sizes and values. It checks the expected and observed outputs and whether they match.

Uploaded by

Carl Johnson
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 56

DELHI TECHNOLOGICAL UNIVERSITY,

DELHI-42

SOFTWARE TESTING
Subject Code: SE302

Laboratory File

Submitted to: Submitted by:


Dr. Ruchika Malhotra Aaron Paul Jacob
2K18/SE/003
PRE LAB EXPERIMENT

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

1 0 - Invalid Size Invalid Size Spec. YES


Spec.

2 -1 - Invalid Size Invalid Size Spec. YES


Spec.

3 2.3 2,3 2 7432423(junk) NO

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

9 2 4147483647, 2147483649 2147483649 -1 NO

10 5 -1, 2.4, 3.4, -5, -5 -5 -5 YES

11 5 9,3,1,3,1 1 1 YES

12 5 -1,2,3,4,5 -1 -1 YES

13 5 1.1, 4,5,6,6 1.1 4 NO

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

17 12 1,2,4,5,24,53,34,25,2,-10,-1 -10 -10 YES

18 12 -10,-9,-8,-7,-6,-5,-4,-3,-2,-1 -10 -10 YES


,0, 1

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);
}

cout<<endl<<"TC X Y Z Expected O/P"<<endl; for(int


i=0;i<5;i++)
cout<<i+1<<" "<<range[0][i]<<"
"<<range[1][2]<<" "<<range[2][2]<<"
"<<max(max(range[0][i],range[1][2]),range[2][2])<<endl
; for(int i=0,count=6;i<5;i++)
if(i!=2)
cout<<count++<<" "<<range[0][2]<<"
"<<range[1][i]<<" "<<range[2][2]<<"
"<<max(max(range[0][2],range[1][i]),range[2][2])<<endl
; for(int i=0,count=10;i<5;i++)
if(i!=2)
cout<<count++<<" "<<range[0][2]<<"
"<<range[1][2]<<" "<<range[2][i]<<"
"<<max(max(range[0][2],range[1][2]),range[2][i])<<endl
; return 0;
}

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);
}

cout<<endl<<"TC X Y Z Expected O/P"<<endl; for(int


i=0;i<5;i++)
cout<<i+1<<" "<<range[0][i]<<"
"<<range[1][2]<<" "<<range[2][2]<<"
"<<max(max(range[0][i],range[1][2]),range[2][2])<<endl
; for(int i=0,count=6;i<5;i++)
if(i!=2)
cout<<count++<<" "<<range[0][2]<<"
"<<range[1][i]<<" "<<range[2][2]<<"
"<<max(max(range[0][2],range[1][i]),range[2][2])<<endl
; for(int i=0,count=10;i<5;i++)
if(i!=2)
cout<<count++<<" "<<range[0][2]<<"
"<<range[1][2]<<" "<<range[2][i]<<"
"<<max(max(range[0][2],range[1][2]),range[2][i])<<endl
; return 0;
}

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.

The following values are checked:


1. Below Minimum
2. Minimum
3. Just above Minimum
4. Nominal
5. Just below Maximum
6. Maximum
7. Just above Maximum

SOURCE CODE
#include<iostream>
#include<vector>
using namespace std;

void Robust(vector<vector<long int> >& range)


{
cout<<"\n\n\t ROBUST CASE TESTING\n";
cout<<endl<<"TC\tX\tY\tZ\tExpected
Output\n"<<endl; for(int i=0;i<7;i++)

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;

vector< vector<long int> >


range2(n,vector<long int>(0,0)); // for Robust
for(int i=1;i<=3;i++)
{
cout<<"Enter Min Range of Variable "<<i<<"
:"; long int minV, maxV, nom;
cin>>minV;
range2[i-1].push_back(minV-1);
range2[i-1].push_back(minV);
range2[i-1].push_back(minV+1);
cout<<"Enter Max Range of Variable "<<i<<"
:"; cin>>maxV;
nom=minV+ (maxV-minV)/2;

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

The following combinations for each variable are checked:


1. Minimum
2. Just above Minimum
3. Nominal
4. Just below Maximum
5. Maximum

SOURCE CODE
#include<iostream>
#include<vector>
using namespace std;

void Worst(vector<vector<long int> >& range)


{
cout<<"\n\n\t WORST CASE TESTING\n";
cout<<endl<<"TC\t\tX\t\tY\t\tZ\tExpected
Output\n"<<endl;

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

The following combinations for each variable are checked:


1. Below Minimum
2. Minimum
3. Just above Minimum
4. Nominal
5. Just below Maximum
6. Maximum
7. Just Above Maximum

SOURCE CODE
#include<iostream>
#include<vector>
using namespace std;

void Worst(vector<vector<long int> >& range)


{
cout<<"\n\n\t WORST CASE TESTING\n";
cout<<endl<<"TC\t\tX\t\tY\t\tZ\tExpected
Output\n"<<endl;

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 }";

outputClass[0]= "Greater of x, y, z";


outputClass[1]= "Input out of range";

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.

The four parts of the decision table are given as:

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;
}

int not_triangle(int ind, vector<vector<int> >arr) {

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];

while (c < (a + b)) {


a = a / 2;
b = b / 2;
}
sides[2][0] = a;
sides[2][1] = b;
sides[2][2] = c;
ind++;
return ind;
}

int Equilateral(int ind, vector<vector<int>


>arr) { a = arr[0][3];
b = arr[1][3];
c = arr[2][3];
int min_max = arr[0][0], max_min = arr[0][1],
nominal_val; for (int i = 0; i < 3; i++) {
if (min_max > arr[i][0])
min_max = arr[i][0];
if (max_min > arr[i][1])
max_min = arr[i][1];
}
nominal_val = (min_max + max_min) / 2;
sides[ind][0] = nominal_val;
sides[ind][1] = nominal_val;
sides[ind][2] = nominal_val;
ind++;
return ind;
}

int Isosceles(int ind, vector<vector<int>


>arr) { a = arr[0][3];
b = arr[1][3];
c = arr[2][3];
int min_max = arr[0][0], max_min = arr[0][1],
nominal_val; for (int i = 0; i < 3; i++) {
if (min_max > arr[i][0])
min_max = arr[i][0];
if (max_min > arr[i][1])
max_min = arr[i][1];
}
nominal_val = (min_max + max_min) / 2;
sides[ind][0] = arr[0][0];
sides[ind][1] = nominal_val;
sides[ind][2] = nominal_val;
ind++;
sides[ind][0] = nominal_val;
sides[ind][1] = arr[1][0];
sides[ind][2] = nominal_val;
ind++;
sides[ind][0] = nominal_val;
sides[ind][1] = nominal_val;
sides[ind][2] = arr[2][0];
ind++;
return ind;
}

int impossible(int ind) {


for (int i = 0; i < 3; i++) {
cout << ind + i << "\t?\t?\t?\tImpossible" << endl;
}
ind = ind + 3;
return ind;
}

int main() {

vector<vector<int> >arr(3,vector<int>(3,0));
cout<< "Enter the sides of the Triangle:"<<endl;

for (int i = 0; i < 3; i++) {


cout<<"Enter min and max values of side "<<i + 1<<": ";
cin>>arr[i][0]>>arr[i][1];
arr[i][2] = (arr[i][0] + arr[i][1]) / 2;
arr[i][3] = arr[i][1] - arr[i][0];
}

cout << Build_DT() << endl;


cout<<"DECISION TABLE - TEST CASES"<<endl;
cout << "S.No\ta\tb\tc\tExpected Output" <<
endl; int ind = 0;

ind = not_triangle(ind, arr);


ind = Equilateral(ind, arr);
ind = Isosceles(ind, arr);
ind = 1;

for (int i = 0; i < 7; i++) {


a = sides[i][0];
b = sides[i][1];
c = sides[i][2];
cout << ind << "\t" << a << "\t" << b << "\t" << c << "\t" <<
result(a, b, c, arr) << endl;
ind++;
}
ind = impossible(ind);
cout << ind << "\t" << arr[0][1] - 1 << "\t" << arr[1][2] <<
"\t" << arr[2][2] + 2 << "\t" << result(arr[0][1] - 1,
arr[1][2], arr[2][2] + 2, arr) << endl;
return 0;
}
OUTPUT

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

where V(G) = Cyclomatic complexity

G : program graph

n : number of nodes

e : number of edges

P : number of connected components

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(&quot;Enter
first side of the triangle:&quot;); /*Enter the sides of
Triangle*/\n8. scanf(&quot;%lf&quot;,&amp;a);\n9.
printf(&quot;Enter second side of the triangle:&quot;);\n10.
scanf(&quot;%lf&quot;,&amp;b);\n11. printf(&quot;Enter third
side of the triangle:&quot;);\n12.
scanf(&quot;%lf&quot;,&amp;c);\n/*Checks whether a triangle is
valid or not*/\n13.
if(a&gt;0&amp;&amp;a&lt;=100&amp;&amp;b&gt;0&amp;&amp;b&lt;=100&
amp;& amp;c&gt;0&amp;&am
p;c&lt;=100) {\n14.
if((a+b)&gt;c&amp;&amp;(b+c)&gt;a&amp;&amp;(c+a)&gt;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&lt;1||a2&lt;1||a3&lt;1) {\n26. printf(&quot;Obtuse angled
triangle&quot;);\n27. }\n28. else if(a1==1||a2==1||a3==1) {\n29.
printf(&quot;Right angled triangle&quot;);\n30. }\n31. else
{\n32. printf(&quot;Acute angled triangle&quot;);\n33. }\n34.
}\n35. else if(valid==-1) {\n36. printf(&quot;\nInvalid
Triangle&quot;);\n37. }\n38. else {\n39. printf(&quot;\nInput
Values are Out of Range&quot;);\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:

The Decision to Decision (DD) path graph is an extension of a program graph. It is


widely known as DD path graph.When we enter into the first node of the sequence, we
can exit only from the last node of that sequence. In DD path graph, such nodes which
are in a sequence are combined into a block and are represented by a single node. Hence,
the DD path graph is a directed graph in which nodes are sequences of statements and
edges are control flow amongst the nodes. All programs have an entry and an exit and the
corresponding program graph has a source node and a destination node. Similarly, the
DD path graph also has a source node and a destination node.

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;
}
};

void dfs_printPaths(vector<vector<Edge*> >& graph,int


src,vector<bool>& vis, int endNode,int& count,string
path) {
if(src==endNode)
{
path+="N"+to_string(endNode);
cout<<"Path "<<count++<<": "<<path<<endl;
return;
}
vis[src]=true;
for( Edge*e : graph[src] )
{
if(vis[e->v]==false)

dfs_printPaths(graph,e->v,vis,endNode,count,path+"N"+to_string(
src)+" -> ");
}
vis[src]=false;

void display_graph(vector<vector<Edge*> >& graph)


{
int n=graph.size();
cout<<"\n\nGraph in Edge Representation is :\n";
for(int i=0;i<n;i++)
{ cout<<endl<<"Vertex "<<i<<" ->";
for(Edge* e: graph[i])
cout<<"("<<e->v<<","<<e->wt<<"), ";

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];

vector<vector<Edge*> > graph(n,vector<Edge*>());


int P=1;
int e=0;

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";
}

void M2(vector<vector< int> > testCases)


{cout<<endl<<endl<<"-------------------------------------------------
----- ---------------------------\n";
cout<<" Mutant 2"<<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"<<M2_Code(testCases[i])<<endl;
if(correct(testCases[i])!=M2_Code(testCases[i]) && flag==false) {
killed++;
flag=true;
}
}
if(flag==true)
cout<<endl<<"Mutant Killed";
else cout<<endl<<"Mutant not Killed";
}
void M3(vector<vector< int> > testCases)
{

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";
}

void M4(vector<vector< int> > testCases)


{

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:

Cause-effect graphing is a systematic method for generating test cases. It considers


dependency of inputs using some constraints.

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;

int triangle(int a[3], int min=1, int max=100)


{
for(int i=0;i<3;i++)
if(a[i]<min || a[i]>max)
return -1;
if(a[0]+a[1]>a[2] && a[1]+a[2]>a[0] && a[2]+a[0]>a[1])
{
if(a[0]==a[1] && a[1]==a[2] && a[2]==a[0])
return 1;
else if(a[0]==a[1] || a[1]==a[2] || a[2]==a[0])
return 2;
else
return 3;
}
else
return 0;
}

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<77;i++) cout<<"-"; cout<<"\n";

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()
{

int expOut[11], testCases[11][3], i=0, x=0, y=0,


z=0; generateCauseAndEffect();
for(i=0;i<11;i++)
{
switch(i)
{
case 0: x=90; y=60; z=20;
break;
case 1: x=60; y=90; z=20;
break;
case 2: x=20; y=60; z=90;
break;
case 3: x=50; y=40; z=30;
break;
case 4: x=60; y=40; z=30;
break;
case 5: x=40; y=60; z=30;
break;

}
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;

const int NOTYPE=0 ,


TYPE_REGULAR=1,TYPE_IF=2,TYPE_ELSE=3,TYPE_IF_CLOSE=4,TYPE_ELSE_CLOS
E=5; const string IF_STRING="if(", ELSE_STRING="else" ,
CLOSE_STRING="}";

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;
}
}
};

void process_line(string line, Graph* g){


Node* current_node = NULL;
// if the line is not empty create a new node for this
line if (line.find_first_not_of(' ')!=string::npos) {
current_node = Node::create_new_node();
}
if (g->head == NULL){
g->head = current_node;
Stack_Node new_node(current_node,TYPE_REGULAR);
mStack.push(new_node);
return;
}
if (mStack.top().type == TYPE_ELSE_CLOSE) {
mStack.top().ptr->next.push_back(current_node);
mStack.pop();
mStack.pop();
mStack.top().ptr->next.push_back(current_node);
mStack.pop();
mStack.pop();
}
else {
if (line.find(ELSE_STRING) == string::npos){
mStack.top().ptr->next.push_back(current_node);
}
}
if(line.find(IF_STRING) != string::npos){
Stack_Node new_node(current_node,TYPE_IF);
mStack.push(new_node);
}
else if (line.find(ELSE_STRING) != string::npos){
Stack_Node node_if_close = mStack.top();
mStack.pop();
mStack.top().ptr->next.push_back(current_node);
mStack.push(node_if_close);
Stack_Node new_node(current_node,TYPE_ELSE);
mStack.push(new_node);
}
else if (line.find(CLOSE_STRING) != string::npos){
if (mStack.top().type == TYPE_REGULAR){
mStack.pop();
if (!mStack.empty() && mStack.top().type == TYPE_IF){
Stack_Node new_node(current_node,TYPE_IF_CLOSE);
mStack.push(new_node);
}
else if(!mStack.empty() && mStack.top().type ==
TYPE_ELSE){ Stack_Node
new_node(current_node,TYPE_ELSE_CLOSE);
mStack.push(new_node);
}
else{
Stack_Node new_node(current_node , TYPE_REGULAR);
mStack.push(new_node); }}
else{
if (mStack.top().type == TYPE_IF) {
Stack_Node new_node(current_node,TYPE_IF_CLOSE);
mStack.push(new_node);
}
else if(mStack.top().type == TYPE_ELSE){
Stack_Node new_node(current_node,TYPE_ELSE_CLOSE);
mStack.push(new_node); }}
}
else {
if (mStack.top().type == TYPE_REGULAR){
mStack.pop();
Stack_Node new_node(current_node,TYPE_REGULAR);
mStack.push(new_node);
}
else if(mStack.top().type == TYPE_IF ||
mStack.top().type == TYPE_ELSE){
Stack_Node new_node(current_node,TYPE_REGULAR);
mStack.push(new_node);
}
}
}
int main() {
char filename[100];
string line;
cout<<"Enter the filename : ";
cin>>filename;
Graph* g = new Graph();
ifstream file(filename);
if (file.is_open()){
while(getline(file,line)) {
process_line(line,g);
}
}
g->printGraph();
return 0;
}

OUTPUT

CONCLUSION

The experiment was successfully run and implemented.

You might also like