Thursday, September 4, 2025
HomeGuest BlogsBoundary Value Analysis : Nature of Roots of a Quadratic equation

Boundary Value Analysis : Nature of Roots of a Quadratic equation

Consider a problem for the determination of the nature of the roots of a quadratic equation where the inputs are 3 variables (a, b, c) and their values may be from the interval [0, 100]. The output may be one of the following depending on the values of the variables:

  • Not a quadratic equation,
  • Real roots,
  • Imaginary roots,
  • Equal roots

Our objective is to design the boundary value test cases. Boundary value analysis is a software testing technique in which tests are designed to include representatives of boundary values in a range. A boundary value analysis has a total of 4*n+1 distinct test cases, where n is the number of variables in a problem. Here we have to consider all three variables and design all the distinct possible test cases. We will have a total of 13 test cases as n = 3.

  • Roots are real if (b2 – 4ac) > 0
  • Roots are imaginary if (b2 – 4ac) < 0
  • Roots are equal if (b2 – 4ac) = 0
  • Equation is not quadratic if a = 0

How do we design the test cases ? For each variable we consider below 5 cases:

  • amin = 0
  • amin+1 = 1
  • anominal = 50
  • amax-1 = 99
  • amax = 100

When we are considering these 5 cases for a variable, rest of the variables have the nominal values, like in the above case where the value of ‘a’ is varying from 0 to 100, the value of ‘b’ and ‘c’ will be taken as the nominal or average value. Similarly, when the values of variable ‘b’ are changing from 0 to 100, the values of ‘a’ and ‘c’ will be nominal or average i.e 50. The possible test cases for the nature of roots of a Quadratic Equation in a Boundary Value Analysis can be: Below is the program that verifies the test cases considered in the table shown above. The program takes user-defined inputs so that you can check for any of the test cases mentioned above. 

C++




// C++ program to check the nature of the roots
 
#include <bits/stdc++.h>
using namespace std;
 
// BVA for nature of roots of a quadratic equation
void nature_of_roots(int a, int b, int c)
{
 
    // If a = 0, D/2a will yield exception
    // Hence it is not a valid Quadratic Equation
    if (a == 0) {
        cout << "Not a Quadratic Equation"
             << endl;
        return;
    }
 
    int D = b * b - 4 * a * c;
 
    // If D > 0, it will be Real Roots
    if (D > 0) {
        cout << "Real Roots" << endl;
    }
 
    // If D == 0, it will be Equal Roots
    else if (D == 0) {
        cout << "Equal Roots" << endl;
    }
 
    // If D < 0, it will be Imaginary Roots
    else {
        cout << "Imaginary Roots" << endl;
    }
}
 
// Function to check for all testcases
void checkForAllTestCase()
{
 
    cout << "Testcase"
         << "\ta\tb\tc\tActual Output"
         << endl;
    cout << endl;
    int a, b, c;
    int testcase = 1;
    while (testcase <= 13) {
        if (testcase == 1) {
            a = 0;
            b = 50;
            c = 50;
        }
        else if (testcase == 2) {
            a = 1;
            b = 50;
            c = 50;
        }
        else if (testcase == 3) {
            a = 50;
            b = 50;
            c = 50;
        }
        else if (testcase == 4) {
            a = 99;
            b = 50;
            c = 50;
        }
        else if (testcase == 5) {
            a = 100;
            b = 50;
            c = 50;
        }
        else if (testcase == 6) {
            a = 50;
            b = 0;
            c = 50;
        }
        else if (testcase == 7) {
            a = 50;
            b = 1;
            c = 50;
        }
        else if (testcase == 8) {
            a = 50;
            b = 99;
            c = 50;
        }
        else if (testcase == 9) {
            a = 50;
            b = 100;
            c = 50;
        }
        else if (testcase == 10) {
            a = 50;
            b = 50;
            c = 0;
        }
        else if (testcase == 11) {
            a = 50;
            b = 50;
            c = 1;
        }
        else if (testcase == 12) {
            a = 50;
            b = 50;
            c = 99;
        }
        else if (testcase == 13) {
            a = 50;
            b = 50;
            c = 100;
        }
        cout << "\t" << testcase << "\t"
             << a << "\t" << b << "\t"
             << c << "\t";
        nature_of_roots(a, b, c);
        cout << endl;
        testcase++;
    }
}
 
