Tutorial-9: To Find out the Roots of a Quadratic Equation and Generate its Boundary Value Test Cases
Inputs for the Tutorial: A quadratic equation a(x2)+bx+c=0 with input as three positive integers a, b, c having values ranging from an interval [0,100].
Objective of this Tutorial: There are two objectives of the tutorial like:
Objective 1: To write a Program in C++ for the determining the nature of roots of the above quadratic equation. The program output may have one of the following words:
“Not a Quadratic Equation”, “Real Roots”, “Imaginary Roots” or “Roots are Equal”
Objective 2: Boundary Value Testing by designing Test Cases which would use input variables at their Minimum Values, Just above Minimum Values, at Nominal Value, Just below Maximum and Minimum Values.
Solution Part 1: Program in C++
#include
#include
void main( )
{
clrscr( );
int a,b,c,d;
cout<<“The quadratic equation is of the type a(x2)+bx+c=0″<<end1; <br=””>cout<<“Enter the value of a:”<<end1;
cin>>a;
cout<<“Enter the value of b:”<<end1; <br=””>cin>>b;
cout<<“Enter the value of c: “<<end1; <br=””>cin>>c;
d = (b*b)-4*a*c;
if((a<0)||(b<0)||(c<0)||(a>100)||(b>100)||(c>100))
cout�”Invalid input”�end1;
elseif(a==0)
cout<<“Not a quadratic equation”<<end1; <br=””>elseif(d==0)
cout<<“Roots are equal”<<end1; <br=””>else if(d<0)
cout<<“Imaginary roots”<<end1;
else
cout<<“Real roots”<<end1; <br=””>getch();
}
</end1;></end1;
</end1;></end1;></end1;></end1;></end1;
</end1;>
Solution Part 2: Design Boundary Value Test Cases
In the above program, we consider the values as 0 (Minimum), 1 (Just above Minimum), 50 (Nominal), 99 (Just below Maximum) and 100 (Maximum)
Test Case ID | a | b | c | Expected Output |
1 | 50 | 50 | 0 | Real Roots |
2 | 50 | 50 | 1 | Real Roots |
3 | 50 | 50 | 50 | Imaginary Roots |
4 | 50 | 50 | 99 | Imaginary Roots |
5 | 50 | 50 | 100 | Imaginary Roots |
6 | 50 | 0 | 50 | Imaginary Roots |
7 | 50 | 1 | 50 | Imaginary Roots |
8 | 50 | 99 | 50 | Imaginary Roots |
9 | 50 | 100 | 50 | Equal Roots |
10 | 0 | 50 | 50 | Not a Quadratic Equation |
11 | 1 | 50 | 50 | Real Roots |
12 | 99 | 50 | 50 | Imaginary Roots |
13 | 100 | 50 | 50 | Imaginary Roots |
Some of the screenshots with different outputs are as under:
1) Screenshot with Output as ” Imaginary Roots” is as under
2) Screenshot with Output as “Real Roots” is as under
3) Screenshot with Output as “Roots are Equal” is as under
4) Screenshot with Output as “Not a Quadratic Equation” 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.
Good way of describing, and pleasant post to get facts about my presentation subject matter,
which i am going to convey in school.