Tutorial-10: To Find out the area of a Triangle, Square, Rectangle and a Circle and generate its Equivalence Class Test Cases
Objective of this Tutorial: There are two objectives of the tutorial like:
Objective 1: To write programs in C++ for the determining the areas of a Triangle, Square, Rectangle & a circle.
Objective 2: Equivalence Class Testing by designing Test Cases for all i.e. Triangle, Square, Rectangle & circle
Solution Part 1: Program in C++
#include
#include
#include
void main()
{
clrscr();
int ch;
char c;
float, b, h, a;
1: cout<<“Enter your choice”;
cout<<“n1.Triangle”;
cout<<“n2.Square”;
cout<<“n3.Rectangle”;
cout<<“n4.Circle”;
cout<<“n5.Exitn”;
cin>>ch;
switch(ch)
{ case 1 : b: cout<<“nEnter the base of the triangle (1-200)”;
cin>>b;
if ((b<=0)||(b>200))
{ cout<<“nInvalid entry for base n”;
goto b;
}
h: cout<<“nEnter the height of the triangle (1-200)”;
cin>>h;
if ((h<=0)||(h>200))
{ cout<<“nInvalid height nEnter the height (1-200)”;
goto h;
}
a= 0.5*b*h;
cout<<“nThe area is “<<a; <=”” font=””></a;>
cout<<“nWant to enter more?(y/n) “;
cin>>c;
if((c==’y’)||(c==’Y’))
goto 1;
break
case 2 : s: cout<<“nEnter the side of the square (1-200)”;
cin>>b;
if ((b<=0)||(b>200))
{ cout<<“nInvalid entry for base n”;
goto s;
}
a= b*b;
cout<<“nThe area is “<<a; <=”” font=””></a;>
cout<<“nWant to enter more?(y/n) “;
cin>>c;
if((c==’y’)||(c==’Y’))
goto 1;
break;
case 3: d: cout<<“nEnter the base of the triangle (1-200)” ;
cin>>b;
if((b<=0)||(b>200))
( cout<<“nInvalid entry for base n”;
goto d;
}
p: cout<<“nEnter the height of the triangle (1-200) “;
cin>>h;
if ((h<=0)||(h>200))
{ cout<<“nInvalid height nEnter the height(1-200)”;
goto p;
}
a=b*h;
cout<<“nThe area is “<<a; <=”” font=””></a;>
cout<<“nWant to enter more?(y/n) “;
cin>>c;
if((c==’y’)||(c==’Y’))
goto 1;
break;
case 4: t: cout<<“nEnter the radius of the circle “;
cin>>b;
if ((b<=0)||(b>200))
{ cout<<“nInvalid entry for base n”;
goto t;
}
a= 3.14*b*b;
cout<<“nThe area is “<<a; <=”” font=””></a;>
cout<<“nWant to enter more?(y/n)”;
cin>>c;
if ((c==’y’)||(c==’Y’))
goto 1;
break;
case 5: exit(0);
break;
default : cout<<“n WRONG CHOICE”;
goto 1;
}
getch();
}
Solution Part 2: Equivalence Class Test Cases
In Equivalence Class Testing, we find two types of equivalence classes 1) Input Domain and 2) 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 the problem.
Case 1: 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<=2001}
Test Cases for the Case of Triangle are as under:
Test Case ID | h | b | Expected Output |
1 | 0 | 100 | Invalid Input |
2 | 100 | 100 | 5000 |
3 | 201 | 100 | Invalid Input |
4 | 100 | 0 | Invalid Input |
5 | 100 | 100 | 5000 |
6 | 100 | 201 | Invalid Input |
Output Domain:
O1 = {: Triangle if h > 0, b > 0}
O2 = {: Not a triangle if h <= 0, b <= 0}
Screenshot of output with Inputs of Triangle is as under:
Case 2: Square
Input Domain:
I1 = {s : s<=0}
I2 = {s : s>200}
I3 = {s : 1<=s<=200}
Test Cases for the Case of Square are as under:
Test Case ID | s | Expected Output |
1 | 0 | Invalid Input |
2 | 100 | 10000 |
3 | 201 | Invalid Input |
Output Domain:
O1 = {: Square if s>}
O2 = {: Not a square if s <= 0}
Screenshot of output with Inputs of Square is as under:
Case 3: 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 Cases for the Case of Rectangle are as under:
Test Case ID | l | b | Expected Output |
1 | 0 | 100 | Invalid Input |
2 | 100 | 100 | 10000 |
3 | 201 | 100 | Invalid Input |
4 | 100 | 0 | Invalid Input |
5 | 100 | 100 | 10000 |
6 | 100 | 201 | Invalid Input |
Screenshot of output with Inputs of Rectangle is as under:
Case 4: Circle
Input Domain:
I1 = {r : r<=0}
I2 = {r : r>200}
I3 = {r : 1<=r<=200}
Test Cases for the Case of Circle are as under:
Test Case ID | r | Expected Output |
1 | 0 | Invalid Input |
2 | 100 | 31400 |
3 | 201 | Invalid Input |
Output Domain:
O1 = {: Circle if 1<=r<=200}
O2 = {: Not a Circle if r <= 0}
Screenshot of output with Inputs of Circle is as under:
Many More Articles & Tutorials on Black Box Testing
An expert on R&D, Online Training and Publishing. He is M.Tech. (Honours) and is a part of the STG team since inception.
hello sir
My Query is Why did u reatrict the height & base is less than 200.
If it is greater than what is the problem?
Pls tell me
Thanks alot