Professional Documents
Culture Documents
Software Testing Lab Manual Final - Updated - 29.4.22
Software Testing Lab Manual Final - Updated - 29.4.22
Testing is a process used to help identify the correctness, completeness and quality of developed
computer software. With that in mind, testing can never completely establish the correctness of
computer software.
Testing objectives include:
1. Testing is a process of executing a program with the intent of finding an error.
2. A good test case is one that has a high probability of finding an as yet
undiscovered error.
3. A successful test is one that uncovers an as yet undiscovered error.
Testing should systematically uncover different classes of errors in a minimum amount of time and with a
minimum amount of effort. A secondary benefit of testing is that it demonstrates that the software appears
to be working as stated in the specifications. The data collected through testing can also provide an
indication of the software's reliability and quality. But, testing cannot show the absence of defect -- it can
only show that software defects are present
Thus the main objectives of the Software Testing Laboratory are
To help students learn about the basic strategies of testing in laboratory;
To help students as they study and learn about writing effective test cases.
To differentiate between the way black box and white box testing is done in practice.
To make the students understand and compare the various testing strategies and their
advantages and drawbacks.
To enlighten students about how to analyze the problem statement and go about in problem
solving.
To help students in choosing the best technique for testing the programs.
A≤X ≤B
1
C≤X ≤D
2
The values of A, B, C and D are the extremities of the input domain. These are best demonstrated
by figure
Source Code:
#include<stdio.h>
int main()
{
int a,b,c,c1,c2,c3;
int istriangle=0;
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);
c1 = (a>=1 && a<=10);
c2=( b>=1 && b<=10);
c3= (c>=1 && c<=10);
if (!c1)
printf("\n the value of a=%d is not the range of permitted value",a);
return 0;
}
Program 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.
/* Assumption price for lock=45.0, stock=30.0 and barrels=25.0 production limit could sell in a
month 70 locks,80 stocks and 90 barrels commission on sales = 10 % <= 1000 and 15 % on 1000 to
1800 and 20 % on above 1800*/
#include<stdio.h>
int main()
{
int locks, stocks, barrels, tlocks, tstocks, tbarrels;
float lprice, sprice, bprice, sales, comm;
int c1,c2,c3,temp;
lprice=45.0;
sprice=30.0;
bprice=25.0;
tlocks=0;
tstocks=0;
tbarrels=0;
printf("\nenter the number of locks and to exit the loop enter -1 for locks\n");
scanf("%d",&locks);
while(locks!=-1)
{
c1=(locks<=0||locks>70);
printf("enter 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("value of locks not in the range 1..70 ");
else
{
if(c2)
printf("value of stocks not in the range 1..80 ");
else
{
temp=tstocks+stocks;
if(temp>80)
printf("new total stocks =%d not in the range 1..80 so old ",temp);
else
tstocks=temp;
}
printf("total stocks=%d\n",tstocks);
if(c3)
printf("value of barrels not in the range 1..90 ");
else
{
temp=tbarrels+barrels;
if(temp>90)
printf("new total barrels =%d not in the range 1..90 so old ",temp);
else
tbarrels=temp;
}
printf("total barrel=%d",tbarrels);
printf("\nenter the number of locks and to exit the loop enter -1 for locks\n");
Checking boundary value for locks, stocks and barrels and commission
Commission Problem Output Boundary Value Analysis Cases
Expected
Input Data Actual output Sta
Case Output
Description tus
Id Total Total Total Comm Comm-
Sales Sales Comment
Locks Stocks Barrels -ission ission
1 Enter the min value for locks, stocks and barrels 1 1 1 100 10 output minimum
2 1 1 2 125 12.5 output minimum +
Enter the min value for 2 items and min +1 for any
3 1 2 1 130 13 output minimum +
one item
4 2 1 1 145 14.5 output minimum +
Enter the sales value such that it is approximately mid
5 value between 100 to 1000 5 5 5 500 50 Midpoint
6 Enter the values to calculate the commission for sales 9 10 10 975 955.5 Border point -
7 nearly less than 1000 10 9 10 970 97 Border point -
Program 3:
Design, develop, code and run the program in any suitable language 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.
#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)
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;
Test Case Name : Boundary Value Analysis test cases for Next date program
Experiment Number : 3
Test data : Enter the three integer value
Pre-condition : Month 1 to 12 , DAY 1 TO 31 AND YEAR 1812 TO 2012 / we are consider one corner of the input space
Min Max
Brief Description : Min +1 Normal -1 Max
Month 1 2 6 11 12
Day 1 2 15 30 31
Year 1812 1813 1912 2011 2012
The use of equivalence classes as the basis for functional testing and is appropriate in situations like
a) When exhaustive testing is desired.
b) When there is a strong need to avoid redundancy.
The above are not handled by BVA technique as we can see massive redundancy in the tables of test
cases. In this technique, the input and the output domain is divided into a finite number of
equivalence classes.
Then, we select one representative of each class and test our program against it. It is assumed by the
tester that if one representative from a class is able to detect error then why should he consider other
cases. Furthermore, if this single representative test case did not detect any error then we assume that
no other test case of this class can detect error. In this method we consider both valid and invalid
input domains. The system is still treated as a black-box meaning that we are not bothered about its
internal logic.
The idea of equivalence class testing is to identify test cases by using one element from each
equivalence class. If the equivalence classes are chosen wisely, the potential redundancy among test
cases can be reduced.
The word 'weak' means 'single fault assumption'. This type of testing is accomplished by using one
variable from each equivalence class in a test case. We would, thus, end up with the weak
equivalence class test cases as shown in the following figure.
Each dot in above graph indicates a test data. From each class we have one dot meaning that there is
one representative element of each test case. In fact, we will have, always, the same number of weak
equivalence class test cases as the classes in the partition.
Just like we have truth tables in digital logic, we have similarities between these truth tables and our
pattern of test cases. The Cartesian product guarantees that we have a notion of "completeness" in
following two ways
a) We cover all equivalence classes.
b) We have one of each possible combination of inputs.
#include<stdio.h>
int main()
{
int a,b,c , c1,c2,c3;
int istriangle=0;
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);
c1 = a>=1 && a<=10;
c2= b>=1 && b<=10;
c3= c>=1 && c<=10;
if (!c1)
printf("\nthe value of a=%d is not the range of permitted value",a);
if (!c2)
printf("\nthe value of b=%d is not the range of permitted value",b);
if (!c3)
printf("\nthe value of c=%d is not the range of permitted value",c);
} while(!(c1 && c2 && c3));
Experiment Number : 4
Test Data : Enter the 3 Integer Value( a , b And c )
Pre-condition : 1 ≤ a ≤ 10 , 1 ≤ b ≤ 10 and 1 ≤ c ≤ 10 and a < b + c , b < a + c and c < a + b
Brief Description : Check whether given value for a equilateral, isosceles , Scalene triangle or can't from a triangle
Triangle Problem -Equivalence Class Test cases for input data
3-WN2 Enter the valid values for a ,b and c 2 2 3 Should display the message Pass -
Isosceles triangle
Isosceles triangle
3-WN3 Enter the valid values for a ,b and c 3 4 5 Should display the message Pass -
Scalene triangle
Scalene triangle
3-WN4 Enter the valid values for a ,b and c 4 1 2 Message should be displayed Pass -
Not a triangle
can't form a triangle
Enter the invalid value for a and Should display value of a is not Value of a not in range of
3-WR5 -1 6 7 Pass -
valid values for b and c. in the range of permitted values permitted values
Enter invalid input for b and valid Should display value of b is not The value of b’ is not the
3-WN6 7 -1 6 Pass
values for a and c in the range of permitted values range of permitted range
Enter invalid input c and two valid Should display value of c is not The value of c is not the
3-WN7 6 7 -1 Pass
values for a and b in the range of permitted values range of permitted rang
Enter the invalid value for a and Should display value of a is not The value of a is not the
3-WN8 11 6 4 Pass
valid values for b and c. in the range of permitted values range of permitted rang
Enter invalid input for b and valid Should display value of b is not The value of b is not the
3-WN9 4 11 6 Pass
values for a and c in the range of permitted values range of permitted rang
Enter invalid input for c and valid Should display value of c is not The value of c is not the
3-WN10 4 6 11 Pass
values for a and b in the range of permitted values range of permitted rang
Strong Normal Equivalence class Testing
Enter the valid values for a , b and Should display the message
3-SN1 5 5 5 Equilateral triangle Pass -
c Equilateral triangle
3-SN2 Enter the valid values for a ,b and c 2 2 3 Should display the message Pass -
Isosceles triangle
Isosceles triangle
3-SN3 Enter the valid values for a ,b and c 3 4 5 Should display the message Pass -
Scalene triangle
Scalene triangle
3-SN4 Enter the valid values for a ,b and c 4 1 2 Message should be displayed Pass -
Not a triangle
can't form a triangle
Strong Robust Equivalence Class Testing
Enter the valid values for a , b and Should display the message
3-SR1 5 5 5 Equilateral triangle Pass -
c Equilateral triangle
3-SR2 Enter the valid values for a ,b and c 2 2 3 Should display the message Isosceles triangle Pass -
Isosceles triangle
3-SR3 Enter the valid values for a ,b and c 3 4 5 Should display the message Pass -
Scalene triangle
Scalene triangle
3-SR4 Enter the valid values for a ,b and c 4 1 2 Message should be displayed Pass -
Not a triangle
can't form a triangle
Enter the invalid value for a and Should display value of a is not Value of a not in range of
3-SR5 -1 6 7 Pass -
valid values for b and c. in the range of permitted values permitted values
Enter invalid input for b and valid Should display value of b is not The value of b’ is not the
3-SR6 7 -1 6 Pass -
values for a and c in the range of permitted values range of permitted range
Enter invalid input c and two valid Should display value of c is not The value of c is not the
3-SR7 6 7 -1 Pass -
values for a and b in the range of permitted values range of permitted rang
Enter the invalid value for a and Should display value of a is not The value of a is not the
3-SR8 11 6 4 Pass -
valid values for b and c. in the range of permitted values range of permitted rang
Enter invalid input for b and valid Should display value of b is not The value of b is not the
3-SR9 4 11 6 Pass -
values for a and c in the range of permitted values range of permitted rang
Enter invalid input for c and valid Should display value of c is not The value of c is not the
3-SR10 4 6 11 Pass -
values for a and b in the range of permitted values range of permitted rang
Enter invalid input for a ,b and valid Should display value of a and b The value of a and b are
3-SR11 -1 -1 9 are not in the range of not the range of permitted Pass -
value for c
permitted values rang
Enter invalid input for b, c and valid Should display value of b and The value of b and c are
3-SR12 9 -1 -1 c are not in the range of not in the range of Pass -
value for a
permitted values permitted rang
Should display value of a and c
Enter invalid input for a, c and valid
3-SR13 -1 9 -1 are not in the range of The value of a and c are Pass -
value for b permitted values not the range of permitted
rang
Enter invalid input for a, c and valid Should display value of a and cThe value of a and c are
3-SR14 11 9 14 are not in the range of not the range of permitted Pass -
value for b
permitted values rang
Enter invalid input for b, c and valid Should display value of b and cThe value of b and c are
3-SR15 9 11 14 are not in the range of not the range of permitted Pass -
value for a
permitted values rang
Enter invalid input for a ,b and valid Should display value of a and bThe value of a and b are
3-SR16 11 14 9 are not in the range of not the range of permitted Pass -
value for c
permitted values rang
Enter invalid input for a ,b and valid Should display value of a and bThe value of a and b are
3-SR17 -2 12 8 are not in the range of not the range of permitted Pass -
value for c
permitted values rang
Should display value of a ,b The value of a, b and c
3-SR18 Enter invalid input for a, b and c -2 -1 -4 and c are not in the range of are not the range of Pass -
permitted values permitted rang
The value of a , b and c Pass
Should display value of a ,b
3-SR19 Enter invalid input for a, b and c 11 12 0 are not the range of -
and c are not in the range of
permitted rang the range of
permitted values
permitted rang
/* Assumption price for lock=45.0, stock=30.0 and barrels=25.0 production limit could sell in a month
70 locks,80 stocks and 90 barrels commission on sales = 10 % <= 1000 and 15 % on 1000 to 1800 and
20 % on above 1800*/
#include<stdio.h>
int main()
{
int locks, stocks, barrels, tlocks, tstocks, tbarrels;
float lprice, sprice, bprice, sales, comm;
int c1,c2,c3,temp;
lprice=45.0;
sprice=30.0;
bprice=25.0;
tlocks=0;
tstocks=0;
tbarrels=0;
printf("\nenter the number of locks and to exit the loop enter -1 for locks\n");
scanf("%d",&locks);
while(locks!=-1)
{
c1=(locks<=0||locks>70);
printf("enter 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("value of locks not in the range 1..70 ");
else
{
if(c2)
printf("value of stocks not in the range 1..80 ");
else
{
temp=tstocks+stocks;
if(temp>80)
printf("new total stocks =%d not in the range 1..80 so old ",temp);
else
tstocks=temp;
}
printf("total stocks=%d\n",tstocks);
if(c3)
printf("value of barrels not in the range 1..90 ");
else
{
temp=tbarrels+barrels;
if(temp>90)
printf("new total barrels =%d not in the range 1..90 so old ",temp);
else
tbarrels=temp;
}
printf("total barrel=%d",tbarrels);
if (!(c1||c2||c3))
{
printf("\ntotal locks = %d\ntotal stocks =%d\ntotal barrels =%d\n",tlocks,tstocks,tbarrels);
sales = lprice*tlocks+sprice*tstocks+bprice*tbarrels;
printf("\nthe total sales=%f\n",sales);
}
if((sales > 0) && !(c1||c2||c3))
{
if(sales > 1800.0)
{
comm=0.10*1000.0;
comm=comm+0.15*800;
comm=comm+0.20*(sales-1800.0);
}
else if(sales > 1000)
{
comm =0.10*1000;
comm=comm+0.15*(sales-1000);
}
else
comm=0.10*sales;
Valid Classes
L1 ={LOCKS :1 <=LOCKS<=70}
L2 ={Locks=-1}(occurs if locks=-1 is used to control input iteration)
S1 ={stocks : 1<=stocks<=80}
B1= {barrels :1<=barrels<=90}
Invalid Classes
L3 ={locks: locks=0 OR locks<-1}
L3 ={locks: locks> 70}
S2 ={stocks : stocks<1}
S3 ={stocks : stocks >80}
B2 ={barrels : barrels <1}
B3 =barrels : barrels >90}
Program 6:
Design, develop, code and run the program in any suitable language 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..
#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;
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;
Invalid cases
M2 = {month : month < 1}
M3 = {month : month > 12}
D2 = {day : day < 1}
D3 = {day : day > 31}
Y2 = {year : year < 1812}
Y3 = {year : year > 2012}
SR1 Enter the M2 , D1 and Y1 -1 15 1912 Should display the message value of
cases the month not in the range 1..12
SR2 Enter the M1, D2 and Y1 6 -1 1912 Should display the message value of
cases the day not in the range 1..31
Should display the message value of
SR3 Enter the M1, D1 and Y2 6 15 1811 the year not in the range
cases
1812..2013
(i)Should display the message value
SR4 Enter the M2 , D2 and Y1 -1 -1 1912 of the month in range 1..12
cases (ii) Should display the message
value of the day in range 1..31
(i) Should display the message
value of the day in range 1..31
SR5 Enter the M1, D2 and Y2 6 -1 1811 (ii) Should display the message
cases
value of the year in range
1812..2013
(i)Should display the message value
of the month in range 1..12
SR6 Enter the M2, D1 and Y2 -1 15 1811
cases (ii) Should display the message
value of the year in range
1812..2013
(i)Should display the message value
Enter the M2, D2 and Y2 of the month in range 1..12
SR7 -1 -1 1811
cases (ii) Should display the message
value of the day in range 1..31
R1 R2 R3 R4 R5 R6 R7 R8
C1 T T T T F F F F
C3 T F T F T F T F
a1 x x x x
a2 x x
actions taken
actions a3 x x
a4 x x x x
a5 x x
The conditions in the decision table may take on any number of values. When it is binary, then
the decision table conditions are just like a truth table set of conditions. (Note that the conditions
do not have to be binary --- table gets “big” then.)
The decision table allows the iteration of all the combinations of values of the condition, thus it
provides a “completeness check.”
The conditions in the decision table may be interpreted as the inputs, and the actions may be
thought of as outputs. OR conditions needs to be thought as inputs needed set the conditions, and
actions can be processing
Triangle Problem Example
Consider a program statement that, given the length of 3 sides, determines whether the 3 sides
can (i) form a triangle and (ii) what type of triangle (equilateral, isosceles, or scalene).
- The inputs are a, b, c sides (each between 1 and 200)
1. a < b + c F T T T T T T T T T T
2. b < a + c - F T T T T T T T T T
3. c < a + b - - F T T T T T T T T
4. a = b - - - T T T T F F F F
5. a = c - - - T T F F T T F F
6. b = c - - - T F T F T F T F
1. Not triangle X X X
1. Scalene X
2. Isosceles X X X
3. Equilateral X
4. “impossible” X X X Note the
Impossible cases
Source code:
#include<stdio.h>
int main()
{
int a,b,c;
int istriangle=0;
printf("enter 3 integers which are sides of triangle\n");
scanf("%d%d%d",&a,&b,&c);
printf("a=%d\t,b=%d\t,c=%d",a,b,c);
// to check is it a triangle or not
if( a<b+c && b<a+c && c<a+b )
istriangle=1;
else
istriangle =0;
;
if (istriangle==1)
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");
return 0;
}
Input Data
Case Id Description Expected Output Actual Output Status Comments
a B C
Message should be
1 Enter the value of a, b and c Such that a is 10 5 5 Not a triangle Pass -
displayed can't form a
not less than sum of two sides
triangle
Enter the value of a, b and c Such that b is Message should be
2 not less than sum of two sides and a is less 5 5 10 displayed can't form a Not a triangle Pass -
than sum of other two sides triangle
Enter the value of a, b and c Such that c is Message should be
3 not less than sum of two sides and a and b 5 10 5 displayed can't form a Not a triangle Pass -
is less than sum of other two sides triangle
Enter the value a, b and c satisfying Should display the message Equilateral
4 5 5 5 Pass -
precondition and a=b, b=c and c=a Equilateral triangle triangle
5 Enter the value a ,b and c satisfying 10 10 9 Should display the message Isosceles triangle Pass -
precondition and a=b and b ≠ c Isosceles triangle
6 Enter the value a ,b and c satisfying 10 9 10 Should display the message Isosceles triangle Pass -
precondition and a=c and b ≠ c Isosceles triangle
7 Enter the value a ,b and c satisfying 9 10 10 Should display the message Pass -
precondition and b=c and a ≠ c Isosceles triangle Isosceles triangle
8 Enter the value a, b and c satisfying 5 6 7 Should display the message Scalene triangle Pass -
precondition and a ≠b , b ≠ c and c ≠ a Scalene triangle
Program 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.
/* Assumption price for lock=45.0, stock=30.0 and barrels=25.0 production limit could sell in a month
70 locks,80 stocks and 90 barrels commission on sales = 10 % <= 1000 and 15 % on 1000 to 1800 and
20 % on above 1800*/
#include<stdio.h>
int main()
{
int locks, stocks, barrels, tlocks, tstocks, tbarrels;
float lprice, sprice, bprice, sales, comm;
int c1,c2,c3,temp;
lprice=45.0;
sprice=30.0;
bprice=25.0;
tlocks=0;
tstocks=0;
tbarrels=0;
printf("\nenter the number of locks and to exit the loop enter -1 for locks\n");
scanf("%d",&locks);
while(locks!=-1)
{
c1=(locks<=0||locks>70);
printf("enter 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("value of locks not in the range 1..70 ");
else
if(c2)
printf("value of stocks not in the range 1..80 ");
else
{
temp=tstocks+stocks;
if(temp>80)
printf("new total stocks =%d not in the range 1..80 so old ",temp);
else
tstocks=temp;
}
printf("total stocks=%d\n",tstocks);
if(c3)
printf("value of barrels not in the range 1..90 ");
else
{
temp=tbarrels+barrels;
if(temp>90)
printf("new total barrels =%d not in the range 1..90 so old ",temp);
else
tbarrels=temp;
}
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
2 Enter the valid input for lock and 20 30 -5 Should display value of barrels is not in
stack and invalid for barrels the range 1..90
3 Enter the valid input for lock and 15 -2 45 Should display value of barrels is not in
barrels and invalid for stocks the range 1..80
4 Enter the valid input for lock and -4 15 16 Should display value of barrels is not in
barrels and invalid for stocks the range 1..70
(i)Should display value of stock is not in
5 Enter the valid input for lock and 15 81 100 the range 1..80 (ii)Should display value of
invalid value for stocks and barrels
barrels is not in the range 1..90
(i)Should display value of lock is not in
6 Enter the valid input for stocks and 88 20 99 the range 1..70 (ii)Should display value of
invalid value for locks and barrels
barrels is not in the range 1..90
(i)Should display value of lock is not in
7 Enter the valid input for barrels and 100 99 25 the range 1..70 (ii)Should display value of
invalid value for locks and stocks
stocks is not in the range 1..80
Program 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..
29.bsales=bprice*tbarrels;
30.sales=lsales+ssales+bsales;
Test variables
Definition
case Description path(Beginning, Du paths Comments
clear ?
id End nodes)
Check for lock price variable DEF(lprice,6) and <6-7-8-9-10-11-12-13-14-15-16-17-18-
1 (6 , 24) Yes -
USE(lprice,27) 19-20-21-22-23-14-24-25-26-27>
Check for Stock price variable DEF(sprice,7) and <7-8-9-10-11-12-13-14-15-16-17-18-19- -
2 (7 , 28) Yes
USE(sprice,28) 20-21-22-23-14-24-25-26-27-28>
Check for barrel price variable DEF(bprice,8) and <8-9-10-11-12-13-14-15-16-17-18-19- -
3 (8 , 29) Yes
USE(bprice,29) 20-21-22-23-14-24-25-26-27-28-29>
(9 , 18) <9-10-11-12-13-14-15-16-17-18> Yes -
<9-10-11-12-13-14-15-16-17-18-19-20- -
(9, 24) No
Check for total locks variable DEF((tlocks,(9,18)) and 21-22-23-14-24>
Program 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
Path testing is an approach to testing where you ensure that every path through a program
has been executed at least once. You normally use a dynamic analyzer tool or test coverage
analyser to check that all of the code in a program has been executed. However, testing all paths
does not mean that you will find all bugs in a program. Many bugs arise because programmers
have forgotten to include some processing in their code, so there are no paths to execute. Some
bugs are also related to the order in which code segments are executed. For example, if segments
a, b and c are executed <a, b, c>, then the program may work properly. However, if they are
executed <a, c, b> then an error may arise. It is practically impossible to test all orders of
processing as well as all program paths.
The starting point for path testing is a program flow graph. This is a skeletal model of all
paths through the program. A flow graph consists of nodes representing decisions and edges
showing flow of control. The flow graph is constructed by replacing program control statements
by equivalent diagrams. If there are no goto statements in a program, it is a simple process to
derive its flow graph. Each branch in a conditional statement (if-then-else or case) is shown as a
separate path. An arrow looping back to the condition node denotes a loop. The objective of path
testing is to ensure that each independent path through the program is executed at least once. An
independent program path is one that traverses at least one new edge in the flow graph. In
program terms, this means exercising one or more new conditions. Both the true and false
branches of all conditions must be executed.
Each node in a flow graph represents a line in the program with an executable statement.
By tracing the flow, therefore, you can see that the independent paths through the binary search
flow graph are:
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 14
1, 2, 3, 4, 5, 14
1, 2, 3, 4, 5, 6, 7, 11, 12, 5,
1, 2, 3, 4, 6, 7, 2, 11, 13, 5, …
Source Code:
#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++)
Pre-Conditions/Issues:
Array has Elements in Ascending order
T/F
Key element is in the Array
T/F
Array has ODD number of Elements
T/F
Program 11 :
Design, develop, code and run the program in any suitable language 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.
#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);
}
}
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”);
}
Independent Paths:
#Edges=18, #Nodes=13, #P=1
V(G)= E-N+2P = 18-13+2 = 7
#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)
{
case 'A': printf("\nEXCELLENT"); break;
case 'B':printf("\nVery Good"); break;
case 'C' : printf("\nGood"); break;
case 'D': printf("\nAbove Average"); break;
case 'E': printf("\n Satisfactory"); break;
}
printf("\t The percentage = %f and grade is %c ",per,grade);
return 0;
}
Independent Paths:
#Edges=25, #Nodes=18, #P=1
V(G)= E-N+2P = 25-18+2 = 09
Pre-Conditions/Issues:
Percentage Per is a positive Float Number
1. Design, develop, code and run the program in any suitable language to solve Paytm
problem. Analyze the testing technique (Boundary value testing/Equivalence class
2. Design, develop, code and run the program in any suitable language to solve Paytm
problem. Analyze the testing technique (Decision table testing/Data Flow testing/Basis
Path testing) that can be used for the same and derive different test cases, execute these
test cases and discuss the test results.