ST Lab Manual
ST Lab Manual
1. Design and develop a program in a language of your choice 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 that the upper
limit for the size of any side is 10. Derive test cases for your program based on boundary-
value analysis, execute the test cases and discuss the results.
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c,c1,c2,c3;
char istriangle;
do
{
printf("\nenter 3 integers which are sides of triangle\n");
scanf("%d%d%d",&a,&b,&c);
printf("\na=%d\tb=%d\tc=%d",a,b,c);
if (!c2)
printf("\n the value of b=%d is not the range of permitted value",b);
if (!c3)
printf("\n the value of c=%d is not the range of permitted value",c); } while(!(c1 && c2 && c3));
else
istriangle ='n';
if (istriangle=='y')
if ((a==b) && (b==c))
printf("equilateral triangle\n");
else if ((a!=b) && (a!=c) && (b!=c))
printf("scalene triangle\n");
else
printf("isosceles triangle\n");
else
printf("Not a triangle\n");
getch();
Note : Also Perform robustness testing , worst case testing and special value testing .
2. Design, develop code and run the program in any suitable language to solve the
commission problem. Analyze it from the perspective of boundary value testing, derive
different test cases, execute these test cases and discuss the test results.
#include<stdio.h>
int main()
{
int locks, stocks, barrels, t_sales;
float commission;
printf("Enter the total number of locks");
scanf("%d",&locks);
printf("Enter the total number of stocks");
scanf("%d",&stocks);
printf("Enter the total number of barrelss");
scanf("%d",&barrels);
if ((locks <= 0) || (locks> 70)||(stocks <= 0) || (stocks > 80)||
(barrels <= 0) || (barrels > 90))
{
if(lock==-1)
Printf(“program terminates”);
else
printf("invalid input");
}
else
{
t_sales = (locks * 45) + (stocks * 30) + (barrels * 25);
if (t_sales <= 1000)
{
commission = 0.10 * t_sales;
}
else if (t_sales < 1800)
{
commission = 0.10 * 1000;
commission = commission + (0.15 * (t_sales - 1000));
}
else
{
commission = 0.10 * 1000;
commission = commission + (0.15 * 800);
commission = commission + (0.20 * (t_sales - 1800));
}
printf("The total sales is %d \n the commission is %f",t_sales,
commission);
}
return 0;
}
No of test cases=(4n+1, n is the number of inputs) {min, min+, norm, max, max-}
Case Input Expected output Actual output
id(BV Description status
Locks Stocks Barrels Sales Commission Sales Commission
A)
1 Barrels is min 35 40 1 2800 420.00
2 Barrels is min+ 35 40 2 2825 425.00
3 Barrels is norm 35 40 45 3900 640.00
4 Barrels is max 35 40 90 5025 865.00
5 Barrels is max- 35 40 89 5000 860.00
6 Stocks is min 35 1 45 2730 406.00
7 Stocks is min+ 35 2 45 2760 412.00
8 Stocks is norm 35 40 45 3900 640.00
9 Stocks is max 35 80 45 5100 880.00
10 Stocks is max- 35 79 45 5070 874.00
1 1 2 1 130 13
2 1 2 2 155 15.5
5 1 2 89 2330 326
6 1 1 1 100 10
7 1 1 2 125 12.5
10 1 1 89 2300 320
11 1 40 1 1270 140.5
12 1 40 20 1745 211.75
13 Cartesian product 1 40 45 2370 334
of 5 element set.
14 1 40 90 3495 559
15 1 40 89 3470 554
16 1 80 1 2470 354
17 1 80 2 2495 359
18 Cartesian product 1 80 45 3570 574
of 5 element set.
19 1 80 90 4695 799
20 1 80 89 4670 794
21 1 79 1 2440 348
22 1 79 2 2465 353
23 Cartesian product 1 79 45 3540 568
of 5 element set.
24 1 79 90 4665 793
25 1 79 89 4640 788
3. Design, develop, code and run the program in any suitable language to implement the
Next Date function. Analyze it from the perspective of boundary value testing, derive
different test cases, execute these test cases and discuss the test results.
#include<stdio.h>
main( )
{
int month[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int d,m,y,nd,nm,ny,ndays;
printf("enter the date,month,year");
scanf("%d%d%d",&d,&m,&y);
if((y%100!=0)&&(y%4==0)||(y%400==0))
{
Month[i]=29;
}
ndays=month [m-1];
(y<=1812) || ( y>2012) || (d<=0) || (d>ndays)|| (m<1) || ( m>12)
{
Printf(“invalid input”);
}
else
{
if(m==2)
{
if(y%100==0)
{
if(y%400==0)
ndays=29;
}
else
if(y%4==0)
ndays=29;
}
nd=d+1;
nm=m;
ny=y;
if(nd>ndays)
{
nd=1;
nm++;
}
if(nm>12)
{
nm=1;
ny++;
}
Pre Conditions :
Day:1<=day<=31{1,2,15,31,30}(min,min-,norm,max,max-)
Month:1<=month<=12 {1,2,6,12,11}
Year: 1812<=year<=2012 {1812,1813,1912,2012,2011}
Month:1<=month<=12 {1,2,6,12,11}
4. Design and develop a program in a language of your choice 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 that 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
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c,c1,c2,c3;
char istriangle;
do
{
printf("\nenter 3 integers which are sides of triangle\n");
scanf("%d%d%d",&a,&b,&c);
printf("\na=%d\tb=%d\tc=%d",a,b,c);
if (!c2)
printf("\nthe value of b=%d is not the range of permitted value",b);
if (!c3)
else
istriangle ='n';
if (istriangle=='y')
if ((a==b) && (b==c))
printf("equilateral triangle\n");
Dept. of ISE,DSATM Page 10
Software Testing Laboratory 18ISL67
else
printf("isosceles triangle\n");
else
printf("Not a triangle\n");
getch();
Brief Description : Check whether given value for a Equilateral, Isosceles , Scalene
triangle or can't form a triangle
Weak equivalence class testing
Case Description Input Expected output Actual status
id data output
a b c
1 Enter min value for a b and c 5 5 5 Equilateral triangle
2 Enter min value for a b and c 2 2 3 Isosceles triangle
3 Enter min value for a b and c 3 4 5 Scalene triangle
4 Enter min value for a b and c 4 1 2 Cannot form a triangle
5. Design, develop, code and run the program in any suitable language to solve the
commission problem. Analyze it from the perspective of equivalence class testing, derive
different test cases, execute these test cases and discuss the test results.
#include<stdio.h>
int main()
{
int locks, stocks, barrels, t_sales;
float commission;
printf("Enter the total number of locks");
scanf("%d",&locks);
printf("Enter the total number of stocks");
scanf("%d",&stocks);
printf("Enter the total number of barrelss");
scanf("%d",&barrels);
if ((locks <= 0) || (locks> 70)||(stocks <= 0) || (stocks > 80)||
(barrels <= 0) || (barrels > 90))
{
if(lock==-1)
Printf(“program terminates”);
else
printf("invalid input");
}
else
{
t_sales = (locks * 45) + (stocks * 30) + (barrels * 25);
if (t_sales <= 1000)
{
commission = 0.10 * t_sales;
}
else if (t_sales < 1800)
{
commission = 0.10 * 1000;
commission = commission + (0.15 * (t_sales - 1000));
}
else
{
commission = 0.10 * 1000;
commission = commission + (0.15 * 800);
commission = commission + (0.20 * (t_sales - 1800));
}
printf("The total sales is %d \n the commission is %f",t_sales,
commission);
}
return 0;
}
Pre-condition: lock = -1 to exit and 1< =lock < = 70, 1<=stock <=80 and 1<=barrel<=90.
Brief Description: The salesperson had to sell at least one complete rifle per month. Checking
boundary value for locks, stocks and barrels and commission
6. Design, develop, code and run the program in any suitable language to implement the
Next Date function. Analyze it from the perspective of equivalence class value testing,
derive different test cases, execute these test cases and discuss the test results.
#include<stdio.h>
main( )
{
int month[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int d,m,y,nd,nm,ny,ndays;
printf("enter the date,month,year");
scanf("%d%d%d",&d,&m,&y);
if((y%100!=0)&&(y%4==0)||(y%400==0))
{
Month[i]=29;
}
Ndays =month [m-1];
(y<1812) || ( y>2012) || (d<1) || (d>ndays)|| (m<1) || ( m>12)
{
Printf (“invalid input”);
}
else
{
if(m==2)
{
if(y%100==0)
{
if(y%400==0)
ndays=29;
}
else
if(y%4==0)
ndays=29;
}
nd=d+1;
nm=m;
ny=y;
if(nd>ndays)
{
nd=1;
nm++;
}
if(nm>12)
{
nm=1;
ny++;
}
printf("\n Given date is %d:%d:%d",d,m,y);
printf("\n Next day’s date is %d:%d:%d",nd,nm,ny);
}
return 0;
}
First Attempt
A first attempt at creating an equivalence relation might produce intervals Such as these:
At a first glance it seems that everything has been taken into account and our day, month and year
intervals have been defined well. Using these intervals we produce test cases using the four
different types of Equivalence Class testing.
Second Attempt
As said before the equivalence relation is vital in producing useful test cases and more time must
be spent on designing it. If we focus more on the equivalence relation and consider more greatly
what must happen to an input date we might produce the following equivalence classes:
Here month has been split up into 30 days (April, June, September and November), 31 days
(January, March, April, May, July, August, October and December) and February.
Day has been split up into intervals to allow months to have a different number of days; we also
have the special case of a leap year (February 29days).
Year has been split up into common years, leap years and the special case the year 2000 so we can
determine the date in the month of February. Here are the test cases for the new equivalence
relation using the four types of Equivalence Class testing.
7. Design and develop a program in a language of your choice to solve the triangle
problem defined as follows : Accept three integers which are supposed to be the three
sides of 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
#include<stdio.h>
#include <conio.h>
void main()
{
int a,b,c;
char istriangle;
istriangle='y';
else
istriangle ='n';
if (istriangle=='y')
printf("equilateral triangle\n");
printf("scalene triangle\n");
else
printf("isosceles triangle\n");
else
printf("Not a triangle\n");
getch();
}
Conditions evaluated for: whether given value for a equilateral, isosceles , Scalene triangle or
can't form a triangle
8. Design, develop, code and run the program in any suitable language to solve the
commission problem. Analyze it from the perspective of decision table-based testing,
derive different test cases, execute these test cases and discuss the test results.
#include<stdio.h>
int main()
{
int locks, stocks, barrels, t_sales;
float commission;
printf("Enter the total number of locks");
scanf("%d",&locks);
printf("Enter the total number of stocks");
scanf("%d",&stocks);
printf("Enter the total number of barrelss");
scanf("%d",&barrels);
if ((locks <= 0) || (locks> 70)||(stocks <= 0) || (stocks > 80)||
(barrels <= 0) || (barrels > 90))
{
if(lock==-1)
Printf(“program terminates”);
else
printf("invalid input");
}
else
{
t_sales = (locks * 45) + (stocks * 30) + (barrels * 25);
if (t_sales <= 1000)
{
commission = 0.10 * t_sales;
}
else if (t_sales < 1800)
{
commission = 0.10 * 1000;
commission = commission + (0.15 * (t_sales - 1000));
}
else
{
commission = 0.10 * 1000;
commission = commission + (0.15 * 800);
commission = commission + (0.20 * (t_sales - 1800));
}
printf("The total sales is %d \n the commission is %f",t_sales,
commission);
}
return 0;
}
DECISION TABLE
Test data: price Rs for lock - 45.0, stock - 30.0 and barrel - 25.0
Sales = total lock * lock price + total stock * stock price + total barrel * barrel price
Commission: 10% up to sales Rs 1000, 15 % of the next Rs 800 and 20 % on any
sales in excess of 1800.
Pre-condition: lock = -1 to exit and 1< =lock < = 70 , 1<=stock <=80 and 1<=barrel<=90
Brief Description: The salesperson had to sell at least one complete rifle per month.
RULES R1 R2 R3 R4 R5 R6 R7 R8 R9
Conditions C1: Locks = -1 T F F F F F F F F
C2 : 1 ≤ Locks ≤ 70 - T T F T F F F T
C3 : 1 ≤ Stocks ≤ 80 - T F T F T F F T
C4 : 1 ≤ Barrels ≤ 90 - F T T F F T F T
Actions a1 : Terminate the input loop X
a2 : Invalid locks input X X X X
a3 : Invalid stocks input X X X X
a4 : Invalid barrels input X X X X
a5 : Calculate total locks, stocks and barrels X X X X X X X
a5 : Calculate Sales X
a6: proceed to commission decision table X
Rules R1 R2 R3 R4
Conditions C1:sales=0 T F F F
C2: sales>0 and sales< =1000 - T F F
C3: sales>1001 and sales< =1800 - - T F
C4: sales >= 1801 - - - T
Actions A1:Terminate the program X
A2:comm =10% * sales X
A3:comm= 10%*1000+(sales-1000)*15% X
A4:comm = 10%*1000+15%*800+(sales-1800)*20% X
Precondition : Initial Value Total Locks= 0 , Total Stocks=0 and Total Barrels=0
Precondition Limit :Total locks, stocks and barrels should not exceed the limit 70,80 and 90
respectively.
9. Design, develop, code and run the program in any suitable language to solve the
commission problem. Analyze it from the perspective of dataflow testing, derive different
test cases, execute these test cases and discuss the test results.
1. #include<stdio.h>
2. int main()
{
3. int locks, stocks, barrels, tlocks, tstocks, tbarrels;
4. float lprice,sprice,bprice,lsales,ssales,bsales,sales,comm;
5. lprice=45.0;
6. sprice=30.0;
7. bprice=25.0;
8. tlocks=0;
9. tstocks=0;
10. tbarrels=0;
11. printf("\nenter the number of locks and to exit the loop enter -1 for locks\n");
12. scanf("%d", &locks);
13.while(locks!=-1)
{
14.printf("enter the number of stocks and barrels\n");
15.scanf("%d%d",&stocks,&barrels);
16.tlocks=tlocks+locks;
17. tstocks=tstocks+stocks;
18. tbarrels=btarrels+barrels;
19. printf("\nenter the number of locks and to exit the loop enter -1 for
20.locks\n");
21.scanf("%d",&locks);
22.}
23. printf("\ntotal locks = %d\”,tlocks);
24. printf(“total stocks =%d\n”,tstocks);
25. printf(“total barrels =%d\n",tbarrels);
38.}
39.else
40. comm=0.10*sales;
41. printf("the commission is=%f\n",comm);
42. return ( ) ;
43. }
Variable path
Test
(beginning Definition
case Description Du paths
and end clear?
id
nodes )
1 Check for lock price variable <5-6-7-8-9-10-11-12- Yes
DEF(lprice,5) and (5,26) 13-14-15-16-17-18-19-
USE(lprice,26) 20-21-22-23-24-25-26>
2 Check for lock variable <12-13-14-15-16-17- No
(12,22)
DEF(locks ,12) and USE(locks,) 18-19-20-21-22>
Note: Find path for all variables used and identify Definition Clear and non-Definition Clear
paths
10. Design, develop, code and run the program in any suitable language 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
#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;
if(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");
scanf("%d",&n);
if(n>0)
{
printf("enter the elements in ascending order\n");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
PATH TESTING
PATH TESTING
F L<=H
Independent paths :
2
#Edges =11 ,#nodes= 9, #p =1
T X[m] = = Key V(G)=E-N+2P=11-9+2=4
3
P1: 1-2-3-8-9
T F
P2: 1-2-3-4-5-7-2
8 X[m] > Key
X[m] < Key 4
P3: 1-2-3-4-6-7-2
P4: 1-2-8-9
9 5 6
PRE CONDITIONS:
Inputs
Paths Expected output Remarks
X[ ] Key
P1: 1-2-3-8-9 {10,20,30,40,50} 30 Success Key X[ ] & Key==X[mid]
P3: 1-2-3-4-6-7-2 {10,20,30,40,50} 40 Repeat and success Key >X[mid] search 2nd half
11. Design, develop, code and run the program in any suitable language to implement the
quick sort algorithm. Determine the basis paths and using them derive different test
cases, execute these test cases and discuss the test results.
#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--
;
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);
}
}
// main program
int main()
{
int a[20],i,key,n;
printf("enter the size of the array");
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++)
printf("%d\t",a[i]);
}
else
{
printf(“size of array is invalid\n”);
}
PATH TESTING
A Initialization
A
First < Last
B
F T
i<j
sc
C an
F T
Right scan
N J
D F
T
K
E Left scan
F
F
T F
i<j
M sc
G an I
H
Recursive calls
T
Dept. of ISE,DSATM Page 36
Software Testing Laboratory 18ISL67
P1: A-B-N
P2: A-B-C-J-K-B
P3: A-B-C-J-K-M-B
P4: A-B-C-D-F-H-C
P5: A-B-C-D-F-H-I-C
P6: A-B-C-D-E-D-F-H
P7: A-B-C-D-F-G-F-H
V (G) =E-N+2P=18-13+2=7
12. Design, develop, code and run the program in any suitable language to implement an
absolute letter grading procedure, making suitable assumptions. Determine the basis
paths and using them derive different test cases, execute these test cases and discuss the
test results.
#include<stdio.h>
int main()
{
float per;
char grade;
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)
{
int main()
{
float per;
char grade;
1. scanf("%f",&per);
2. if(per>=90)
3. grade= 'A';
11. switch(grade)
12. {
13. case 'A': printf("\nEXCELLENT");
break;
Start 1
2
3
5
6
7
8
9
10
19
11
13 14 15 16 17
19
Independent Paths:
20
End #Edges=25, #Nodes=18, #P=1
V(G)= E-N+2P = 25-18+2 = 09
P1: 1-2-4-6-8-10-11-17-19-20 E Grade
P2: 1-2-4-6-8-9-11-16-19-20 D Grade
P3: 1-2-4-6-7-11-15-19-20 C Grade
P4: 1-2-4-5-11-14-19-20 B Grade
P5: 1-2-3-11-13-19-20 A Grade
P6: 1-2-4-6-8-10-11-13-19-20
P7: 1-2-4-6-8-10-11-14-19-20
P8: 1-2-4-6-8-10-11-15-19-20
P9: 1-2-4-6-8-10-11-16-19-20
Pre-Conditions/Issues:
Percentage Per is a positive Float Number
5. Write the test cases for any known application also given the justification about the
6. Take any system (e.g. ATM system) and study its system specifications and report the
various bugs.
7. Explain the data flow testing metrics evaluation for any program/application.
9. Perform path testing form any program with switch case statement.
10. Perform path testing to demonstrate cyclomatic complexity greater than 10. Also Discuss
VIVA QUESTIONS
10. Number of test cases for boundary value analysis for n numbers?
11. What type of variables we are using boundary value analysis?
12. What are the 5 boundary value analysis values of a variable?
13. What is Robust testing?
14. What is worst case casting?
15. Number of test cases for worst case testing?
16. What is robust worst case testing?
17. Number of test cases for robust worst case testing?
18. What is special value testing (skirt testing)?
19. What is the limitation of boundary value analysis?
20. What is equivalence class?
21. What is equivalence class testing?
22. What is weak normal equivalence class testing?
23. What is strong normal equivalence class testing?
24. What is weak robust equivalence class testing?
25. What is strong robust equivalence class testing?
26. When equivalence class is appropriate?
27. What is decision table based testing?
28. What are the different positions of decision table?
29. What is a rule?
30. What are the different types of decision tables?
31. What are limited entry decision tables?
32. What is extended entry decision tables?
33. When decision table based testing is appropriate?
34. What is a program graph?
35. What is DD (decision to decision) path?
36. What is test coverage metrics?
37. What is basis path testing?
38. What is data flow testing?
39. What is Def (v.n)?
40. What is Use (v,n)?