// Driver Code
int main()
{
    checkForAllTestCase();
    return 0;
}


Java




// Java program to check the nature of the roots
import java.util.*;
 
class GFG
{
 
// BVA for nature of roots of a quadratic equation
static void nature_of_roots(int a, int b, int c)
{
 
    // If a = 0, D/2a will yield exception
    // Hence it is not a valid Quadratic Equation
    if (a == 0)
    {
        System.out.print("Not a Quadratic Equation"
            +"\n");
        return;
    }
 
    int D = b * b - 4 * a * c;
 
    // If D > 0, it will be Real Roots
    if (D > 0) {
        System.out.print("Real Roots" +"\n");
    }
 
    // If D == 0, it will be Equal Roots
    else if (D == 0) {
        System.out.print("Equal Roots" +"\n");
    }
 
    // If D < 0, it will be Imaginary Roots
    else {
        System.out.print("Imaginary Roots" +"\n");
    }
}
 
// Function to check for all testcases
static void checkForAllTestCase()
{
 
    System.out.print("Testcase"
        + "\ta\tb\tc\tActual Output"
        +"\n");
    System.out.println();
    int a, b, c;
    a = b = c = 0;
    int testcase = 1;
    while (testcase <= 13) {
        if (testcase == 1) {
            a = 0;
            b = 50;
            c = 50;
        }
        else if (testcase == 2) {
            a = 1;
            b = 50;
            c = 50;
        }
        else if (testcase == 3) {
            a = 50;
            b = 50;
            c = 50;
        }
        else if (testcase == 4) {
            a = 99;
            b = 50;
            c = 50;
        }
        else if (testcase == 5) {
            a = 100;
            b = 50;
            c = 50;
        }
        else if (testcase == 6) {
            a = 50;
            b = 0;
            c = 50;
        }
        else if (testcase == 7) {
            a = 50;
            b = 1;
            c = 50;
        }
        else if (testcase == 8) {
            a = 50;
            b = 99;
            c = 50;
        }
        else if (testcase == 9) {
            a = 50;
            b = 100;
            c = 50;
        }
        else if (testcase == 10) {
            a = 50;
            b = 50;
            c = 0;
        }
        else if (testcase == 11) {
            a = 50;
            b = 50;
            c = 1;
        }
        else if (testcase == 12) {
            a = 50;
            b = 50;
            c = 99;
        }
        else if (testcase == 13) {
            a = 50;
            b = 50;
            c = 100;
        }
        System.out.print("\t" + testcase+ "\t"
            + a+ "\t" + b+ "\t"
            + c+ "\t");
        nature_of_roots(a, b, c);
        System.out.println();
        testcase++;
    }
}
 
// Driver Code
public static void main(String[] args)
{
    checkForAllTestCase();
}
}
 
// This code is contributed by 29AjayKumar


Python3




# Python3 program to check the nature of the roots
 
# BVA for nature of roots of a quadratic equation
def nature_of_roots(a, b, c):
 
    # If a = 0, D/2a will yield exception
    # Hence it is not a valid Quadratic Equation
    if (a == 0):
        print("Not a Quadratic Equation");
        return;
     
    D = b * b - 4 * a * c;
 
    # If D > 0, it will be Real Roots
    if (D > 0):
        print("Real Roots");
     
    # If D == 0, it will be Equal Roots
    elif(D == 0):
        print("Equal Roots");
     
    # If D < 0, it will be Imaginary Roots
    else:
        print("Imaginary Roots");
     
# Function to check for all testcases
def checkForAllTestCase():
 
    print("Testcase\ta\tb\tc\tActual Output");
    print();
    a = b = c = 0;
    testcase = 1;
    while (testcase <= 13):
        if (testcase == 1):
            a = 0;
            b = 50;
            c = 50;
        elif(testcase == 2):
            a = 1;
            b = 50;
            c = 50;
        elif(testcase == 3):
            a = 50;
            b = 50;
            c = 50;
        elif(testcase == 4):
            a = 99;
            b = 50;
            c = 50;
        elif(testcase == 5):
            a = 100;
            b = 50;
            c = 50;
        elif(testcase == 6):
            a = 50;
            b = 0;
            c = 50;
        elif(testcase == 7):
            a = 50;
            b = 1;
            c = 50;
        elif(testcase == 8):
            a = 50;
            b = 99;
            c = 50;
        elif(testcase == 9):
            a = 50;
            b = 100;
            c = 50;
        elif(testcase == 10):
            a = 50;
            b = 50;
            c = 0;
        elif(testcase == 11):
            a = 50;
            b = 50;
            c = 1;
        elif(testcase == 12):
            a = 50;
            b = 50;
            c = 99;
        elif(testcase == 13):
            a = 50;
            b = 50;
            c = 100;
         
        print("\t" , testcase , "\t" , a , "\t" , b , "\t" , c , "\t", end="");
        nature_of_roots(a, b, c);
        print();
        testcase += 1;
     
# Driver Code
if __name__ == '__main__':
    checkForAllTestCase();
 
# This code is contributed by 29AjayKumar


C#




// C# program to check the nature of the roots
using System;
 
class GFG
{
 
// BVA for nature of roots of a quadratic equation
static void nature_of_roots(int a, int b, int c)
{
 
    // If a = 0, D/2a will yield exception
    // Hence it is not a valid Quadratic Equation
    if (a == 0)
    {
        Console.Write("Not a Quadratic Equation"
                       +"\n");
        return;
    }
 
    int D = b * b - 4 * a * c;
 
    // If D > 0, it will be Real Roots
    if (D > 0) {
        Console.Write("Real Roots" +"\n");
    }
 
    // If D == 0, it will be Equal Roots
    else if (D == 0) {
        Console.Write("Equal Roots" +"\n");
    }
 
    // If D < 0, it will be Imaginary Roots
    else {
        Console.Write("Imaginary Roots" +"\n");
    }
}
 
// Function to check for all testcases
static void checkForAllTestCase()
{
 
    Console.Write("Testcase"
        + "\ta\tb\tc\tActual Output"
        +"\n");
    Console.WriteLine();
    int a, b, c;
    a = b = c = 0;
    int testcase = 1;
    while (testcase <= 13) {
        if (testcase == 1) {
            a = 0;
            b = 50;
            c = 50;
        }
        else if (testcase == 2) {
            a = 1;
            b = 50;
            c = 50;
        }
        else if (testcase == 3) {
            a = 50;
            b = 50;
            c = 50;
        }
        else if (testcase == 4) {
            a = 99;
            b = 50;
            c = 50;
        }
        else if (testcase == 5) {
            a = 100;
            b = 50;
            c = 50;
        }
        else if (testcase == 6) {
            a = 50;
            b = 0;
            c = 50;
        }
        else if (testcase == 7) {
            a = 50;
            b = 1;
            c = 50;
        }
        else if (testcase == 8) {
            a = 50;
            b = 99;
            c = 50;
        }
        else if (testcase == 9) {
            a = 50;
            b = 100;
            c = 50;
        }
        else if (testcase == 10) {
            a = 50;
            b = 50;
            c = 0;
        }
        else if (testcase == 11) {
            a = 50;
            b = 50;
            c = 1;
        }
        else if (testcase == 12) {
            a = 50;
            b = 50;
            c = 99;
        }
        else if (testcase == 13) {
            a = 50;
            b = 50;
            c = 100;
        }
        Console.Write("\t" + testcase+ "\t"
                        + a+ "\t" + b+ "\t"
                        + c+ "\t");
        nature_of_roots(a, b, c);
        Console.WriteLine();
        testcase++;
    }
}
 
// Driver Code
public static void Main(String[] args)
{
    checkForAllTestCase();
}
}
 
// This code is contributed by 29AjayKumar


Javascript




// JavaScript program to check the nature of the roots
 
 
// BVA for nature of roots of a quadratic equation
function nature_of_roots(a, b, c)
{
 
    // If a = 0, D/2a will yield exception
    // Hence it is not a valid Quadratic Equation
    if (a == 0) {
        console.log("Not a Quadratic Equation")
        return;
    }
 
    let D = b * b - 4 * a * c;
 
    // If D > 0, it will be Real Roots
    if (D > 0) {
        console.log("Real Roots");
    }
 
    // If D == 0, it will be Equal Roots
    else if (D == 0) {
        console.log("Equal Roots");
    }
 
    // If D < 0, it will be Imaginary Roots
    else {
        console.log("Imaginary Roots");
    }
}
 
// Function to check for all testcases
function checkForAllTestCase()
{
 
    console.log("Testcase\ta\tb\tc\tActual Output\n");
    let a, b, c;
    let testcase = 1;
    while (testcase <= 13) {
        if (testcase == 1) {
            a = 0;
            b = 50;
            c = 50;
        }
        else if (testcase == 2) {
            a = 1;
            b = 50;
            c = 50;
        }
        else if (testcase == 3) {
            a = 50;
            b = 50;
            c = 50;
        }
        else if (testcase == 4) {
            a = 99;
            b = 50;
            c = 50;
        }
        else if (testcase == 5) {
            a = 100;
            b = 50;
            c = 50;
        }
        else if (testcase == 6) {
            a = 50;
            b = 0;
            c = 50;
        }
        else if (testcase == 7) {
            a = 50;
            b = 1;
            c = 50;
        }
        else if (testcase == 8) {
            a = 50;
            b = 99;
            c = 50;
        }
        else if (testcase == 9) {
            a = 50;
            b = 100;
            c = 50;
        }
        else if (testcase == 10) {
            a = 50;
            b = 50;
            c = 0;
        }
        else if (testcase == 11) {
            a = 50;
            b = 50;
            c = 1;
        }
        else if (testcase == 12) {
            a = 50;
            b = 50;
            c = 99;
        }
        else if (testcase == 13) {
            a = 50;
            b = 50;
            c = 100;
        }
        process.stdout.write("\ttestcase\t" + a + "\t" + b + "\t" + c + "\t");
        nature_of_roots(a, b, c);
        testcase++;
    }
}
 
// Driver Code
checkForAllTestCase();
 
 
// This code is contributed bt phasing17


Output:

Testcase    a    b    c    Actual Output

    1    0    50    50    Not a Quadratic Equation

    2    1    50    50    Real Roots

    3    50    50    50    Imaginary Roots

    4    99    50    50    Imaginary Roots

    5    100    50    50    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    50    50    0    Real Roots

    11    50    50    1    Real Roots

    12    50    50    99    Imaginary Roots

    13    50    50    100    Imaginary Roots

Time complexity: O(1)
Auxiliary space: O(1)

Feeling lost in the world of random DSA topics, wasting time without progress? It’s time for a change! Join our DSA course, where we’ll guide you on an exciting journey to master DSA efficiently and on schedule.
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 neveropen!

RELATED ARTICLES

Most Popular

Dominic
32264 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6632 POSTS0 COMMENTS
Nicole Veronica
11800 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11859 POSTS0 COMMENTS
Shaida Kate Naidoo
6749 POSTS0 COMMENTS
Ted Musemwa
7025 POSTS0 COMMENTS
Thapelo Manthata
6698 POSTS0 COMMENTS
Umr Jansen
6718 POSTS0 COMMENTS