0% found this document useful (0 votes)
45 views17 pages

Program 1-Boundary Value Analysis

The document describes program code for testing software using different structural testing techniques: boundary value analysis, robustness testing, worst case testing, and equivalence class testing. The programs generate test cases for variables based on their minimum and maximum values. Program 1 generates test cases at the boundary values of each variable. Program 2 generates additional test cases beyond the boundaries. Program 3 tests all combinations of minimum and maximum values for each variable. Program 4 combines robustness and worst case testing. Program 5 defines equivalence classes of input and output values and generates a test case for each class.

Uploaded by

Sher Khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views17 pages

Program 1-Boundary Value Analysis

The document describes program code for testing software using different structural testing techniques: boundary value analysis, robustness testing, worst case testing, and equivalence class testing. The programs generate test cases for variables based on their minimum and maximum values. Program 1 generates test cases at the boundary values of each variable. Program 2 generates additional test cases beyond the boundaries. Program 3 tests all combinations of minimum and maximum values for each variable. Program 4 combines robustness and worst case testing. Program 5 defines equivalence classes of input and output values and generates a test case for each class.

Uploaded by

Sher Khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 17

Program 1-Boundary Value Analysis

#include<stdio.h>

int main()
{
int n,i=0,total,tcno=0,col,var_count=0;
int ar[100][3];//Assuming variables are not more than 100
printf("Enter the number of variables ");
scanf("%d",&n);
total=4*n;
col=n;
while(n)
{
printf("\n\nEnter the range of variable %d:",i+1);
printf("\nMINIMUM: ");
scanf("%d",&ar[i][0]);
printf("MAXIMUM: ");
scanf("%d",&ar[i][1]);
ar[i][2]=(ar[i][1]+ar[i][0])/2;
n--;
i++;
}//end while
printf("\n\n\nTest cases according to BOUNDARY VALUE ANALYSIS
are:\n\n\n");
printf("TEST CASE No. \t");
while(i)
{
printf("Variable %d \t",n+1);
n++;
i--;
}//end while
printf("\n\n%-14d\t",tcno+1);
tcno++;
while(n--)
{
printf("%-10d\t",ar[i][2]);
}//end while

while(total--)
{

printf("\n\n%-14d\t",tcno+1);
i=0;
while(i<col)
{
if(i == var_count)
{
switch ( tcno % 4 )
{
case 0: printf("%-10d\t",ar[i][1]-1);
break;
case 1: printf("%-10d\t",ar[i][0]);
break;
case 2: printf("%-10d\t",ar[i][0]+1);
break;
case 3: printf("%-10d\t",ar[i][1]);
break;
}// end switch
}//end if
else
{
printf("%-10d\t",ar[i][2]);
}//end else
i++;
}//end inner while
if(tcno%4==0)
var_count++;
tcno++;
}//end outer while
getch();
return 0;
}//end main
PROGRAM 2-ROBUSTNESS TESTING
#include<stdio.h>

int main()
{
int n,i=0,total,tcno=0,col,var_count=0;
int ar[100][5]; //Assuming variables are not more than 100
printf("Enter the number of variables ");
scanf("%d",&n);
total=6*n;
col=n;
while(n)
{
printf("\nEnter the range of %d variable:",i+1);
printf("\nMINIMUM: ");
scanf("%d",&ar[i][0]);
printf("MAXIMUM: ");
scanf("%d",&ar[i][1]);
ar[i][2]=(ar[i][1]+ar[i][0])/2;
n--;
i++;
} //end while

printf("\n\nTEST CASES according to ROBUSTNESS TESTING are:\n\n");


printf("TEST CASE No. \t");

while(i)
{
printf("Variable %d \t",n+1);
n++;
i--;
} //end while

printf("\n\n%-14d\t",tcno+1);
tcno++;

while(n--)
{
printf("%-10d\t",ar[i][2]);
}

while( total--)
{
printf("\n\n%-14d\t",tcno+1);
i=0;
while( i< col)
{
if(i == var_count)
{
switch( tcno%6 )
{
case 1: printf("%-10d\t",ar[i][0]-1);
break;
case 2: printf("%-10d\t",ar[i][0]);
break;
case 3: printf("%-10d\t",ar[i][0]+1);
break;
case 4: printf("%-10d\t",ar[i][1]-1);
break;
case 5: printf("%-10d\t",ar[i][1]);
break;
case 0: printf("%-10d\t",ar[i][1]+1);
break;
}// end switch
}//end if
else
{
printf("%-10d\t",ar[i][2]);
}
i++;
}//end while
if( tcno%6==0 )
{
var_count++;
}
tcno++;
}
getch();
return 0;
}

PROGRAM 3-WORST
CASE TESTING
#include<stdio.h>
#include<math.h>

int main()
{
int n=2,i=0,j,k,total,tcno=0,col,var_count=0;
int ar[2][5]; //Assuming variables are 3
col=n;
while(n)
{
printf("\nEnter the range of variable %d :",i+1);
printf("\nMINIMUM: ");
scanf("%d",&ar[i][0]);
printf("MAXIMUM: ");
scanf("%d",&ar[i][4]);
ar[i][2]=(ar[i][0]+ar[i][4])/2;
ar[i][1]=ar[i][0]+1;
ar[i][3]=ar[i][4]-1;
n--;
i++;
}
//end while
printf("\n\nTEST CASES according to WORST CASE TESTING are:\n\n");
printf("TEST CASE No. \t");

while(i)
{
printf("Variable %d \t",n+1);
n++;
i--;
} //end while
for( i=0 ; i<5 ; i++)
for( j=0 ; j<5 ; j++)

{
printf("\n\n%-14d\t",tcno+1);
tcno++;
printf("%-10d\t%-10d",ar[0][i],ar[1][j]);
}

getch();
return 0;
}

PROGRAM 4-ROBUST WORST CASE TESTING


#include<stdio.h>
#include<math.h>
int main()
{
int n=2,i=0,j,k,total,tcno=0,col;
int ar[2][7]; //Assuming variables are 3
col=n;
while(n)
{
printf("\nEnter the range of variable %d :",i+1);
printf("\nMINIMUM: ");
scanf("%d",&ar[i][1]);
printf("MAXIMUM: ");
scanf("%d",&ar[i][5]);
ar[i][3]=(ar[i][1]+ar[i][5])/2;
ar[i][2]=ar[i][1]+1;
ar[i][0]=ar[i][1]-1;
ar[i][4]=ar[i][5]-1;
ar[i][6]=ar[i][5]+1;
n--;
i++;
} //end while

printf("\n\nTEST CASES according to WORST CASE ROBUSTNESS TESTING


are:\n\n");
printf("TEST CASE No. \t");

while(i)
{
printf("Variable %d \t",n+1);
n++;
i--;
} //end while
for( i=0 ; i<7 ; i++)
for( j=0 ; j<7 ; j++)

{
printf("\n\n%-14d\t",tcno+1);
tcno++;
printf("%-10d\t%-10d\t",ar[0][i],ar[1][j]);

getch();
return 0;
}

PROGRAM 5- EQUIVALENCE CLASS TESTING


#include<iostream>
#include<conio.h>
using namespace std;

/* Function to check the type of the triangle


Input: 3 vertices
Output:
-1 - Inavlid input
0 - Equilateral triangle
1 - Isoscles triangle
2 - Scalene triangle
3 - Not a triangle
*/

int triangle(int a[3], int min[3], int max[3])


{
for(int i=0;i<3;i++)
if(a[i]<min[i] || a[i]>max[i])
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 0;
else if(a[0]==a[1] || a[1]==a[2] || a[2]==a[0])
return 1;
else
return 2;
}
else
return 3;
}
string inputClass[20], outputClass[4];
void generateClasses()
{
inputClass[0] = "{x : x<xmin}";
inputClass[1] = "{x : x>xmax}";
inputClass[2] = "{x : xmin<x<xmax}";
inputClass[3] = "{y : y<ymin}";
inputClass[4] = "{y : y>ymax}";
inputClass[5] = "{y : ymin<y<ymax}";
inputClass[6] = "{z : z<zmin}";
inputClass[7] = "{z : z>zmax}";
inputClass[8] = "{z : zmin<z<zmax}";
inputClass[9] = "{x,y,z : x=y=z}";
inputClass[10] = "{x,y,z : x=y,x!=z}";
inputClass[11] = "{x,y,z : x=z,x!=y}";
inputClass[12] = "{x,y,z : y=z,x!=y}";
inputClass[13] = "{x,y,z : x!=y!=z}";
inputClass[14] = "{x,y,z : x=y+z}";
inputClass[15] = "{x,y,z : x>y+z}";
inputClass[16] = "{x,y,z : y=x+z}";
inputClass[17] = "{x,y,z : y>x+z}";
inputClass[18] = "{x,y,z : z=x+y}";
inputClass[19] = "{x,y,z : z>x+y}";

outputClass[0] = "Equilateral Triangle";


outputClass[1] = "Isoscles Triangle";
outputClass[2] = "Scalene Triangle";
outputClass[3] = "Not a Triangle";
}

void equivalenceTesting(int min[3], int max[3])


{
int expOut[24], testCases[24][3], i=0, x=0, y=0, z=0;

generateClasses();

cout<<"\nInput Classes...";
for(i=0;i<20;i++)
cout<<"\nI"<<i<<": "<<inputClass[i];

cout<<"\n\nOutput Classes...";
for(i=0;i<4;i++)
cout<<"\nO"<<i<<": "<<outputClass[i];

//for input equivalance class


for(i=0;i<20;i++)
{
switch(i)
{
case 0: x=min[0]-1; y=(min[1]+max[1])/2;
z=(min[2]+max[2])/2;
break;
case 1: x=max[0]+1; y=(min[1]+max[1])/2;
z=(min[2]+max[2])/2;
break;
case 2: x=(min[0]+max[0])/2; y=(min[1]+max[1])/2;
z=(min[2]+max[2])/2;
break;
case 3: y=min[1]-1; x=(min[0]+max[0])/2;
z=(min[2]+max[2])/2;
break;
case 4: y=max[1]+1; x=(min[0]+max[0])/2;
z=(min[2]+max[2])/2;
break;
case 5: y=(min[1]+max[1])/2; x=(min[0]+max[0])/2;
z=(min[2]+max[2])/2;
break;
case 6: z=min[0]-1; y=(min[1]+max[1])/2;
x=(min[0]+max[0])/2;
break;
case 7: z=max[0]+1; y=(min[1]+max[1])/2;
x=(min[0]+max[0])/2;
break;
case 8: z=(min[2]+max[2])/2; y=(min[1]+max[1])/2;
x=(min[0]+max[0])/2;
break;
case 9: x=y=z=60;
break;
case 10: x=y=60; z=(min[2]+max[2])/2;
break;
case 11: x=z=60;y=(min[1]+max[1])/2;
break;
case 12: y=z=60;z=(min[0]+max[0])/2;
break;
case 13: x=40; y=60; z=80;
break;
case 14: y=(min[1]+max[1])/2; z=(min[2]+max[2])/2;
x=y+z;
break;
case 15: y=(min[1]+max[1])/2; z=(min[2]+max[2])/2;
x=y+z+1;
break;
case 16: x=(min[0]+max[0])/2; z=(min[2]+max[2])/2;
y=x+z;
break;
case 17: x=(min[0]+max[0])/2; z=(min[2]+max[2])/2;
y=x+z+1;
break;
case 18: y=(min[1]+max[1])/2; x=(min[0]+max[0])/2;
z=x+y;
break;
case 19: y=(min[1]+max[1])/2; x=(min[0]+max[0])/2;
z=x+y+1;
break;
}
testCases[i][0]=x; testCases[i][1]=y; testCases[i]
[2]=z;
}

//for output equivalance class


for( ;i<24;i++)
{
switch(i-20)
{
case 0: x=y=z=60;
break;
case 1: x=y=60; z=70;
break;
case 2: x=50; y=60; z=70;
break;
case 3: x=20; y=60; z=100;
break;
}
testCases[i][0]=x; testCases[i][1]=y; testCases[i]
[2]=z;
}

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+"; for(int i=0;i<71;i++) cout<<"-"; cout<<"+";
cout<<"\n|\ta\t\tb\t\tc\t| Output\t\t|";
cout<<"\n+"; for(int i=0;i<71;i++) cout<<"-"; cout<<"+\n";
for(int i=0;i<24;i++)
{
for(int j=0;j<3;j++)
{
if(j==0) cout<<"|";
cout<<"\t"<<testCases[i][j]<<"\t|";
}
int expOut=triangle(testCases[i],min,max);
if(expOut<0)
cout<<" Invalid input\t";
else cout<<" "<<outputClass[expOut];
cout<<"\t|"<<endl;
}
cout<<"+";for(int i=0;i<71;i++) cout<<"-"; cout<<"+";
cout<<"\n>>No. of Test Cases =
"<<sizeof(inputClass)/sizeof(inputClass[0]) +
sizeof(outputClass)/sizeof(outputClass[0]);
}

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];
}
equivalenceTesting(min,max);
return 0;
}

You might also like