boundary value analysis – Programmerbay https://programmerbay.com A Tech Bay for Tech Savvy Fri, 20 Sep 2019 06:45:41 +0000 en-US hourly 1 https://wordpress.org/?v=6.5.5 https://programmerbay.com/wp-content/uploads/2019/09/cropped-without-transparent-32x32.jpg boundary value analysis – Programmerbay https://programmerbay.com 32 32 Design the test cases and test the program of Previous Date problem by using Boundary Value Analysis https://programmerbay.com/design-the-test-cases-and-test-the-program-of-previous-date-problem-by-using-boundary-value-analysis/ https://programmerbay.com/design-the-test-cases-and-test-the-program-of-previous-date-problem-by-using-boundary-value-analysis/#respond Fri, 20 Sep 2019 06:22:04 +0000 https://programmerbay.com/?p=5253 In this, we will test our program to check whether it can give the previous date as an output or not. We are supposing interval [2000,2050]  for year, [1,31] days for date, [1,12] for month. If we observe closely, we require to figure out whether the year input is a leap year or not between the selected year interval.

We will be applying Boundary Value Analysis to generate test cases.  The expected output can be  [Invalid date, previous Date].

Program:

#include<conio.h>
#include<stdio.h>
void main()
{
	int month,date,year, valid=-1,leap_year=-1;
	printf("please enter a date = ");
	scanf("%d",&date);
		printf("please enter a month = ");
	scanf("%d",&month);
		printf("please enter a year = ");
	scanf("%d",&year);
	if((date>0 && date<=31)&&(month>=1 && month<=12)&&(year>=2000 && year<=2050))
	{
	// finding given input is a leap year or not
	if((year%4)==0)
	{
		leap_year=1;
    if((year%100)==0)
    {
	if((year%400)==0)
	{
		leap_year=1;	
	}
	else
	{
	leap_year=-1;	
	}
}
}
if(month==2 && leap_year==1 && date >29)
valid=-1;
else if(month==2 && leap_year==-1 && date >28)
valid=-1;
else 
valid=1;
}

if((month==6 || month==4||month==9||month==11) && date>30)
valid=-1;

// validating & finding output


if(valid==1)
{
	printf("Entered date = %d-%d-%d",date,month,year);

if(date==1)
{
if(month==1)
{
date=31;
month=12;
year--;
}
else if(leap_year=1 && month==3)
{
	date=29;
	month--;
}
else if(leap_year==-1 && month==3)
{
	date=28;
	month--;
}
else if(month==2||month==4||month==6||month==8||month==9||month==11){
	date=31;
	month--;
}else{
	date=30;
	month--;
}
}
else{
	
	date--;
}
printf("\nPrevious date = %d-%d-%d \n",date,month,year);
}
else
printf("\n Not a valid date");

getch();
}

So, there will be 4N+ 1 test cases that is 4*3 +1 =13 in this case as we are using boundary value analysis.

Test IDDateMonthYearExpected OutputProgram OutputTest Outcome
116202531-5-202531-5-2025Pass
22620251-6-20151-6-2015Pass
3306202529-6-201529-6-2015Pass
43162025Invalid DateInvalid DatePass
5151202514-1-202514-1-2025Pass
6152202514-2-202514-2-2025Pass
71511202514-11-202514-11-2025Pass
81512202514-12-202514-12-2025Pass
9156200014-6-200014-6-2000Pass
10156200114-2-200114-2-2001Pass
11156204914-6-204914-6-2049Pass
12156205014-6-205014-6-2050Pass
13156202514-6-202514-6-2025Pass

Testing the program:

Invalid Date:

previous date

Previous Date:

previous date 1

]]>
https://programmerbay.com/design-the-test-cases-and-test-the-program-of-previous-date-problem-by-using-boundary-value-analysis/feed/ 0
Design the test cases and test the program of Quadratic Equation problem by using Boundary Value Analysis https://programmerbay.com/design-the-test-cases-and-test-the-program-of-quadratic-equation-problem-by-using-boundary-value-analysis/ https://programmerbay.com/design-the-test-cases-and-test-the-program-of-quadratic-equation-problem-by-using-boundary-value-analysis/#respond Thu, 19 Sep 2019 11:05:42 +0000 https://programmerbay.com/?p=5180 A quadratic equation is an equation which must be in the form of ax2+bx+c where a can’t be 0. we use Quadratic formula to find roots and check whether the roots are real or imaginary.

quadratic formula 1

This Quadratic formula is applied only when b2– 4ac >= 0.
such that,
If b2– 4ac > 0 , means the eqn. has more than one real roots
if b2– 4ac = 0 , represent equal or single root
if b2– 4ac <0, represents imaginary root
Lastly, if a is 0, then the equation would not be considered as a quadratic equation.

So, a quadratic equation can have [ Real, Equal, Imaginary, not quadratic ]

We are supposing interval [0,10] where our input values will fall in between this interval and we will create test cases using Boundary Value Analysis accordingly.

Program:

#include<conio.h>
#include<stdio.h>
#include<math.h>
void main()
{
float a,b,c,result;
printf(" ax^2 + bx + c, \n enter the values of a, b and c : = ");
scanf("%f %f %f", &a,&b,&c);

result = (b*b)- (4*a*c);
if(a==0)
printf("not quadratic");
else if(result>0)
{
result= sqrt(result);
printf("Real roots are, %f,%f \n",(-b-result)/(2*a),(-b+result)/(2*a));
}
else if(result==0)
{
result= sqrt(result);
printf("equal root, %f,%f \n",(-b)/(2*a),(-b)/(2*a));
}
else
{
printf("Imaginary root");
}

getch();
}

 

 

Testing the Program


Real roots:

  real 1

Equal roots:

equal roots 1

Not Quadratic

not quadratic 1

Imaginary :

imaginary 1

In Boundary Value Analysis, there will be 4N+1 test cases which means 4*3+1 = 13 test cases will be generated 
Test IDabcExpected OutputProgram OutputTested Outcome
1055Not QuadraticNot QuadraticPass
2155RealRealPass
3955ImaginaryImaginaryPass
41055ImaginaryImaginaryPass
5505ImaginaryImaginaryPass
6515ImaginaryImaginaryPass
7595ImaginaryImaginaryPass
85105EqualEqualPass
9550RealRealPass
10551RealRealPass
11559ImaginaryImaginaryPass
125510ImaginaryImaginaryPass
13555ImaginaryImaginaryPass

]]>
https://programmerbay.com/design-the-test-cases-and-test-the-program-of-quadratic-equation-problem-by-using-boundary-value-analysis/feed/ 0