SoftwareTestingFile
SoftwareTestingFile
AIM: -Write a program to find the maximum in threenumbers input by the user and generate
test cases for the program usingBoundary Value Analysis.
SOURCE CODE: -
// Author : Aman Gupta
// Roll Number : 2K21/SE/21
// Batch : SE A1(G1)
#include<bits/stdc++.h>
usingnamespacestd;
intmain(){
intn;
cin>>n;
vector<p air<int,int>>scope;
vector<v ector<int>>result;
cout<<"E
nter No. of variables:-";
for(inti=0;i<n;i+
+){
inta,b;
cin>>a>>b;
cout<<"E nter Range:-";
scope.push_back({a ,b}) ;
}
OUTPUT: -
EXPERIMENT - 2
AIM: -Write a program to find the maximum in threenumbers input by the user and generate
test cases for the program usingRobust Approach.
SOURCE CODE: -
// Author : Aman Gupta
// Roll Number : 2K21/SE/21
// Batch : SE A1(G1)
#include<bits/stdc++.h>
usingnamespacestd;
intmain(){
intn;
cin>>n;
vector<p air<int,int>>scope;
cout<<"E nter No. of variables:-";
for(inti=0;i<n ;i+ +){
cout<<"E nter Range:-";
inta,b;
cin>>a> >b;
scope.push_back({ a,b});
}
vector<v ector<int>>result;
for(inti=0;i<n ;i+ +){
vector<int>temp(n);
for(intj=0;j<6 ;j+ +){
for(intk=0;k<n;k++){
if(i!=k){
temp[k ]=(s cope[k ].first+s cope[k].second)/2;
}
else{
if(j==0)temp[k]=scope[i].first-1 ;
elseif(j==1)temp[k]=scope[i].first;
elseif(j==2)temp[k]=scope[i].first+1;
elseif(j==3)temp[k]=scope[i].second-1 ;
elseif(j==4)temp[k]=scope[i].second;
elsetemp[k ]=scope[i] .second+1;
}
}
result.push_back(temp);
}
}
vector<int>temp(n);
for(inti=0;i<n ;i+ +){
temp[i]=(s cope[i] .first+scope[i] .second)/2;
}
result.push_back(temp);
cout<<"S .No."< <"";
for(inti=0;i<n ;i+ +){
cout<<"Variable"< <i+
1<<"";
}
cout<<"Output";
cout<<endl;
inttc=1;
for(inti=0;i<r esult.size();i+ +){
cout<<setw(5 )<<tc;
tc++;
intmaxi=INT_MIN;
for(autoj:result[i] ) {
maxi=max(maxi,j);
cout<<setw(1 1)<<j;
}
if(i=
=6*n)cout<<setw(10)< <maxi;
elseif(i%(2*n)==0||i%
(2*n)==((2*n)-1))cout<<" InValid";
elsecout<<setw(1 0)<<maxi;
cout<<endl;
}
}
OUTPUT: -
EXPERIMENT - 3
AIM: -Write a program to find the maximum in threenumbers input by the user and generate
test cases for the program usingWorst Boundary Value.
SOURCE CODE: -
// Author : Aman Gupta
// Roll Number : 2K21/SE/21
// Batch : SE A1(G1)
#include<bits/stdc++.h>
usingnamespacestd;
v oidpatterns(inti,vector<int>&temp,vector<vector<int>>&c ases,vector<vector<int>>&
result){
if(i= =cases.size()){
result.push_back(temp);
return;
}
for(intj=0;j<5 ;j+ +){
temp.push_back(cases[i][j] ) ;
patterns(i+ 1,temp,cases,result);
temp.pop_back();
}
}
intmain(){
cout<<"E nter No. of variables:-";
intn;
cin>>n;
vector<p air<int,int>>scope;
for(inti=0;i<n ;i+ +){
cout<<"E nter Range:-";
inta,b;
cin>>a> >b;
scope.push_back({a ,b}) ;
}
vector<v ector<int>>cases(n);
for(inti=0;i<n ;i+ +){
cases[i] .push_back(s cope[i] .first);
cases[i] .push_back(s cope[i] .first+1);
cases[i] .push_back((scope[i] .first+s cope[i] .second)/2);
cases[i] .push_back(s cope[i] .second-1);
cases[i] .push_back(s cope[i] .second);
}
vector<int>temp;
v ector<v ector<int>>result;
patterns(0,temp,cases,r esult);
cout<<"S .No."< <"";
for(inti=0;i<n ;i+ +){
cout<<"Variable"< <i+
1<<"";
}
cout<<"Output";
cout<<endl;
inttc=1;
for(autoi:result){
cout<<setw(5 )<<tc;
tc++;
intmaxi=INT_MIN;
for(autoj:i) {
maxi=max(maxi,j);
cout<<setw(1 1)<<j;
}
cout<<setw(1 0)<<maxi;
cout<<endl;
}
}
OUTPUT: -
EXPERIMENT - 4
AIM: -Write a program to find the maximum in threenumbers input by the user and generate
test cases for the program usingWorst Robust Approach.
SOURCE CODE: -
// Author : Aman Gupta
// Roll Number : 2K21/SE/21
// Batch : SE A1(G1)
#include<bits/stdc++.h>
usingnamespacestd;
v oidpatterns(inti,vector<int>&temp,vector<vector<int>>&cases,vector<vector<int>>&
result){
if(i==cases.size()){
result.push_back(temp);
return;
}
for(intj=0;j<7;j+
+){
temp.push_back(cases[i][j] ) ;
patterns(i+1,temp,cases,result);
temp.pop_back();
}
}
intmain(){
cout<<"E nter No. of variables:";
intn;
cin>>n;
vector<p air<int,int>>scope;
for(inti=0;i<n;i+ +){
cout<<"E nter Range:";
inta,b;
cin>>a>>b;
scope.push_back({a,b}) ;
}
vector<v ector<int>>cases(n);
for(inti=0;i<n;i+ +){
cases[i] .push_back(s cope[i] .first-1);
cases[i] .push_back(s cope[i] .first);
cases[i] .push_back(s cope[i] .first+1);
cases[i] .push_back((scope[i] .first+scope[i] .second)/2);
cases[i] .push_back(s cope[i] .second-1);
cases[i] .push_back(s cope[i] .second);
cases[i] .push_back(s cope[i] .second+1);
}
vector<int>temp;
vector<v ector<int>>result;
patterns(0,temp,cases,result);
cout<<"S .No."<<"";
for(inti=0;i<n;i+ +){
cout<<"V ariable"<<i+1<<"";
}
cout<<"O utput"<<endl;
inttc=1;
for(autoi:result){
cout<<setw(5 )<<tc;
tc++;
intmaxi=INT_MIN;
boolflag=true;
for(intj=0;j<n;j+ +){
if(i[ j] >scope[j] .second||i[j] <scope[j] .first){
flag=false;
}
maxi=max(maxi,i[j] );
cout<<setw(9 )<<i[j] ;
}
if(flag){
cout<<setw(9 )<<maxi;
}
else{
cout<<"INVALID";
}
cout<<endl;
}
}
OUTPUT: -
EXPERIMENT - 5
AIM: -Write a program to find the type of the triangleon the basis of sides input by the user
and generate test cases to test the usingEquivalanceClass Testing.
Source Code: -
// Author : Aman Gupta
// Roll Number : 2K21/SE/21
// Batch : SE A1(G1)
#include<bits/stdc++.h>
usingnamespacestd;
intnum=1;
voidcheck(intside1,intside2,intside3,intl,intr){
cout<<setw(3)<<num<<setw(1 0)<<side1<<setw(10)<<side2<<setw(1 0)<<side3<<" ";
num++;
if(side1<l||side1>r||side2<l||side2>r||side3<l||side3>r)cout<<"I nvalid Input"<<endl;
elseif(side1+side2<=side3||side1+side3<=side2||side2+side3<=side1)cout<<"N ot atriangle"<<
endl;
else{
if(side1==side2&&side1==side3)cout<<"E quilateral Triangle"<<endl;
elseif(side1==side2||side2==side3||side1==side3)cout<<"I sosceles Triangle"<<endl;
elsecout<<"S
calene Triangle"<<endl;
}
}
intmain(){
intleft,right;
c out<<"E
nter value range for sides:";
cin>>left>>right;
ap<int,int>m;
m
m[0]=(left+right)/2;
m[1]=left-1;
m[2]=right+1;
return0;}
Output: -
EXPERIMENT - 6
Aim: -Write a program to find the type of the triangleon the basis of sides input by the user
and generate test cases to test the program usingDecision Table Testing.
Source Code: -
// Author : Aman Gupta
// Roll Number : 2K21/SE/21
// Batch : SE A1(G1)
#include<iostream>
#include<vector>
usingnamespacestd;
stringresult(inta,intb,intc,vector<vector<int>>arr){
stringresult="N ot 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]) {
result="I nput values are out of range";
}elseif(a<b+c&&b<a+c&&c<a+b){
if(a==b&&b==c) {
result="E quilateral Triangle";
}elseif(a==b||b==c||a==c){
result="I sosceles Triangle";
}else{
result="S
calene Triangle";
}
}
returnresult;
}
stringBuild_DT(){
stringstr="\nDECISION TABLE FOR TRIANGLE CLASSIFICATIONPROBLEM\n";
str=str+"- ---------------------------------------------------------------\n";
str=str+"D ecisions | 1 | 2 | 3 |4 | 5 | 6 | 7 | 8 | 9 | 10| 11|\n";
str=str+"- ---------------------------------------------------------------\n";
str=str+"C 1: a < b + c? | F | T | T |T | T | T | T | T | T | T | T |\n";
str=str+"C 2: b < a + c? | - | F | T |T | T | T | T | T | T | T | T |\n";
str=str+"C 3: c < a + b? | - | - | F |T | T | T | T | T | T | T | T |\n";
str=str+"C 4: a = b ? | - | - | - |T | T | T | T | F | F | F | F |\n";
str=str+"C 5: a = c ? | - | - | - |T | T | F | F | T | F | F | F |\n";
str=str+"C
6: b = c ? | - | - | - |T | F | T | F | F | F | T | F |\n";
s tr=str+"- ---------------------------------------------------------------\n";
str=str+"R ule count |32 |16 | 8 |1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |\n";
str=str+"- ---------------------------------------------------------------\n";
str=str+"A 1: Not a triangle | X | X | X | | | | | | | | |\n";
str=str+"A 2: Scalene | | | | | | | | | | | X |\n";
str=str+"A 3: Isosceles | | | | | | | X | | X | X | |\n";
str=str+"A 4: Equilateral | | | |X | | | | | | | |\n";
str=str+"A
5: Impossible | | | | | X | X | | X | | | |\n";
returnstr;
}
intnot_triangle(intind,vector<v ector<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++;
returnind;
}
intEquilateral(intind,vector<vector<int>>arr){
a=arr[0][3];
b=arr[1][3];
c=arr[2][3];
intmin_max=arr[0 ][0],max_min=arr[0 ][1],nominal_val;
for(inti=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++;
returnind;
}
intIsosceles(intind,vector<vector<int>>arr){
a=arr[0][3];
b=arr[1][3];
c=arr[2][3];
intmin_max=arr[0 ][0],max_min=arr[0 ][1],nominal_val;
for(inti=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++;
returnind;
}
intimpossible(intind){
for(inti=0;i<3;i+
+){
cout<<ind+i<<"\t?\t?\t?\tImpossible"<<endl;
}
ind=ind+3;
returnind;
}
intmain(){
vector<v ector<int>>arr(3 ,vector<int>(3,0));
cout<<"E nter the sides of the Triangle:"<<endl;
for(inti=0;i<3;i+ +){
cout<<"E nter 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<<"D ECISION TABLE - TEST CASES"<<endl;
cout<<"S .No\ta\tb\tc\tExpected Output"<<endl;
intind=0;
ind=not_triangle(ind,arr);
ind=Equilateral(ind,arr);
ind=Isosceles(ind,arr);
ind=1;
for(inti=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;
return0;
}
Output: -
EXPERIMENT - 7
Source Code: -
// Author : Aman Gupta
// Roll Number : 2K21/SE/21
// Batch : SE A1(G1)
#include<bits/stdc++.h>
usingnamespacestd;
c lassCyclomaticComplexityCalculator{
public:
intcalculate(constvector<s tring>&sourceCode){
intnodes=0;
for(conststring&line:sourceCode){
nodes+=countDecisiveNodes(line);
}
intcomplexity=nodes+1;
returncomplexity;
}
private:
intcountDecisiveNodes(conststring&line){
intcontrolFlows=1;
if(line.find("if")!=string::npos||line.find("elseif")!=string::npos)
controlFlows++;
if(line.find("for")!=string::npos||line.find("while")!=string::npos)
controlFlows++;
if(line.find("case")!=string::npos)
controlFlows++;
returncontrolFlows;
}
};
intmain(){
ifstreaminputFile("source_code.txt");
if(!inputFile.is_open()){
cerr<<"F ailed to open the source_code.txtfile."<<endl;
return1;
}
vector<s tring>sourceCode;
stringline;
while(getline(inputFile,line)){
sourceCode.push_back(line);
}
inputFile.close();
for(autoi:sourceCode){
cout<<i< <endl;
}
yclomaticComplexityCalculatorcalculator;
C
intcomplexity=calculator.calculate(s ourceCode);
cout<<"C yclomatic Complexity:"<<complexity<<endl;
return0;
}
Output: -
EXPERIMENT - 8
Aim: -Write a program to input graph matrix and performDD path testing.
Source Code: -
// Author : Aman Gupta
// Roll Number : 2K21/SE/21
// Batch : SE A1(G1)
#include<bits/stdc++.h>
usingnamespacestd;
c lassEdge{
public:
intwt;
intv;
Edge(intnb,intw){
v=nb;
wt=w;
}
};
intmain(){
intn;
cout<<"E nter the number of Decision nodes (Sizeof Matrix):";
cin>>n;
cout<<"P lease input the graph matrix:\n";
vector<v ector<int>>mat(n,vector<int>(n,0));
for(inti=0;i<n;i+
+)
for(intj=0;j<n;j+
+)
c in>>mat[i][j] ;
vector<v ector<Edge*>>graph(n ,vector<E dge*>());
intP=1;
inte=0;
for(inti=0;i<n;i+ +)
for(intj=0;j<n;j+ +)
if(mat[i] [j] ==1){
graph[i].push_back(newEdge(j,1));
e++;
}
vector<b ool>vis(n ,false);
intcount=1;
cout<<"C yclomatic Complexity is:"<<e-n+2*P<<endl;
cout<<"\nPaths are:\n";
dfs_printPaths(graph,0,vis,n-1,count,"");
cout<<endl;
return0;
}
Output: -
EXPERIMENT - 9
Source Code: -
// Author : Aman Gupta
// Roll Number : 2K21/SE/21
// Batch : SE A1(G1)
#include<iostream>
#include<vector>
usingnamespacestd;
intkilled=0;
intcorrect(vector<int>testCase){
intA=testCase[0];
intB=testCase[1];
intC=testCase[2];
if(A>B)
if(A>C)
returnA;
else
returnC;
else
if(C>B)
returnC;
else
returnB;
return0;
}
intM1_Code(v ector<int>testCase){
intA=testCase[0];
intB=testCase[1];
intC=testCase[2];
if(A<B)
if(A>C)
returnA;
else
returnC;
else
if(C>B)
returnC;
else
returnB;
return0;
}
intM2_Code(v ector<int>testCase){
intA=testCase[0];
intB=testCase[1];
intC=testCase[2];
if(A>(B+C) )
if(A>C)
returnA;
else
returnC;
else
if(C>B)
returnC;
else
returnB;
return0;
}
intM3_Code(v ector<int>testCase){
intA=testCase[0];
intB=testCase[1];
intC=testCase[2];
if(A>B)
if(A<C)
returnA;
else
returnC;
else
if(C>B)
returnC;
else
returnB;
return0;
}
intM4_Code(v ector<int>testCase){
intA=testCase[0];
intB=testCase[1];
intC=testCase[2];
if(A>B)
if(A>C)
returnA;
else
returnC;
else
if(C==B)
returnC;
else
returnB;
return0;
}
intM5_Code(v ector<int>testCase){
intA=testCase[0];
intB=testCase[1];
intC=testCase[2];
if(A>B)
if(A>C)
returnA;
else
returnC;
else
if(C>B)
returnB;
else
returnB;
return0;
}
voidM1(vector<vector<int>>testCases){
cout<<endl<<endl<<"- -------------------------------------------------------
--------------------------\n";
cout<<" Mutant 1"<<endl;
cout<<"\t\t A\tB\tC\tExpected\t Actual"<<endl;
b oolflag=false;
for(inti=0;i<testCases.size();i+
+){
cout<<"T est Case"<<i+1<<"\t"<<testCases[i] [0]<<"\t"<<testCases[i][1]<<
"\t"<<testCases[i] [2]<<"\t"<<correct(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<<"M utant Killed";
else
cout<<endl<<"M
utant not Killed";
}
voidM2(vector<vector<int>>testCases){
cout<<endl<<endl<<"- ----------------------------------------------------
--------------------------\n";
cout<<" Mutant 2"<<endl;
cout<<"\t\t A\tB\tC\tExpected\t Actual"<<endl;
b oolflag=false;
for(inti=0;i<testCases.size();i+
+){
cout<<"T est Case"<<i+1<<"\t"<<testCases[i] [0]<<"\t"<<testCases[i][1]<<
"\t"<<testCases[i] [2]<<"\t"<<correct(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<<"M utant Killed";
else
cout<<endl<<"M
utant not Killed";
}
voidM3(vector<vector<int>>testCases){
cout<<endl<<endl<<"- ----------------------------------------------------
--------------------------\n";
cout<<" Mutant 3"<<endl;
cout<<"\t\t A\tB\tC\tExpected\t Actual"<<endl;
b oolflag=false;
for(inti=0;i<testCases.size();i+
+){
cout<<"T est Case"<<i+1<<"\t"<<testCases[i] [0]<<"\t"<<testCases[i][1]<<
"\t"<<testCases[i] [2]<<"\t"<<correct(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<<"M utant Killed";
else
cout<<endl<<"M
utant not Killed";
}
voidM4(vector<vector<int>>testCases){
cout<<endl<<endl<<"- -------------------------------------------------------
--------------------------\n";
cout<<" Mutant 4"<<endl;
cout<<"\t\t A\tB\tC\tExpected\t Actual"<<endl;
b oolflag=false;
for(inti=0;i<testCases.size();i+
+){
cout<<"T est Case"<<i+1<<"\t"<<testCases[i] [0]<<"\t"<<testCases[i][1]<<
"\t"<<testCases[i] [2]<<"\t"<<correct(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<<"M utant Killed";
else
cout<<endl<<"M
utant not Killed";
}
voidM5(vector<vector<int>>testCases){
cout<<endl<<endl<<"- ----------------------------------------------------
--------------------------\n";
cout<<" Mutant 5"<<endl;
cout<<"\t\t A\tB\tC\tExpected\t Actual"<<endl;
b oolflag=false;
for(inti=0;i<testCases.size();i+
+){
cout<<"T est Case"<<i+1<<"\t"<<testCases[i] [0]<<"\t"<<testCases[i][1]<<
"\t"<<testCases[i] [2]<<"\t"<<correct(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<<"M utant Killed";
else
cout<<endl<<"M
utant not Killed";
}
intmain(){
cout<<endl<<endl<<"- -------------------------------------------------------
--------------------------\n";
cout<<" MUTATION TESTING"<<endl;
cout<<"E nter number of test cases:";
intN;
cin>>N;
vector<v ector<int>>testCases(N,vector<int>(3,0));
for(inti=0;i<N;i++){
cout<<"E nter test case"<<i+1<<":";
cin>>testCases[i] [0]>>testCases[i][1]>>testCases[i] [2];
}
1(testCases);
M
M2(testCases);
M3(testCases);
M4(testCases);
M5(testCases);
c out<<endl<<endl<<"- -------------------------------------------------------
--------------------------\n";
cout<<" MUTATION SCORE"<<endl;
cout<<"T otal Mutants:"<<5<<endl;
cout<<"M utants Killed:"<<killed<<endl;
cout<<"M
utation Score:"<<killed/5.0<<endl;
return0;
}
OUTPUT: -