Sunteți pe pagina 1din 19

INDEX

S. Teacher’s
Aim of Experiment Date
No. Sign.

To determine the nature of Quadratic


1. Equation. And design Boundary Value test
cases.

To determine the area of a Triangle, Square,


2. Rectangle and a circle. Design Equivalence
Class test cases.

To determine previous date when its input is


3. present date. Perform Decision Table
Testing and design the test cases.

To determine the value of x raise to y and


4.
perform Decision Table based testing on it.

To read the three sides of a triangle and to


check whether the triangle is isosceles,
equilateral or scalene and test the same
5.
using:
A. Cause Effect testing technique
B. Path testing.

Compute the total salary of an employee,


6. given his/her basic salary and other given
information.
Experiment No. 1

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).

TEST CASE ID x y z EXPECTED O/P OBSERVED O/P


1 50 50 0 REAL ROOTS REAL ROOTS
2 50 50 1 REAL ROOTS REAL ROOTS
3 50 50 50 IMAGINARY ROOTS IMAGINARY ROOTS
4 50 50 99 IMAGINARY ROOTS IMAGINARY ROOTS
5 50 50 100 IMAGINARY ROOTS IMAGINARY ROOTS
6 50 0 50 IMAGINARY ROOTS IMAGINARY ROOTS
7 50 1 50 IMAGINARY ROOTS IMAGINARY ROOTS
8 50 99 50 IMAGINARY ROOTS IMAGINARY ROOTS
9 50 100 50 EQUAL ROOTS EQUAL ROOTS
10 0 50 50 NOT A Q.E. NOT A Q.E.
11 1 50 50 REAL ROOTS REAL ROOTS
12 99 50 50 IMAGINARY ROOTS IMAGINARY ROOTS
13 100 50 50 IMAGINARY ROOTS IMAGINARY ROOTS

OUTPUTS:
Test Case ID 1:

Test Case ID 3:

Test Case ID 9:

Test Case ID 10:


Experiment No. 2

Aim: To determine the area of triangle, square, rectangle and a circle.


Design the Equivalence Class test cases.

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}

TEST CASE ID l b EXPECTED O/P OBSERVED O/P


1 0 100 Invalid I/P Invalid I/P
2 1000100 10000 10000
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 Screenshot:
CIRCLE
Input Domain:
I1: {r : r<=0}
I2: {r : r>200}
I3: {r : 1<=r<=200}

TEST CASE ID R EXPECTED O/P OBSERVED O/P


1 0 Invalid I/P Invalid I/P
2 1000 31400 31400
3 201 Invalid I/P Invalid I/P

Output Domain:
O1: {<r> : Circle if r>0}
O2: {<r> : Not a Circle if r<=0}

Output Screenshot:
Experiment No. 3

Aim: To determine previous date when its input is present date.


1<=month<=12
1<=day<=31
1990<=year<=2025
The possible outputs are “Previous Date” and “Invalid Date”.
Perform Decision Table based testing and design test cases.
Program:
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
int day,month,year,flag=0;
cout<<"Enter the day value:";
cin>>day;
cout<<"Enter the month value";
cin>>month;
cout<<"Enter the year value";
cin>>year;
if(year>=1900 || year<=2025)
{if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)
{if(day>=1 || day<=31)
{ flag=1; }
else
{ flag=0; }
}
else if(month==2)
{ int rval=0;
if(year%4==0)
{
rval=1;
if(year%100==0 && (year%400)!=0)
{ rval=0; }
}
if(rval==1 && day>=1 && day<=29)
{ flag=1; }
else
{ flag=0; }
}
else
{ if(day>=1&&day<=30)
{ flag=1; }
else
{ flag=0; }
}
}
if (flag)
{if(day==1)
{if(month==1)
{
year--;
day=31;
month=12;
}
else if(month==3)
{
int rval=0;
if(year%4==0)
{
rval=1;
if(year%100==0 && (year%400)!=0)
{ rval=0; }
}
if(rval==1)
{day=29;
month--; }
else
{ day=28;
month--; }
}
else if(month==2||month==4||month==6||month==9||month==11)
{ day=31;
month--; }
else
{ day=30;
month--; }
}
else
{ day--; }
printf("The previous date is:%d-%d-%d",day,month,year);
}
else
{ printf("The entered date is invlaid: %d-%d-%d",day,month,year); }
getch();
return 1;
}
Test Cases:
Test Case Month Day Year Expected O/P Observed O/P
ID
1 June 1 1964 31-5-1964 31-5-1964
2 June 31 1984 Impossible Impossible
3 May 1 1945 30-4-1945 30-4-1945
4 March 31 2007 30-3-2007 30-3-2007
5 August 29 2007 28-8-2007 28-8-2007
6 February 29 1962 Impossible Impossible

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:

Conditions R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11


C1: x<y+z 0 1 1 1 1 1 1 1 1 1 1
C2: y<x+z X 0 1 1 1 1 1 1 1 1 1
C3: z<x+y X X 0 1 1 1 1 1 1 1 1
C4: x=y ? X X X 1 1 1 1 0 0 0 0
C5: x=z ? X X X 1 1 0 0 1 1 0 0
C6: y=z? X X X 1 0 1 0 1 0 1 0
E1: Not a Triangle 1 1 1
E2: Scalene 1
E3: Isosceles 1 1 1
E4: Equilateral 1
E5: Not Possible 1 1 1
Test Cases:
TEST CASE ID x y Z EXPECTED O/P OBSERVED O/P
1 4 1 2 Not a Triangle Not a Triangle
2 1 4 2 Not a Triangle Not a Triangle
3 1 2 4 Not a Triangle Not a Triangle
4 5 5 5 Equilateral Equilateral
5 ? ? ? Not Possible Not Possible
6 ? ? ? Not Possible Not Possible
7 2 2 3 Isosceles Isosceles
8 ? ? ? Not Possible Not Possible
9 2 3 2 Isosceles Isosceles
10 3 2 2 Isosceles Isosceles
11 3 4 5 Scalene Scalene

B. Test Cases using Path-Testing Technique

Flow Graph: 1-12

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:

Flow Graph Nodes DD Path Graph


Corresponding
Nodes
1-12 A
13 B
14 C
15 D
16-17 E
18 F
19-20 G
21 H
22 I
23 J
24-25 K
26 L
27 M
28 N
29-30 O
31-33 P

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:

S-ar putea să vă placă și