ST_Lab
ST_Lab
ST_Lab
(KCS 751A)
LABORATORY MANUAL
B.TECH, 4th Year, Semester - VII
COMPUTER SCIENCE
&
ENGINEERING
This manual is intended for the 4th year students of Computer Science & Engineering in the subject of
Software Testing. This manual typically contains practical/lab sessions related Software Testing
covering various aspects related the subject to enhanced understanding.
Students are advised to thoroughly go through this manual rather than only topics mentioned in the
syllabus as practical aspects are the key to understanding and conceptual visualization of theoretical
aspects covered in the books.
M2. To develop technocrats with creative skills and leadership qualities, to solve local and global
challenges.
M3. To impart human values and ethics in students, to make them socially and eco-friendly
responsible.
Vision of the Department
“To produce globally competent professionals having social values and commitment to serve the
global needs with the ability to work in an interdisciplinary environment.”
M2. "To create a conducive environment in which students can explore computational problems and
analyze them to identify the optimal solutions."
M3. "To strive for continual enhancement of technical knowledge & innovation through industry
interface to accomplish global needs."
PEO2: Students must be able to analyze, design, and implement the latest technology-driven projects.
PEO3: Students must be able to work in a collaborative environment and understand the ethical,
social, and economic impact of their work.
Program Outcomes (POs)
PO’s An Engineering Graduate of the Department of Computer Science and Engineering Program will
be able to demonstrate:
PO11 PROJECT MANAGEMENT AND FINANCE: Apply the knowledge and understanding of
engineering and management principles to design, planned budget and propose IT project for an
identified need within a specific scope.
PO12 LIFE-LONG LEARNING: Developed confidence to acquire new knowledge in the computing
discipline and to engage in life-long learning.
PSO 1: Able to design and implement the data structures and algorithms to deliver quality software
products.
PSO 2: Able to apply Artificial Intelligence and Machine Learning concepts to solve society-related
needs.
Aims
The aim of this course is to identify the need of software testing in current industry scenario, techniques and
tools in area of software testing and to detect software failures so that defects may be discovered and
corrected. Practical experimentation with the language is strongly encouraged.
Course Objectives
Program: -
#include<stdio.h>
#include<conio.h>
int main( )
{
int a,b,c,c1,c2,c3;
do
{
printf("enter the sides of triangle\n");
scanf("%d%d%d",&a,&b,&c);
c1=((a>=1) && (a<=10));
c2=((b>=1) && (b<=10));
c3=((c>=1) && (c<=10));
if(!c1)
printf("value of a is out of range");
if(!c2)
printf("value of b is out of range");
if(!c3)
printf("value of c is out of range");
}
while(!c1 || !c2 || !c3);
if((a+b)>c && (b+c)>a && (c+a)>b)
{
if(a==b && b==c)
printf("Triangle is equilateral\n");
else if (a!=b && b!=c && c!=a)
printf("Triangle is scalene\n");
else
printf("Triangle is isosceles\n");
}
else printf("Triangle cannot be formed \n");
getch( ); return 0;
}
INPUT/OUTPUT
Test cases using Boundary value analysis for Triangle Program
Testcases Inputs
Description Output Comments
A B C
BVA1 Enter the values of a(nom),b(nom) and 5 5 1 Isosceles Valid
c(min)
BVA 2 Enter the values of a(nom),b(nom) and 5 5 2 Isosceles Valid
c(min+)
BVA 3 Enter the values of a(nom),b(nom) and 5 5 5 Equilateral Valid
c(nom)
BVA 4 Enter the values of a(nom),b(nom) and 5 5 9 Isosceles Valid
c(max-)
BVA 5 Enter the values of a(nom),b(nom) and 5 5 10 Triangle cannot be Valid
c(max) formed
BVA 6 Enter the values of a(nom),b(min) and 5 1 5 Isosceles Valid
c(nom)
BVA 7 Enter the values of a(nom),b(min+) 5 2 5 Isosceles Valid
and c(nom)
BVA 8 Enter the values of a(nom),b(max-) 5 9 5 Isosceles Valid
and c(nom)
BVA 9 Enter the values of a(nom),b(max) and 5 10 5 Triangle cannot be Valid
c(nom) formed
BVA 10 Enter the values of a(min),b(nom) and 1 5 5 Isosceles Valid
c(nom)
BVA 11 Enter the values of a(min+),b(nom) 2 5 5 Isosceles Valid
and c(nom)
BVA 12 Enter the values of a(max-),b(nom) 9 5 5 Isosceles Valid
and c(nom)
BVA 13 Enter the values of a(max),b(nom) and 10 5 5 Triangle cannot be Valid
c(nom) formed
Experiment No. 2
Aim: Design, develop, code and run the program to implement the NextDate function. Analyze it from the
perspective of boundary value testing, derive different test cases, execute these test cases and discuss the
test results.
Program: -
#include<stdio.h>
int check(int day,int month)
{
if((month==4||month==6||month==9 ||month==11) && day==31) return 1;
else
return 0;
}
int isleap(int year)
{
if((year%4==0 && year%100!=0) || year%400==0) return 1; else
return 0;
}
int main()
{
int day,month,year,tomm_day,tomm_month,tomm_year; char flag;
do
{ flag='y'; printf("\nenter the today's date in the form of dd mm yyyy\n");
scanf("%d%d%d",&day,&month,&year);
tomm_month=month;
tomm_year= year;
if(day<1 || day>31)
{
printf("value of day, not in the range 1...31\n");
flag='n';
}
if(month<1 || month>12)
{
printf("value of month, not in the range 1. .. 12\n");
flag='n';
}
else if(check(day,month))
{
printf("value of day, not in the range day<=30");
flag='n';
}
if(year<=1812 || year>2015)
{
printf("value of year, not in the range 1812. ...... 2015\n");
flag='n';
}
if(month==2)
{
if(isleap(year) && day>29)
{
printf("invalid date input for leap year");
flag='n';
}
else if(!(isleap(year))&& day>28)
{
printf("invalid date input for not a leap year");
flag='n';
}
}
}
while(flag=='n');
switch (month)
{
case 1: case 3: case 5: case 7: case 8: case 10:if(day<31) tomm_day=day+1;
else
{
tomm_day=1;
tomm_month=month+1;
}
break; case 4: case 6: case 9: case 11: if(day<30) tomm_day=day+1;
else
{
tomm_day=1; tomm_month=month+1;
}
break; case 12: if(day<31) tomm_day=day+1; else
{
tomm_day=1;
tomm_month=1; if(year==2015)
{
printf("the next day is out of boundary value of year\n");
tomm_year=year+1;
}
else
tomm_year=year+1;
}
break; case 2: if(day<28)
tomm_day=day+1;
INPUT/OUTPUT
Considering Date program, we have three variables day, month and year.
month 1 2 6 11 12
Test Inputs
cases Description Output Comments
DD MM YY
BVA1 15 6 1812 16/6/1812 Valid
Enter the values for
day(nom),month(nom) and year(min)
BVA2 15 6 1813 16/6/1813 Valid
Enter the values for
day(nom),month(nom) and year(min+)
Enter the values for 15 6 1914 16/6/1914
BVA 3 day(nom),month(min) and year(nom) Valid
Enter the values for 15 6 2014 16/6/2014
BVA4 day(nom),month(nom) and year(max-) Valid
Enter the values for 15 6 2015 16/6/2015
BVA5 day(nom),month(nom) and year(max) Valid
Enter the values for 15 1 1914 16/1/1914
BVA6 day(nom),month(min) and year(nom) Valid
Enter the values for 15 2 1914 16/2/1914
BVA7 day(nom),month(min+) and year(nom) Valid
Enter the values for 15 11 1914 16/11/1914
BVA8 day(nom),month(max-) and year(nom) Valid
Enter the values for 15 12 1914 16/12/1914
BVA9 day(nom),month(max) and year(nom) Valid
Enter the values for 1 6 1914 2/6/1914
BVA10 day(min),month(nom) and year(nom) Valid
Enter the values for 2 6 1914 3/6/1914
BVA11 day(min+),month(nom) and year(nom) Valid
Enter the values for day(max- 30 6 1914 1/7/1914
BVA12 ),month(nom) and year(nom) Valid
BVA13 Enter the values for 31 6 1914 Day out of Valid
day(max),month(nom) and year(nom) rangefor
the
month
Experiment No. 3
Aim: Design and develop a program to solve the triangle problem defined as follows: Accept three integers
which are supposed to be the three sides of a triangle and determine if the three values represent an
equilateral triangle, isosceles triangle, scalene triangle, or they do not form a triangle at all. Assume the
upper limit for the size of any side is 10. Derive test cases for your program based on equivalence class
partitioning, execute the test cases and discuss the results.
Program:
#include<stdio.h> #include<conio.h>
int main()
{
int a,b,c,c1,c2,c3;
do
{
printf("enter the sides of triangle\n"); scanf("%d%d%d",&a,&b,&c); c1=((a>=1) && (a<=10));
c2=((b>=1) && (b<=10));
c3=((c>=1) && (c<=10)); if(!c1)
printf("value of a is out of range"); if(!c2)
printf("value of b is out of range"); if(!c3)
printf("value of c is out of range");
}while(!c1 || !c2 || !c3);
if((a+b)>c && (b+c)>a && (c+a)>b)
{
Inputs Expected
Test cases Description output Comments
A B C
Enter the valid values for a, b and
WN/SN1 5 5 5 Equilateral Valid
c from outputequivalence classes.
Enter the valid values for a, b and
WN/SN2 c from outputequivalence classes. 5 5 3 Isosceles Valid
Enter the valid values for a, b and
WN/SN3 c from outputequivalence classes. 5 3 4 Scalene Valid
Enter the valid values for a, b and Triangle
WN/SN4 c from outputequivalence classes. 10 1 1 cannotbe Valid
formed
Weak Robust
Testcases Inputs
Description Expected output Comments
A B C
WR 1 Enter the valid values for b and c -1 5 5 Value of a is notin a Triangle
from outputequivalence classes range cannot be
and invalid value for a. formed
WR 2 Enter the valid values for a and 3 -1 4 Value of b is not Triangle
c from output in a range cannot be
equivalence classes and invalid formed
value for b.
WR 3 Enter the valid values for a and b 10 10 -1 Value of c is notin a Triangle
from outputequivalence classes range cannot be
and invalid value for c. formed
WR 4 Enter the valid values for b and c 11 3 3 Value of a is not in a Triangle
from outputequivalence classes range cannot be
and invalid value for a. formed
WR 5 Enter the valid values for a and 5 11 6 Value of b is not Triangle
c from output in a range cannot be
equivalence classes and invalid formed
value for b.
WR 6 Enter the valid values for a and b 9 10 11 Value of c is notin a Triangle
from outputequivalence classes range cannot be
and invalid value for c. formed
Strong Robust
Inputs
Test Description Expected Comments
cases A B C output
SR 1 Enter the valid value for b from output -1 3 -1 Values of a and Triangle cannot
equivalenceclasses and invalid values care not in range beformed
for a and c.
SR 2 Enter the valid value for a from output 5 -1 -1 Values of b and Triangle cannot
equivalenceclasses and invalid values care not in range beformed
for b and c.
SR 3 Enter the valid value for c from output -1 -1 10 Values of a and Triangle cannot
equivalenceclasses and invalid values bare not in range beformed
for a and b.
SR 4 Enter the valid value for a from output 7 11 11 Values of b and Triangle cannot
Aim: Design, develop, code and run the program to implement the NextDate function. Analyze it
from the perspective of equivalence class value testing, derive different test cases, execute these test
cases and discuss the test results.
Inputs
Test Description Output Comments
cases DD MM YY
WN/SN1 Enter valid values for day, 12 2 1990 13/2/1990 Valid
month and year from
equivalence classes.
Weak Robust
Testcases Inputs
Description Output Comments
DD MM YY
WR1 Enter valid values for month and year from -1 6 1992 Day out of Valid
equivalenceclasses and invalid value for range
day.
Enter valid values for day and year 15 -1 1992 Month out Valid
WR2 from equivalenceclasses and invalid of range
value for month.
Enter valid values for day and month from 15 6 1811 Year out of Valid
WR3 equivalenceclasses and invalid value for range
year.
Enter valid values for month and year from 32 6 1992 Day out of Valid
WR4 equivalenceclasses and invalid value for range
day.
Enter valid values for day and year 15 13 1992 Month out Valid
WR5 from equivalenceclasses and invalid of range
value for month.
Enter valid values for day and month from 15 6 2016 Year out of Valid
WR6 equivalenceclasses and invalid value for range
year.
Strong Robust
Test Inputs
cases Description Output Comments
DD M YY
M
SR1 Enter valid values for month and -1 6 1992 Day out of Valid
year from equivalenceclasses and range
invalid value for day.
Enter valid values for day and year 15 -1 1992 Month out of Valid
SR2 from equivalenceclasses and invalid range
value for month.
SR3 Enter valid values for day and 15 6 1811 Year out of Valid
month from equivalenceclasses range
and invalid value for year.
SR4 Enter valid value for year from -1 -1 1992 Day, Month out Valid
equivalence classes andinvalid ofrange
values for day and month.
SR5 Enter valid value month for from -1 6 1811 Day, Year out Valid
equivalence classesand invalid of range
values for day and year.
SR6 Enter valid value for day from 15 -1 1811 Month, Year out Valid
equivalence classes andinvalid ofrange
values for month and year.
SR7 Enter valid values for month and 32 6 1992 Day out of Valid
year from equivalenceclasses and range
invalid value for day.
SR8 Enter valid values for day and year 15 13 1992 Month out of Valid
from equivalenceclasses and invalid range
value for month.
SR9 Enter valid values for day and 15 6 2016 Year out of Valid
month from equivalenceclasses range
and invalid value for year.
SR10 Enter valid value for year from 32 13 1992 Day, Month out Valid
equivalence classes andinvalid ofrange
values for day and month.
SR11 Enter valid value month for from 32 6 2016 Day, Year out Valid
equivalence classesand invalid of range
values for day and year.
SR12 Enter valid value for day from 15 13 2016 Month, Year Valid
equivalence classes andinvalid out ofrange
values for month and year.
SR13 Enter invalid values for day, month -1 -1 1811 Day, Month, Valid
and year. Year outof
range
SR14 Enter invalid values for day, month 32 13 2016 Day, Valid
and year. Month,
Year outof
range
Experiment No. 5
Aim: Design and develop a program to solve the triangle problem defined as follows: Accept three
integers which are supposed to be the three sides of a triangle and determine if the three values represent
an equilateral triangle, isosceles triangle, scalene triangle, or they do not form a triangle at all. Derive test
cases for your program based on decision table approach, execute the test cases and discuss the results.
Program:
#include<stdio.h>
#include<conio.h>
int main()
{
int a,b,c;
printf("enter the sides of triangle\n");
scanf("%d%d%d",&a,&b,&c);
if((a+b)>c && (b+c)>a && (c+a)>b)
{
if(a==b && b==c)
printf("triangle is equilateral\n");
else if (a!=b && b!=c && c!=a)
printf("triangle is scalene\n");
else
printf("triangle is isosceles\n");
}
else
printf("triangle cannot be formed\n");
return 0;
}
INPUT/ OUTPUT
R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11
C1: a<b+c F T T T T T T T T T T
Conditions C2: b<c+a -- F T T T T T T T T T
C3: c<a+b -- -- F T T T T T T T T
C4: a=b -- -- -- T T F F F T T F
Actions C5: b=c -- -- -- T F T F F T F T
C6: c=a -- -- -- T F F T F F T T
A1: Not a x x x
triangle
A2: x
Equilateral
A3: x x x
Isosceles
A4: x
Scalene
A5: x x x
Impossible
Inputs
Testcases Description A B C Output Comments
Case 1 Enter the values of a, b and c such that value of a is 7 2 3 Not a Valid
greaterthan sum of b and c. triangle
Case 2 Enter the values of a, b and c such that value of b is 2 8 3 Not a Valid
greaterthan sum of a and c. triangle
Case 3 Enter the values of a, b and c such that value of c is 2 4 7 Not a Valid
greaterthan sum of a and b. triangle
Case 4 Enter the values of a, b and c such that values of a,b 5 5 5 Equilater Valid
and care equal. al
Case 5 Enter the values of a, b and c Such that value of a is 4 4 3 Isosceles Valid
equalto value of b.
Case 6 Enter the values of a, b and c such that value of b is 2 5 5 Isosceles Valid
equalto value of c.
Case 7 Enter the values of a, b and c such that value of a is 6 2 6 Isosceles Valid
equal tovalue of c.
Case 8 Enter the values of a, b and c such that values of a,b 2 3 4 Scalene Valid
and care different.
Case 9 Enter the values of a, b and c such that value of a is ? ? ? Impossible Valid
equal tovalue of b and c but value of b is not equal to
c.
Enter the values of a, b and c such that value of b is
Case 10 equal to value of c and value of c is equal to a but ? ? ? Impossible Valid
value of a not equalto b.
Enter the values of a, b and c such that value of a is
Case 11 equal to b and value of b is equal to value of c but ? ? ? Impossible Valid
value of a notequal to c.
Experiment No. 6
Aim: Design, develop a code to solve the commission problem. Analyse it from the perspective of decision
tablebased testing, derive different test cases, execute these test cases and discuss the test results.
RULES R1 R2 R3 R4 R5 R6 R7 R8 R9
barrels
IDT3 Enter the valid values for locks, 20 20 96 1500 175 valid
stocks andinvalid value for barrels Invalid no.of barrels
IDT4 Enter the valid values for locks and 20 -1 20 1400 160 valid
barrelsand invalid value for stocks Invalid no.of stocks
IDT5 Enter the valid values for locks, 20 20 20 2000 260 valid
stocks andbarrels Calculates sales and
commission
IDT6 Enter the invalid values for locks, -2 81 -1 0 0 valid
stocks andbarrels Invalid no.of locks,
Stocks andbarrels.
IDT7 Enter the valid value for stocks and -2 20 91 600 60 valid
invalidvalues for locks and barrels Invalid no.of locks
and barrels
IDT8 Enter invalid input for locks and 71 -1 20 500 50 valid
stocks andvalid input for barrels Invalid no.of locks
and stocks
IDT9 Enter the invalid value for locks and -3 20 20 1100 115 valid
validvalues for stocks and barrels Invalid no.of locks
RULES R1 R2 R3
Program:
#include<stdio.h>
#include<conio.h> int main()
{
int c1,c2,c3,temp;
int locks,stocks,barrels,totallocks,totalstocks,totalbarrels;
float lockprice,stockprice,barrelprice,locksales,stocksales,barrelsales,sales,com;
lockprice=45.0;
stockprice=30.0;
barrelprice=25.0;
totallocks=0;
totalstocks=0;
totalbarrels=0;
clrscr();
printf("Enter the number of locks and to exit press -1\n");
scanf("%d",&locks);
while(locks != -1)
{
c1=(locks<=0 || locks>70);
printf("\nEnter the number of stocks and barrels\n");
scanf("%d %d",&stocks,&barrels);
c2=(stocks<=0 || stocks>80);
c3=(barrels<=0 || barrels>90);
if(c1)
printf("\nValue of locks are not in the range of 1. .. 70\n");
else
{
temp=totallocks+locks;
if(temp>70)
printf("New totallocks = %d not in the range of 1 .... 70\n",temp);
else
totallocks=temp;
}
printf("Total locks = %d",totallocks);
if(c2)
printf("\n Value of stocks not in the range of 1 .... 80\n");
else
{
temp=totalstocks+stocks;
if(temp>80)
printf("\nNew total stocks = %d not in the range of 1. .. 80",temp);
else totalstocks=temp;
}
printf("\nTotal stocks = %d",totalstocks); if(c3)
printf("\n Value of barrels not in the range of 1 ... 90\n");
else
{
temp=totalbarrels+barrels; if(temp>90)
printf("\nNew total barrels = %d not in the range of 1 ... 90\n",temp); else
totalbarrels=temp;
}
printf("\nTotal barrels=%d", totalbarrels); printf("\nEnter the number of locks and to exit press -
1\n");
scanf("%d",&locks);
}
printf("\n Total locks = %d",totallocks);
printf("\n Total stocks = %d",totalstocks);
printf("\n Total barrels = %d",totalbarrels);
locksales=totallocks*lockprice;
stocksales=totalstocks*stockprice;
barrelsales=totalbarrels*barrelprice;
sales=locksales+stocksales+barrelsales;
printf("\n Total sales = %f",sales); if(sales>1800)
{ com=0.10*1000; com=com+(0.15*800);
com=com+0.20*(sales-1800);
}
else if(sales>1000)
{
com=0.10*1000;
com=com+0.15*(sales-1000);
}
else com=0.10*sales;
printf("\nCommission = %f",com);
getch();
return 0;
}
lockprice 8 63
stockprice 9 64
barrelprice 10 65
Variable
Te Description s DU paths DC
s path
tid (beginnin ?
g ,end
nodes)
Check for lockprice 8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,26,27,28,2
variable 9,
1 DEF(ocklprice,8) <8,63 31,32,33,34,35,37,38,39,40,42,43,44,45,46,48,49 YES
>
And ,50,51,53,54,55,56,57,58,59,60,61,62,63
USE(lockprice,63)
Check for 9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,26,
stockprice
2 variable <9,64 27,28,29,31,32,33,34,35,37,38,39,40,42,43,44,45, YES
DEF(stockprice,9) >
And 46,48,49,50,51,53,54,55,56,57,58,59,60,61,62,63,64
USE(stockprice,64)
Check for 10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,26,27,28,
barrelprice
3 variable <10,65 29,31,32,33,34,35,37,38,39,40,42,43,44,45,46, YES
DEF(barrelprice,10) >
And 48,49,50,51,53,54,55,56,57,58,59,60,61,62,63,64,65
USE(barrelprice,65)
<11,34 11,12,13,14,15,16,17,18,19,20,21,22,23,24,26,27,28,29,31, NO
> 32,33,34
Check for
totallocks
4 variable NO
<11,60 11,12,13,14,15,16,17,18,19,20,21,22,23,24,26,27,28,29,31,32,
DEF(totallocks,1 33,34,35,37
>
1,32) ,38,39 ,40,42,43
,44,45,46,48,49,50,51,53,54,55,56,57,58,59,60
And
USE(totallocks,
28,34,60,63) 11,12,13,14,15,16,17,18,19,20,21,22,23,24,26,27,28,29,31,32,
33,34,35,37
<11,63 ,38,39 ,40,42,43 NO
> ,44,45,46,48,49,50,51,53,54,55,56,57,58,59,60,61,62,63
32,33,34,35,37,38,39,40,42,43,44,45,46,48,49,50,51,53,54,55, YES
<32,28
56,57,58,17
>
,18,19,20,21,22,23,24,26,27,28
YES
<32,34> 32,33,34
<32,60> 32,33,34,35,37,38,39,40,42,43,44,45,46,48,49,50,51, YES
53,54, 55,56,57,58,59, 60
<32,63> 32,33,34,35,37,38,39,40,42,43,44,45,46,48,49,50,51
, 53,54,55,56,57,58,59 ,60,61,62,63 YES
<12,39 12,13,14,15,16,17,18,19,20,21,22,23,24,26,27,28,29,31,3 YES
> 2,33,34,35,37,38,39
<12,45 12,13,14,15,16,17,18,19,20,21,22,23,24,26,27,28,29 NO
>
,31,32,33,34,35,37,38,39,40,42,43,44,45
YES
<43,61> 43,44,45,46,48,49,50,51,53,54,55,56,57,58,59,60,61
YES
<43,64> 43,44,45,46,48,49,50,51,53,54,55,56,57,58,59,60,61,62,6
3,64
<13,56> 13,14,15,16,17,18,19,20,21,22,23,24,26,27,28,29 NO
,31,32,33,34,35,37,38,39,40,42,43,44,45,46,48,49
,50,51,53,54,55,56
<13,62> NO
Check for
13,14,15,16,17,18,19,20,21,22,23,24,26,27,28,29,
totalbarrels
variable 31,32,33,34,35,37,38,39,40,42,43,44,45,46,48,49,
6 DEF(totalbarrels,1
50,51,53,54,55,56,57,58,59,60,61,62
3,54)
And
USE(totalbarrels,
50,56,62,65) <13,65> 13,14,15,16,17,18,19,20,21,22,23,24,26,27,28,29,
31,32,33,34,35,37,38,39,40,42,43,44,45,46,48,49, NO
50,51,53,54,55,56,57,58,59,60,61,62,63,64,65
Check for
11 stocksales variable <64,66> 64,65,66 YES
DEF(stocksales,64
)
And
USE(stocksales,66)
Check for
12 barrelsales <65,66> 65,66 YES
variable
DEF(barrelsales,6
5)
And
USE(barrelsales,66)
Check for sales <66,67> 66,67 YES
variable <66,68> 66,67,68 YES
1 DEF(sales,66)
<66,72> 66,67,68,69,70,71,72 YES
3 And
YES
USE(sales,67,68,72, <66,74> 66,67,68,74
74,77,8 0) <66,77> 66,67,68,74,75,76,77 YES
<66,80> 66,67,68,74,79,80 YES
<70,71> 70,71 NO
<70,72> 70,71,72 NO
<70,81> 70,71,72,73,81
<71,72> 71,72 NO
<71,81> 71,72,73,81 NO
14 <72,81> 72,73,81
NO
<76,77> 76,77
Check for <76,81> 76,77,78,81 YES
commission <77,81> 77,78,81 NO
variable <80, 80,81
81> NO
DEF(com,70,71,72,
76,77,8 0) YES
And Y
USE(com,71,72,77, E
81)
S
Note
In above Du-Paths, some paths like
<70,77>,<71,71>,<71,77>,<72,71>,<72,72>,<72,77>,<76,71>,<76,72>,<77,71>,<77, 71>,<77,77>,
<80,70>,<80,72>,<80,77>,<80,77> are not possible to be formed. So they are not considered in above table.
Experiment No. 8
Aim: Design, develop a code to implement the binary search algorithm. Determine the basis paths and
using them derive different test cases, execute these test cases and discuss the test results.
Program:
#include<stdio.h>
int binsrc(int x [ ],int low,int high,int key)
{
int mid;
while(low<=high)
{
mid=(low+high)/2
;
if(x[mid]==key)
return mid;
elseif(x[mid]<key
) low=mid+1;
else high=mid-1;
}
return -1;
}
int main()
{
int a[20],key,i,n,succ;
printf("Enter the n value up to max of 20");
scanf("%d",&n);
if(n>0)
{
printf("enter the elements in ascending order\n");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("enter the key element to be searched\n");
scanf("%d",&key);
succ=binsrc(a,0,n-1,key);
if(succ>=0)
printf("Element found in position = %d\n",succ+1);
else
printf("Element not found \n");
}
else
printf("Number of element should be greater than zero\n");
return 0; }
Program Graph
1 2 3 4
1
4
7
8 9
1
1 1
5 1
0
1
2
1
3
McCabe’s Basis path method
Considering DD-Path graph of the program, first we need to find Baseline path. A baseline path consists of
maximum number of decision nodes. Using Baseline path we start flipping each decision node for finding
newpaths. Considering Binary search program
Baseline Path: A B C D E F H B J K.
Nodes which are bold and large are decision nodes. Now start flipping each decision node.
Flipping at B : A B J K.
Flipping at D : A B C D I K.
Flipping at E : A B C D E G H B J.
Cyclomatic Complexity
V(G) =e-n+2p
Test Input
Cases Description N Array elements Key Expected Comment
Output
Infeasible
TC1 Enter the basis because Valid
2 {5,10} 4
path consisting low>high
1 {10} 5
ofall decision means from B
nodes to J
ABCDEFHBJK. then K which
means no
elements left
which is not
true in any
case.
0 Infeasible
Enter the basis because
TC2 path --------- ---- low>high Invalid
consisting means from B
ofall decision to J then K
nodes ABJK. which means
no elements
left which
isnot true in
any case.
Aim: Design, develop a code to implement the Quicksort algorithm. Determine the basis paths and using
them derive different test cases, execute these test cases and discuss the test results.
Program:
#include<stdio.h>
void quicksort(int x[10],int first,int last)
{
int temp,pivot,i,j;
if(first<last)
{
pivot=first;
i=first;
j=last;
while(i<j)
{
while(x[i]<=x[pivot] && i<last)
i++;
while(x[j]>x[pivot])
j--;
K. 15 if(i<j)
{
temp=x[i];
x[i]=x[j];
x[j]=temp;
}
}
temp=x[pivot];
x[pivot]=x[j];
x[j]=temp;
quicksort(x,first,j-1);
quicksort(x,j+1,last);
}
}
int main()
{
int a[20],i,key,n; printf("enter the size of the array max
of 20 elements");
scanf("%d",&n); if(n>0)
{
printf("enter the elements of the array");
for(i=0;i<n;i++)
scanf("%d",&a[i]); quicksort(a,0,n-1);
printf("the elements in the sorted array is:\n");
for(i=0;i<n;i++) print f("%d\t",a[i]);
}
else
printf(“size of array is
invalid\n”);
}
Cyclomatic Complexity
V(G) =e-n+2p
Or
V(G) =e-n+p (for closed closed graph)Where, e is number of edges in DD-Path graph. n is number of
nodes in DD-Path graph. p is number of regions connected.(always 1)
Number of linearly independent paths (Test cases) for a given graph G = 23-17+(1)
= 6+1
= 7 Test cases
Program graph
DD path graph
NODES DDPATHS
1 A
2-3 B
4 C
5-8 D
9 E
10 F
11 G
12 H
13 I
14 J
15 K
16-20 L
21 M
22-25 N
26 P
27 Q
28 O
Baseline Path: A BC DE FG I K M E N A B C O P A B C O.
Nodes which are bold and large are decision nodes. Now start flipping each decision node.
Flipping at C : A B C O.
Flipping at E : A B C D E N A B C O.
Flipping at G : A B C D E F G H G I K M E N A B C O.
Flipping at I :A B C D E F G I J I K M E N A B C O.
Flipping at K : A B C D E F G I K L M E N A B C O.
Flipping at P :A B C D E F G I K L M E N A B C O P A B C O.
Test Number of
Cases Description elements Array Elements Comment
(n)
Enter the basis path consisting of all Infeasible because path
TC1 decisionnodes ---- from G to I meansno Invalid
ABCDEFGIKMENABCOPABCO. elements in array.
Enter the basis path consisting of all
TC2 1 {9} Valid
decisionnodes ABCO.
Path C to D indicates
Enter the basis path consisting of all ---- if(first<last) is condition Invalid
TC3 decisionnodes ABCDENABCO. is true. So at first iteration
while(x[i]<=x[pivot]&&i
< last) condition also
should be true and path E
to F should be present.
But we have
EN so Infeasible
Enter the basis path consisting of all
TC4 decisionnodes 2 {5,4 } Valid
ABCDEFGHGIKMENABCO.
Note
If given array contains a single element, then first=last, if(first<last) condition is true indicates there are
more than one elements in the given array. Even when there will be single element
While(x[i]<=x[pivot]&&i<last) conditionwill get executed at least once, because x[i]=x[pivot] is also
considered. So path there should be one path G to H present for any feasible solution. So in above table
paths containing G to I are all infeasible.
Experiment No.10
Aim: Design, develop a code to implement an absolute letter grading procedure, making suitable
assumptions. Determine the basis paths and using them derive different cases, execute these test cases and
discuss the test results.
Program:
#include<stdio.h>
#include<conio.h>
int main()
{
float per; char grade;
printf("enter the percentage\n");
scanf("%f",&per);
if(per>=90) grade='a';
else if((per>=80) && (per<90))
grade='b';
else if((per>=70) && (per<80))
grade='c';
else if((per>=60) && (per<70))
grade='d';
else grade='e';
switch(grade)
{
case 'a':
printf("excellent\n");
break;
case 'b':
printf("very good\n");
break;
case 'c':
printf("good\n");
break;
case 'd':
printf("above average\n");
break;
case 'e':
printf("satisfactory\n");
break;
}
printf("the percentage is %f and the grade is %c\n",per,grade);
return 0;
}
Cyclomatic Complexity
V(G) =e-n+2p
= 7+2
= 9 Test cases
Program graph
DD path graph
Nodes DD-Paths
1-6 A
7 B
8 C
9 D
10 E
11 F
12 G
13 H
14 I
15 J
16 K
17 L
18-19 M
20-21 N
22-23 O
24-25 P
26-27 Q
28 R
29-31 S
Finding Basis paths for Letter Grading program using McCabe’s method
Considering DD-Path graph of Absolute Letter grading program, Baseline path is formed by
considering alldecision nodes as shown below.
Baseline Path: AB D F H J K L M R S.
Nodes which are bold and large are decision nodes. Now start flipping each decision node.
Flipping at B : A B C K L M R S.
Flipping at D : A B D E K L M R S.
Flipping at F : A B D F G K L M R S.
Flipping at H : A B D F H I K L M R S.
Flipping at L : A B D F H J K L N R S.
A B D F H J K L O R S.
A B D F H J K L P R S.
A B D F H J K L Q R S.
Test Cases for Letter Grading Program
In above table we got test cases containing only Excellent and satisfactory type outputs. As we have five
typesof outputs in our program, three types of outputs (i.e., good, very good and above average) are left
untested. So for completeness we add three more tests for left out cases as shown below.