Documente Academic
Documente Profesional
Documente Cultură
S. Teacher’s
Aim of Experiment Date
No. Sign.
Aim: To determine the nature of roots of a quadratic equation, its input is triple of
positive integers x, y, z and values may be from interval [0,100]. The program output
may have one of the following:
[Not a quadratic equation, real roots, imaginary roots, equal roots]
Design the Boundary Value test cases.
Program:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int x,y,z,d;
cout<<”The quadratic equation is of the type x(a^2)+ya+z=0”<<endl;
cout<<”Enter the value of x:”<<endl;
cin>>x;
cout<<”Enter the value of y:”<<endl;
cin>>y;
cout<<”Enter the value of z:”<<endl;
cin>>z;
d=(y*y)-4*x*z;
if((x<0)||(x>100)||(y<0)||(y>100)||(z<0)||(z>100))
cout<<”Invalid Input”<<endl;
else if(x==0)
cout<<”Not a Quadratic Equation”<<endl;
else if(d==0)
cout<<”Roots are Equal”<<endl;
else if(d<0)
cout<<”Roots are Imaginary”<<endl;
else
cout<<”Roots are Real”<<endl;
getch();
}
Test Cases:
The basic idea of boundary value testing is to use input variables at their minimum, just
above minimum, Nominal value, just below maximum and minimum.
In this program, we consider the values as 0 (minimum), 1 (just above minimum), 50
(nominal), 99 (just below maximum) and 100 (maximum).
OUTPUTS:
Test Case ID 1:
Test Case ID 3:
Test Case ID 9:
Program:
#include<iostream.h>
#include<conio.h>
#include<process.h>
void main()
{
clrscr();
int ch;
char c;
float b,h,a;
I: cout<<"Enter your Choice";
cout<<"\n1. Triangle";
cout<<"\n2. Square";
cout<<"\n3. Rectangle";
cout<<"\n4. Circle";
cout<<"\n5. Exit\n";
cin>>ch;
switch(ch)
{
case 1: b: cout<<"\nEnter the base of the triangle (1-200)"; //TRIANGLE
cin>>b;
if((b<=0)||(b>200))
{ cout<<"\nInvalid entry for base\n";
goto b; }
h: cout<<"Enter the height of the triangle (1-200)";
cin>>h;
if((h<=0)||(h>200))
{ cout<<"\nInvalid entry for height\n";
goto h; }
a=0.5*b*h;
cout<<"\nThe Area is"<<a;
cout<<"\nWant to enter more? (y/n)";
cin>>c;
if((c=='y')||(c=='Y'))
goto I;
break;
case 2: s: cout<<"\nEnter the side of the square (1-200)"; //SQUARE
cin>>b;
if((b<=0)||(b>200))
{ cout<<"\nInvalid entry for side\n";
goto s; }
a=b*b;
cout<<"\nThe Area is"<<a;
cout<<"\nWant to enter more? (y/n)";
cin>>c;
if((c=='y')||(c=='Y'))
goto I;
break;
case 3: d: cout<<"\nEnter the width of the rectangle (1-200)";
//RECTANGLE
cin>>b;
if((b<=0)||(b>200))
{ cout<<"\nInvalid entry for width\n";
goto d; }
p:cout<<"Enter the height of the rectangle (1-200)";
cin>>h;
if((h<=0)||(h>200))
{ cout<<"\nInvalid entry for height\n";
goto p; }
a=b*h;
cout<<"\nThe Area is"<<a;
cout<<"\nWant to enter more? (y/n)";
cin>>c;
if((c=='y')||(c=='Y'))
goto I;
break;
case 4: t:cout<<"\nEnter the radius of the circle (1-200)"; //CIRCLE
cin>>b;
if((b<=0)||(b>200))
{ cout<<"\nInvalid entry for radius\n";
goto t; }
a=3.14*b*b;
cout<<"\nThe Area is"<<a;
cout<<"\nWant to enter more? (y/n)";
cin>>c;
if((c=='y')||(c=='Y'))
goto I;
break;
case 5: exit(0); //EXIT
break;
default: cout<<"\nWrong Choice";
goto I;
}
getch();
}
Test Cases:
In equivalence class testing, we find two types of equivalence classes: Input Domain
and Output Domain.
Input Domain is formed from one valid sequence and two invalid sequences. The
Output domain is obtained from different types of outputs of a problem.
TRIANGLE
Input Domain:
I1: {h : h<=0}
I2: {h : h>200}
I3: {h : 1<=h<=200}
I4: {b : b<=0}
I5: {b : b>200}
I6: {b : 1<=b<=200}
TEST CASE ID h b EXPECTED O/P OBSERVED O/P
1 0 100 Invalid I/P Invalid I/P
2 1000100 5000 5000
3 201 100 Invalid I/P Invalid I/P
4 100 0 Invalid I/P Invalid I/P
5 100 201 Invalid I/P Invalid I/P
Output Domain:
O1: {<h, b> : Triangle if h>0, b>0}
O2: {<h, b> : Not a Triangle if h<=0, b<=0}
Output Screenshot:
SQUARE
Input Domain:
I1: {s :s<=0}
I2: {s : s>200}
I3: {s : 1<=s<=200}
TEST CASE ID s EXPECTED O/P OBSERVED O/P
1 0 Invalid I/P Invalid I/P
2 1000 10000 10000
3 201 Invalid I/P Invalid I/P
Output Domain:
O1: {<s> : Square if s>0}
O2: {<s> : Not a Square if s<=0}
Output Screenshot:
RECTANGLE
Input Domain:
I1: {l : l<=0}
I2: {l : l>200}
I3: {l : 1<=l<=200}
I4: {b : b<=0}
I5: {b : b>200}
I6: {b : 1<=b<=200}
Output Screenshot:
CIRCLE
Input Domain:
I1: {r : r<=0}
I2: {r : r>200}
I3: {r : 1<=r<=200}
Output Domain:
O1: {<r> : Circle if r>0}
O2: {<r> : Not a Circle if r<=0}
Output Screenshot:
Experiment No. 3
Output Screenshots:
Test Case ID 1
Test Case ID 2
Test Case ID 3
Test Case ID 4
Test Case ID 5
Test Case ID 6
Experiment No. 4
Aim: To determine the value of x raise to y and perform Decision Table based
testing on it.
Program:
#include<iostream.h>
#inlcude<conio.h>
#include<math.h>
void main()
{
clrscr();
int x,y;
float c;
char ch;
I: cout<<”To Calculate ‘x power to y’ \n”;
cout<<”Enter the value of ‘x’\n”;
cin>>x;
cout<<”Enter the value of ‘y’\n”;
cin>>y;
c=pow(x,y);
cout<<”Result is”<<c;
cout<<”\nWant to enter again? (y/n)”<<endl;
cin>>ch;
if((ch==’y’)||(ch==’Y’))
goto I;
getch();
}
Test Cases: Decision table based testing is useful for describing situations in which a number
of combinations of actions are taken for different conditions. There are four parts of a decision
table: Condition Stub, Action Stub, Condition Entries and Action Entries.
TEST CASE ID x y EXPECTED O/P OBSERVED O/P
1 2 3 +ve Result +ve Result
2 -1 3 -ve Result -ve Result
3 -2 -4 +ve Result +ve Result
4 0 1 Result is 0 Result is 0
5 0 0 Domain Error Domain Error
6 -1 -0.6 Result is 0 Result is 0
Decision Table:
Conditions
C1: x=0, y=0 T
C2: x=+ve, y=+ve T
C3: x=+ve, y=-ve T
C4: x=-ve, y=+ve T
C5: x=-ve, y=-ve even T
C6: x=0, y=integer T
C7: x=integer, y=0 T
C8: x=-ve, y=-ve odd T
Actions
A1: Domain Error X
A2: Negative O/P X X
A3: Output=1 X
A4: Positive O/P X X X
A5: Output=0 X
Output Screenshot:
Experiment No. 5
Aim: To read the three sides of triangle, its input will be positive integers greater
than 0 and less than or equal to 100 and to check whether the triangle is
isosceles, equilateral or scalene and test the same using:
A. Cause effect graphing testing technique
B. Path testing and deduce
1. Flow graph
2. DD Path graph
3. Independent paths
4. Cyclomatic complexity
Program:
#include<iostream.h> //1
#include<conio.h> //2
int main() //3
{ //4
clrscr(); //5
int a,b,c,validinput=0; //6
cout<<"Enter the side 'a' value:"; //7
cin>>a; //8
cout<<"Enter the side 'b' value:"; //9
cin>>b; //10
cout<<"Enter the side 'c' value:"; //11
cin>>c; //12
if((a>0)&&(a<=100)&&(b>0)&&(b<=100)&&(c>0)&&(c<=100)) //13
if(((a+b)>c)&&((c+a)>b)&&((b+c>a))) //14
validinput=1; //15
else //16
validinput=-1; //17
if(validinput==1) //18
{ //19
if((a==b)&&(b==c)) //20
cout<<"The Triangle is EQUILATERAL"; //21
else if((a==c)||(a==b)||(b==c)) //22
cout<<"The Triangle is ISOSCELES"; //23
else //24
cout<<"The Triangle is SCALENE"; //25
} //26
else if(validinput==0) //27
cout<<"The values do not constitute Triangle"; //28
else //29
cout<<"The inputs belong to invalid range"; //30
getch(); //31
return 1; //32
} //33
A. Test Cases using Cause-Effect Graphing Technique
Causes:
C1: side a is less than sum of b and c
C2: side b is less than sum of a and c
C3: side c is less than sum of a and b
C4: side a is equal to side b
C5: side a is equal to side c
C6: side b is equal to side c
Effects:
E1: Not a triangle
E2: Scalene triangle
E3: Isosceles triangle
E4: Equilateral triangle
E5: Impossible
Cause-Effect Graph:
C E
1 1
C
V
E
2
2
C
3
E
3
C
4
E
4
C
5
E
5
C
6
Decision Table:
1 1 1 1
7 6 4 3
1
5
1
8
1 2
9 7
2 2
2 8 9
0
2 2
1 2 3
0
2
2 4
3
2
5
2
6
3 3 3
1 2 3
Mapping Table for DD-Path Graph:
DD-Path Graph:
A
E C B
M
G
H I O
N
J K
P
Independent Paths:
1. ABCDFGHLP
2. ABCEFGHLP
3. ABFMOP
4. ABFMNP
5. ABFGHLP
6. ABFGIJLP
7. ABFGIKLP
Cyclomatic Complexity:
The Cyclomatic Complexity or the structural complexity of the above code can be found
by using three different ways:
1. By using McCabe’s Cyclomatic Metric formulae:
V(G)=e-n+2P
Where V(G) is the cyclomatic metric of the graph G with n vertices, e edges and P
connected components.
In this case, the value of e=21, n=16 and P=1
Therefore, the value of V(G) is deduced to be 7
2. Predicate Decision Nodes:
V(G)=∏+1
As there are 6 decision nodes, the value of V(G) is 7
3. Cyclomatic Complexity is equal to total number of regions of the flowgraph. As there
are 7 regions in our graph, the value of V(G) is 7.
Output Screenshots:
Test Case ID 1
Test Case ID 4
Test Case ID 7
Test Case ID 11
Experiment No. 6
Aim: Compute the total salary of an employee, given his/her basic salary and the
following slab is:
HRA=30% of basic salary
DA=80% of basic salary
MA= Rs. 100
TA= Rs. 800
I.Tax= Rs. 700
PF= Rs. 780
Program:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr() //1
float bs; //2
cout<<"Enter the basic salary of the employee"; //3
cin>>bs; //4
int hra,da,ma=100,ta=800,itax=700,pf=780; //5
hra=0.3*bs; //6
da=0.8*bs; //7
cout<<"\nHouse Allowance: Rs."<<hra; //8
cout<<"\nDearness Allowance: Rs."<<da; //9
cout<<"\nMedical Allowance: Rs."<<ma; //10
cout<<"\nTravel Allowance: Rs."<<ta; //11
cout<<"\nIncome Tax: Rs."<<itax; //12
cout<<"\nProvidend Fund: Rs."<<pf; //13
float netsal; //14
netsal=(bs+hra+da+ta-itax-pf); //15
cout<<"\nThe net salary of the employee: Rs."<<netsal; //16
getch(); //17
}
Output Screenshot: