Our Android App Also Got an Upgrade. Download now!

C program Boundary Value Analysis - Nature of roots of a quadratic equation

bva_quadratic.txt

File size: 1.21 KB

File content type: text/plain

Category: Practical Files

Subject: Software Testing and Quality Assurance

#include <stdio.h>
#define MIN 0
#define MAX 100

void test(int a, int b, int c) {
	char *output = "";
	if(a == 0) {
		output = "Not a Quadratic Equation\n";
	} else {
		int d = b*b - 4*a*c;
		if(d < 0) {
			output = "Imaginary Roots\n";
		} else if(d == 0) {
			output = "Real and Equal Roots\n";
		} else {
			output = "Real and Distinct Roots\n";
		}
	}
	
	printf("%d\t%d\t%d\t%s",a,b,c,output);
}

int main(void) {
	int min, max;
	
	printf("Enter range\n");
	scanf("%d%d",&min,&max);
	
	if(min < MIN || max > MAX) {
		printf("Invalid range\n");
		return 0;
	}
	
	int nominal = (min + max)/2;
	int values[] = {min, min+1, nominal, max-1, max};
	
	printf("a\tb\tc\tOutput\n");
	// fix variable b,c to nominal value and change values of a
	for(int i=0;i<5;i++) {
		test(values[i],nominal, nominal);
	}
	
	//fix variable a,c to nominal value and change values of b
	for(int i=0;i<5;i++) {
		// skip the case where all three values of a,b,c are same
		// since it was already included once in above loop
		if(values[i] != nominal)
		test(nominal, values[i], nominal);
	}
	
	// fix variable a,b to nominal values and change values of c
	for(int i=0;i<5;i++) {
		if(values[i] != nominal)
		test(nominal, nominal, values[i]);	
	}
	
	return 0;
}

STQA nature of roots program.

Last Updated: July 16, 2022