Download as pdf or txt
Download as pdf or txt
You are on page 1of 79

Software Testing Laboratory 18ISL66

Introduction to Software Testing Laboratory

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.

Dept. of ISE, BNMIT 2021-22 Page 1


Software Testing Laboratory 18ISL66
Program 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.

Boundary Value Analysis:


Boundary value analysis focuses on the boundary of the input space to identify test cases. The
rationale behind boundary value analysis is that errors tend to occur near the extreme values of an
input variable.
The Focus of BVA
Boundary Value Analysis focuses on the input variables of the function. For the purposes of this report I
will define two variables ( I will only define two so that further examples can be kept concise) X and X .
1 2

Where X lies between A and B and X lies between C and D.


1 2

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

Dept. of ISE, BNMIT 2021-22 Page 2


Software Testing Laboratory 18ISL66
if the programmer forgot to count from zero or they just miscalculated. Errors in the code
concerning loop counters being off by one or the use of a < operator instead of ≤. These are all
very common mistakes and accompanied with other common errors we find an increasing need to
perform Boundary Value Analysis.
Applying Boundary Value Analysis
In the general application of Boundary Value Analysis can be done in a uniform manner. The basic
form of implementation is to maintain all but one of the variables at their nominal (normal or average)
values and allowing the remaining variable to take on its extreme values. The values used to test the
extremities are:
• Min ------------------------------------ - Minimal
• Min+ ------------------------------------ - Just above Minimal
• Nom ------------------------------------ - Average
• Max- ------------------------------------ - Just below Maximum
• Max ------------------------------------ - Maximum

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);

Dept. of ISE, BNMIT 2021-22 Page 3


Software Testing Laboratory 18ISL66
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));

// to check is it a triangle or not


if(c1&&c2&&c3)
{
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;
}

Dept. of ISE, BNMIT 2021-22 Page 4


Software Testing Laboratory 18ISL66
Test Case Name :Boundary Value Analysis for triangle problem
Experiment Number : 1
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 -Boundary value Test cases for input data

Case Input Data Actual


Description Expected Output Status Comments
Id A B C Output
Isosceles
1 Enter the min value for a , b and c 1 5 5 Should display the message Isosceles triangle Pass -
triangle
Enter the min value for 2 items and min +1 Should display the message Isosceles triangle Isosceles
2 2 5 5 Pass -
for any one item1 triangle
Enter the min value for 2 items and min +1 Should display the message Equilateral Equilateral
3 5 5 5 triangle Pass -
for any one item1 triangle
Enter the min value for 2 items and min +1 Should display the message Isosceles triangle Isosceles
4 9 5 5 Pass -
for any one item1 triangle
Enter the normal value for 2 items and 1 Not
5 10 5 5 Should display the message not a triangle Pass -
item is min value a triangle
Enter the normal value for 2 items and 1 Isosceles
6 5 1 5 Should display the message Isosceles triangle Pass -
item is min value triangle
Enter the normal value for 2 items and 1 Isosceles
7 5 2 5 Should display the message Isosceles triangle Pass -
item is min value triangle

Dept. of ISE, BNMIT 2021-22 Page 5


Software Testing Laboratory 18ISL66
Isosceles
8 Enter the normal Value for a, b and c 5 9 5 Should display the message Isosceles triangle Pass -
triangle
Enter the normal value for 2 items and 1 Not
9 5 10 5 Should display the message Not a triangle Pass -
item is max value a triangle
Enter the normal value for 2 items and 1 Isosceles
10 5 5 1 Should display the message Isosceles triangle Pass -
item is max value triangle
Enter the normal value for 2 items and 1 Isosceles
11 5 5 2 Should display the message Isosceles triangle Pass -
item is max value triangle
Enter the max value for 2 items and max - 1 Isosceles
12 5 5 9 Should display the message Isosceles triangle Pass -
for any one item triangle
Enter the max value for 2 items and max - 1 Not
13 5 5 10 Should display the message Not a triangle Pass -
for any one item a triangle

Dept. of ISE, BNMIT 2021-22 Page 6


Software Testing Laboratory 18ISL66

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
{

Dept. of ISE, BNMIT 2021-22 Page 7


Software Testing Laboratory 18ISL66
temp=tlocks+locks;
if(temp>70)
printf("new total locks =%d not in the range 1..70 so old ",temp);
else
tlocks=temp;
}
printf("total locks = %d\n",tlocks);

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");

Dept. of ISE, BNMIT 2021-22 Page 8


Software Testing Laboratory 18ISL66
scanf("%d",&locks);
}
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;
printf("the commission is=%f\n",comm);
}
else
printf("there is no sales\n");
return 0;
}

Dept. of ISE, BNMIT 2021-22 Page 9


Software Testing Laboratory 18ISL66
Test Case Name : Boundary Value for Commission Problem
Experiment Number : 2
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. Calculating the sales and commission of a salesperson depending on the
number of locks ,stocks and barrels he sells per month.

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 -

Dept. of ISE, BNMIT 2021-22 Page 10


Software Testing Laboratory 18ISL66
8 10 10 9 955 97.5 Border point -
9 Enter the values sales exactly equal to 1000 10 10 10 1000 100 Border point
10 10 10 11 1025 103.75 Border point +
Enter the values to calculate the commission for sales
11 10 11 10 1030 104.5 Border point +
nearly greater than 1000
12 11 10 10 1045 106.75 Border point +
Enter the value sales approximately mid value
13 between 1000 to 1800 14 14 14 1400 160 Midpoint
14 17 18 18 1755 213.25 Border point -
Enter the values to calculate the commission for sales
15 18 17 18 1770 215.5 Border point -
nearly less than 1800
16 18 18 17 1775 216.25 Border point -
17 Enter the values sales exactly equal to 1800 18 18 18 1800 220 Border point
18 18 18 19 1825 225 Border point +
Enter the values to calculate the commission for sales
19 18 19 18 1830 226 Border point +
nearly greater than 1800
20 19 18 18 1845 229 Border point +
Enter the values normal value for lock, stock and
21 barrel 48 48 48 4800 820 Midpoint
Output maximum
22 70 80 89 7775 1415 -
Enter the max value for 2 items and max - 1 for any Output maximum
23 one item 70 79 90 7770 1414 -
Output maximum
24 69 80 90 7755 1411 -
25 Enter the max value for locks,stocks and barrels 70 80 90 7800 1420 Output maximum

Dept. of ISE, BNMIT 2021-22 Page 11


Software Testing Laboratory 18ISL66

Output Special Value Test Cases


Expected
Input Data Actual output
Case Output
Description
Id Total Total Total Commis Comm
Sales Sales Status Comment
Locks Stocks Barrels sion ission
Enter the random values such that to calculate
1 11 10 8 995 99.5 Border point -
commission for sales nearly less than 1000
Enter the random values such that to calculate
2 10 11 9 1005 100.75 Border point +
commission for sales nearly greater than 1000
Enter the random values such that to calculate
3 18 17 19 1795 219.25 Border point -
commission for sales nearly less than 1800
Enter the random values such that to calculate
4 18 19 17 1805 221 Border point +
commission for sales nearly greater than 1800

Dept. of ISE, BNMIT 2021-22 Page 12


Software Testing Laboratory 18ISL66

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)

Dept. of ISE, BNMIT 2021-22 Page 13


Software Testing Laboratory 18ISL66
{
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>2013)
{
printf("value of year, not in the range 1812.......2012\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';
}

Dept. of ISE, BNMIT 2021-22 Page 14


Software Testing Laboratory 18ISL66
}
}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)

Dept. of ISE, BNMIT 2021-22 Page 15


Software Testing Laboratory 18ISL66
tomm_day=day+1;
else
{
tomm_day=1;
tomm_month=1;
if(year==2012)
{
printf("the next day is out of boundary value of year\n");
return 0;
}
else
tomm_year=year+1;
}
break;
case 2:
if(day<28)
tomm_day=day+1;
else if(isleap(year)&& day==28)
tomm_day=day+1;
else if(day==28 || day==29)
{
tomm_day=1;
tomm_month=3;
}
break;
}
printf("next day is : %d %d %d",tomm_day,tomm_month,tomm_year);
return 0;
}

Dept. of ISE, BNMIT 2021-22 Page 16


Software Testing Laboratory 18ISL66

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

Next date Output Boundary Value Analysis Cases

Case Input Data Expected Output Actual output


Description Status Comment
Id Month day year Month day year Month day year

1 Enter the min value month,day and year 1 1 1812 1 2 1812


Enter the min+1 value for year and min for
2 1 1 1813 1 2 1813
month and day
Enter the normal value for year and min for
3 1 1 1912 1 2 1912
month and day
Enter the max -1 value for year and min for
4 1 1 2011 1 2 2011
month and day

Dept. of ISE, BNMIT 2021-22 Page 17


Software Testing Laboratory 18ISL66
Enter the max value for year and min for
5 1 1 2012 1 2 2012
month and day
Enter the min+1 value of day and min for
6 1 2 1812 1 3 1812
month and year
Enter the min+1 value for day and year and
7 1 2 1813 1 3 1813
min for month
Enter the min+1 value for day , normal
8 1 2 1912 1 3 1912
value for year and min value for month
Enter the min+1 value for day , max -1
9 1 2 2011 1 3 2012
value for year and min value for month
Enter the min+1 value for day , max value
10 1 2 2012 1 3 2012
for year and min value for month
Enter the normal value of day and min for
11 1 15 1812 1 16 1812
year and month
Enter the normal value for day and min+1
12 1 15 1813 1 16 1813
for year and min for month
Enter the normal value for day normal value
13 1 15 1912 1 16 1912
for year and min value for month
Enter the normal value for day , max -1
14 1 15 2011 1 16 2011
value for year and min value for month
Enter the normal value for day , max value
15 1 15 2012 1 16 2012
for year and min value for month

Dept. of ISE, BNMIT 2021-22 Page 18


Software Testing Laboratory 18ISL66
Enter the max - 1 value of day and min for
16 1 30 1812 1 31 1812
day and year
Enter the max -1 value for day and min for
17 1 30 1813 1 31 1813
month and min+1 for year
Enter the max - 1 value for day , normal
18 1 30 1912 1 31 1912
value for year and min value for month
Enter the max - 1 value for day , max -1
19 1 30 2011 1 31 2011
value for year and min value for month
Enter the max -1 value for day , max value
20 1 30 2012 1 31 2012
for year and min value for month
Enter the max value of day and min for year
21 1 31 1812 2 1 1812
and month

Enter the max value for day and min for


22 1 31 1813 2 1 1813
month and min + 1 for year

Enter the max value for day , normal value


1 31 1912 2 1 1912
for year and min value for month

Enter the max value for day , max -1 value


24 1 31 2011 2 1 2011
for year and min value for month

Enter the max value for day , max value


25 1 31 2012 2 1 2012
for year and min value for month

Dept. of ISE, BNMIT 2021-22 Page 19


Software Testing Laboratory 18ISL66

Next date Output Special value test cases


Case Input Data Expected Output Actual output Status
Description
Id month day year month day year month day year Comment
Should display the
1 Enter the D1, M1 and Y1 valid cases 12 31 1811 message value of the year
in range 1812..2012

2 Enter the D1, M1 and Y2 valid cases 12 31 2011 1 1 2012

Should display the


3 Enter the D1, M1 and Y3 valid cases 12 31 2013 message Next date is out
of boundary 2013

Dept. of ISE, BNMIT 2021-22 Page 20


Software Testing Laboratory 18ISL66
Program 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

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.

Dept. of ISE, BNMIT 2021-22 Page 21


Software Testing Laboratory 18ISL66
Types of equivalence class testing:

Following are four types of equivalence class testing:


1) Weak Normal Equivalence Class Testing.
2) Strong Normal Equivalence Class Testing.
3) Weak Robust Equivalence Class Testing.
4) Strong Robust Equivalence Class Testing.

1) Weak Normal Equivalence Class Testing:

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.

2) Strong Normal Equivalence Class Testing:

Dept. of ISE, BNMIT 2021-22 Page 22


Software Testing Laboratory 18ISL66
This type of testing is based on the multiple fault assumption theory. So, now we need test cases from
each element of the Cartesian product of the equivalence classes, as shown in the following figure.

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.

3) Weak Robust Equivalence Class Testing:


The name for this form of testing is counter intuitive and oxymoronic. The word' weak' means single
fault assumption theory and the word 'Robust' refers to invalid values. The test cases resulting from
this strategy are shown in the following figure.

Dept. of ISE, BNMIT 2021-22 Page 23


Software Testing Laboratory 18ISL66

Following two problems occur with robust equivalence testing.


a) Very often the specification does not define what the expected output for an invalid test case
should be. Thus, testers spend a lot of time defining expected outputs for these cases.
b) Strongly typed languages like Pascal, Ada, eliminate the need for the consideration of invalid
inputs. Traditional equivalence testing is a product of the time when languages such as FORTRAN, C
and COBOL were dominant. Thus this type of error was quite common.

4) Strong Robust Equivalence Class Testing:


This form of equivalence class testing is neither counter intuitive nor oxymoronic, but is just
redundant. As explained earlier also, 'robust' means consideration of invalid values and the 'strong'
means multiple fault assumption. We obtain the test cases from each element of the Cartesian product
We find here that we have 8 robust (invalid) test cases and 12 strong or valid inputs. Each one is
represented with a dot. So, totally we have 20 test cases (represented as 20 dots) using this technique.

Dept. of ISE, BNMIT 2021-22 Page 24


Software Testing Laboratory 18ISL66

Guidelines for Equivalence Class Testing:


1) The weak forms of equivalence class testing (normal or robust) are not as comprehensive as the
corresponding strong forms.
2) If the implementation language is strongly typed and invalid values cause run-time errors then
there is no point in using the robust form.
3) If error conditions are a high priority, the robust forms are appropriate.
4) Equivalence class testing is approximate when input data is defined in terms of intervals and sets of
discrete values. This is certainly the case when system malfunctions can occur for out-of-limit
variable values.
5) Equivalence class testing is strengthened by a hybrid approach with boundary value testing (BVA).
6) Equivalence class testing is used when the program function is complex. In such cases, the
complexity of the function can help identify useful equivalence classes.
7) Strong equivalence class testing makes a presumption that the variables are independent and the
corresponding multiplication of test cases raises issues of redundancy. If any dependencies occur,
they will often generate "error" test cases.
8) Several tries may be needed before the "right" equivalence relation is established.
9) The difference between the strong and weak forms of equivalence class testing is helpful in the
distinction between progression and regression testing.

Dept. of ISE, BNMIT 2021-22 Page 25


Software Testing Laboratory 18ISL66
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("\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));

// to check is it a triangle or not


if(c1&&c2&&c3)
{
if( a<b+c && b<a+c && c<a+b )
istriangle=1;
else
istriangle=0;
}

Dept. of ISE, BNMIT 2021-22 Page 26


Software Testing Laboratory 18ISL66
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;
}

Dept. of ISE, BNMIT 2021-22 Page 27


Software Testing Laboratory 18ISL66

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

Weak Normal Equivalence class Testing


Input Data
Case Id Description Expected Output Actual Output Status Comments
a b C
Enter the valid values for a , b and Should display the message
3-WN1 5 5 5 Equilateral triangle Pass -
c Equilateral triangle

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

Weak Robust Equivalence class Testing


3-WR1 Enter the valid values for a ,b and c 5 5 5 Should display the message Pass -
Equilateral triangle
Equilateral triangle
3-WR2 Enter the valid values for a ,b and c 2 2 3 Should display the message Pass -
Isosceles triangle
Isosceles triangle
3-WR3 Enter the valid values for a ,b and c 3 4 5 Should display the message Pass -
Scalene triangle
Scalene triangle
3-WR4 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

Dept. of ISE, BNMIT 2021-22 Page 28


Software Testing Laboratory 18ISL66

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 -

Dept. of ISE, BNMIT 2021-22 Page 29


Software Testing Laboratory 18ISL66

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

Dept. of ISE, BNMIT 2021-22 Page 30


Software Testing Laboratory 18ISL66

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

Dept. of ISE, BNMIT 2021-22 Page 31


Software Testing Laboratory 18ISL66
Program 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..

/* 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
{

Dept. of ISE, BNMIT 2021-22 Page 32


Software Testing Laboratory 18ISL66
temp=tlocks+locks;
if(temp>70)
printf("new total locks =%d not in the range 1..70 so old ",temp);
else
tlocks=temp;
}
printf("total locks = %d\n",tlocks);

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);

Dept. of ISE, BNMIT 2021-22 Page 33


Software Testing Laboratory 18ISL66
printf("\nenter the number of locks and to exit the loop enter -1 for locks\n");
scanf("%d",&locks);
}

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;

printf("the commission is=%f\n",comm);


}
else
printf("there is no sales\n");
return 0;
}

Dept. of ISE, BNMIT 2021-22 Page 34


Software Testing Laboratory 18ISL66

Test Case Name :Equivalence Class for Commission Problem


Experiment Number : 5
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% Upto 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.
Calculating the sales and commission of a sales person depending on number of locks stocks and barrels he sells per month.

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}

Dept. of ISE, BNMIT 2021-22 Page 35


Software Testing Laboratory 18ISL66

Commission Problem Output Equivalence Class Testing


Weak Normal Equivalence class & Strong Normal Equivalence Class
Input Data Expected Output Actual output
Case
Description Total Total Total Commis Status Comment
Id Sales Commission Sales
Locks Stocks Barrels sion
WN1 Enter the value within the range for 35 40 45 3900 640
SN1 locks,stocks and barrels
WN2 Enter the value within the range for -1 Exit from the input loop.Proceed to
- -
SN2 locks,stocks and barrels calculate sales and commission

Weak Robustness equivalence Class


Case Input Data Expected Output
Description Actual output Status Comment
Id Locks Stocks Barrels Sales Commission
Enter the value within the range for 35 40 45
WR1 3900 640
locks,stocks and barrels
Exit from the input loop.
Enter the value within the range for -1 - -
WR2 Proceed to calculate sales and
locks,stocks and barrels
commission

-6 4 2 Message saying Value of Locks not


WR3 Enter the value locks = -1
in the range 1..70
Enter the value less than -1 or equal to 0 40 45 Message saying Value of Locks not
WR4
zero for locks and other valid inputs in the range 1..70

Dept. of ISE, BNMIT 2021-22 Page 36


Software Testing Laboratory 18ISL66
Enter the value greater than 70 for 71 40 45 Message saying Value of Locks not
WR5
locks and other valid inputs in the range 1..70
Enter the value less than or equal than 35 0 45 Message saying Value of stocks not
WR6
0 for stocks and other valid inputs in the range 1..80
Enter the value greater than 80 for 35 81 45 Message saying Value of stocks not
WR7
stocks and other valid inputs in the range 1..80
Enter the value less than or equal 0 for 35 40 0 Message saying Value of Barrels
WR8
barrels and other valid inputs not in the range 1..90
Enter the value greater than 90 for 35 40 91 Message saying Value of Barrels
WR9
barrels and other valid inputs not in the range 1..90

Strong Robustness equivalence Class


Input Data
Case Id Description Expected Output Actual output Status Comment
Locks Stocks Barrels
Enter the value within the range for 35 40 45 640
SR1 3900
locks,stocks and barrels
Enter the value within the range for -1 - - Exit from the input loop.Proceed to calculate sales and
SR2
locks,stocks and barrels commission
Enter the value less than -1 for locks -2 40 45 Message saying Value of Locks not
SR3
and other valid inputs in the range 1..70
Enter the value less than or equal
Message saying Value of stocks not
SR4 than 0 for stocks and other valid 35 -1 45
in the range 1..80
inputs
Enter the value less than or equal 0 35 40 -2 Message saying Value of Barrels
SR5
for barrels and other valid inputs not in the range 1..90
Message saying Value of Locks not
Enter the locks and stocks less than -2 -1 45 in the range 1..70
SR6
or equal to 0 and other valid inputs Message saying Value of stocks not
in the range 1..80

Dept. of ISE, BNMIT 2021-22 Page 37


Software Testing Laboratory 18ISL66
Message saying Value of Locks not
Enter the locks and barrel less than -2 40 -1 in the range 1..70
SR7
or equal to 0 and other valid inputs Message saying Value of Barrels
not in the range 1..90
Message saying Value of stocks not
Enter the stocks and barrel less than 35 -1 -1 in the range 1..80
SR8
or equal to 0 and other valid inputs Message saying Value of Barrels
not in the range 1..90
Message saying Value of Locks not
in the range 1..70
Enter the stocks and barrel less than -2 -2 -2 Value of stocks not in the range
SR9
or equal to 0 and other valid inputs 1..80
Value of Barrels not in the range
1..90

Some addition equivalence Boundary checking


Input Data Expected Output Actual output
Case Id Description Total Total Total Comm
Sales Commission Sales Status Comment
Locks Stocks Barrels ission

Enter the value for lock, stocks and 5 5 5


OR1 500 50
barrels where 0 < Sales < 1000
Enter the value for lock, stocks and 15 15 15
OR2 1500 175
barrels where 1000 < Sales < 1800
Enter the value for lock, stocks and 25 25 25
OR3 2500 360
barrels where Sales < 1800

Dept. of ISE, BNMIT 2021-22 Page 38


Software Testing Laboratory 18ISL66

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;

Dept. of ISE, BNMIT 2021-22 Page 39


Software Testing Laboratory 18ISL66
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>2013)
{
printf("value of year, not in the range 1812.......2012\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';

Dept. of ISE, BNMIT 2021-22 Page 40


Software Testing Laboratory 18ISL66
}
}
}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;

Dept. of ISE, BNMIT 2021-22 Page 41


Software Testing Laboratory 18ISL66
case 12: if(day<31)
tomm_day=day+1;
else
{
tomm_day=1;
tomm_month=1;
if(year==2012)
{
printf("the next day is out of boundary value of year\n");
return 0;
}
else
tomm_year=year+1;
}
break;
case 2:
if(day<28)
tomm_day=day+1;
else if(isleap(year)&& day==28)
tomm_day=day+1;
else if(day==28 || day==29)
{
tomm_day=1;
tomm_month=3;
}
break;
}
printf("next day is : %d %d %d",tomm_day,tomm_month,tomm_year);
return 0;
}

Dept. of ISE, BNMIT 2021-22 Page 42


Software Testing Laboratory 18ISL66
Test Case Name : Equivalence class test cases for Next date
Experiment Number :6
Test data : Enter the three integer value
Pre-condition : Month 1 to 12 , DAY 1 TO 31 AND YEAR 1812 TO 2013
Valid Cases
M1 = { month ; 1 ≤ month ≤ 12 }
D1 = { day : 1 ≤ day ≤ 31 }
Y1 = { year : 1812 ≤ year ≤ 2012 }

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}

Next date Output Equivalence Class Testing


( Weak and Strong Normal Equivalence Class )

Case Input Data Expected Output Actual output


Description Status Comment
Id month day year month day year month day year
WN1,
6 15 1912 6 16 1912
SN1 Enter the M1, D1 and Y1 valid cases

Dept. of ISE, BNMIT 2021-22 Page 43


Software Testing Laboratory 18ISL66

( Weak Robustness Equivalence Class )

Case Input Data Expected Output Actual output Status Comment


Description
Id month day year month day year month day year

Enter the M1, D1 and Y1


WR1 6 15 1912 6 16 1912
cases
Enter the M2 , D1 and Y1 Should display the message value
-1 15 1912
WR2 cases of the month not in the range 1..12
Enter the M3 ,D1 and Y1 Should display the message value
13 15 1912
WR3 cases of the month not in the range 1..12
Should display the message value
6 -1 1912
WR4 Enter the M1, D2 and Y1 cases of the day not in the range 1..31
Should display the message value
6 32 1912
WR5 Enter the M1, D3 and Y1 cases of the day not in the range 1..31
Should display the message value
Enter the M1, D1 and Y2 6 15 1811 of the year not in the range
WR6 cases 1812..2012
Should display the message value
Enter the M1, D1 and Y3 6 15 2014 of the year not in the range
WR7 cases 1812..2012

Dept. of ISE, BNMIT 2021-22 Page 44


Software Testing Laboratory 18ISL66
(Strong Robustness Equivalence Class )
Case Input Data
Description Expected Output Actual output Status Comment
Id month day year

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

Dept. of ISE, BNMIT 2021-22 Page 45


Software Testing Laboratory 18ISL66
(iii) Should display the message
value of the year in range
1812..2013
Enter the M1, D1 and Y1
SR8 6 15 1912 6 -16-1912
cases
Some addition equivalence Boundary checking
Input Data Expected Output Actual output
Case
Description mo mon Status Comment
Id day year day month year day year
nth th
Should display the
1 Enter the D1, M1 and Y1 valid cases 31 12 1811 message value of the year
in range 1812..2013

2 Enter the D1, M1 and Y2 valid cases 31 12 2011 1 1 2012

Should display the


3 Enter the D1, M1 and Y3 valid cases 31 12 2012 message Next date is out
of boundary 2012

Dept. of ISE, BNMIT 2021-22 Page 46


Software Testing Laboratory 18ISL66
Program 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 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.
Decision table is based on logical relationships just as the truth table.
It is a tool that helps us look at the “complete” combination of conditions

Components of a Decision Table


rules

R1 R2 R3 R4 R5 R6 R7 R8

C1 T T T T F F F F

conditions C2 T T F F T T F F values of conditions

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

Read a Decision Table by columns of rules : R1 says when all conditions


are T, then actions a1, a2, and a5 occur

 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)

Dept. of ISE, BNMIT 2021-22 Page 47


Software Testing Laboratory 18ISL66
- Then the inputs must satisfy certain conditions:
• a<b+c
• b<a+c
• c<a+b

Triangle Problem Example


Assume a, b and c are Pick input <a, b, c> for each of the columns
all 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

 There is the “invalid situation” --- not a triangle:


- There are 3 test conditions in the Decision table
- Note the “-” entries, which represents “don’t care,” when it is determined that the input sides <a,
b, c> do not form a triangle
 There is the “valid” triangle situation:
- There are 3 types of valid; so there are 23 = 8 potential conditions
- But there are 3 “impossible” situations
- So there are only 8 – 3 = 5 conditions
 So, for valid values of a, b, and c, we need to come up with 8 sets of <a, b, c> to test the 8
“Rules”.
 Advantages:
- Allow us to start with a “complete” view, with no consideration of dependence
- Allow us to look at and consider “dependence,” “impossible,” and “not relevant” situations and
eliminate some test cases.
- Allow us to detect potential error in our specifications
 Disadvantages:
- Need to decide (or know) what conditions are relevant for testing
- Scaling up can be massive: 2n for n conditions.

Dept. of ISE, BNMIT 2021-22 Page 48


Software Testing Laboratory 18ISL66

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;
}

Dept. of ISE, BNMIT 2021-22 Page 49


Software Testing Laboratory 18ISL66

Test Case Name :Decision table for triangle problem


Experiment Number : 7
Test Data : Enter the 3 Integer Value( a , b And c )
Pre-condition : 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

Input data decision Table


RULES 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
C2 : b < a + c - F T T T T T T T T T
C3 : c < a + b - - F T T T T T T T T
Conditions
C4 : a = b - - - T T T T F F F F
C5 : a = c - - - T T F F T T F F
C6 : b = c - - - T F T F T F T F
a1 : Not a triangle X X X
a2 : Scalene triangle X
Actions a3 : Isosceles triangle X X X
a4 : Equilateral triangle X
a5 : Impossible X X X

Dept. of ISE, BNMIT 2021-22 Page 50


Software Testing Laboratory 18ISL66

Triangle Problem -Decision Table Test cases for input data

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

Dept. of ISE, BNMIT 2021-22 Page 51


Software Testing Laboratory 18ISL66

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

Dept. of ISE, BNMIT 2021-22 Page 52


Software Testing Laboratory 18ISL66
{
temp=tlocks+locks;
if(temp>70)
printf("new total locks =%d not in the range 1..70 so old ",temp);
else
tlocks=temp;
}
printf("total locks = %d\n",tlocks);

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;
}

Dept. of ISE, BNMIT 2021-22 Page 53


Software Testing Laboratory 18ISL66
printf("total barrel=%d",tbarrels);
printf("\nenter the number of locks and to exit the loop enter -1 for locks\n");
scanf("%d",&locks);
}
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;

printf("the commission is=%f\n",comm);


}
else
printf("there is no sales\n");
return 0;
}

Dept. of ISE, BNMIT 2021-22 Page 54


Software Testing Laboratory 18ISL66

Test Case Name :Decision Table for Commission Problem


Experiment Number : 8
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% Upto 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. Calculate sales and commission based on number of
locks ,stocks and barrels sold.
Input data decision Table
RULES R1 R2 R3 R4 R5 R6 R7 R8 R10
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
a6: Calculate Sales X
a7: proceed to commission decision table X

Dept. of ISE, BNMIT 2021-22 Page 55


Software Testing Laboratory 18ISL66

Commission calculation Decision Table


Precondition : lock = -1
RULES R1 R2 R3 R4
C1 : Sales = 0 T F F F
C1 : Sales > 0 AND Sales ≤ 1000 T F F
Condition
C2 : Sales > 1001 AND sales ≤ 1800 T F
C3 : sales ≥1801 T
A1 : Terminate the program X
A2 : comm= 10%*sales X
Actions 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

Dept. of ISE, BNMIT 2021-22 Page 56


Software Testing Laboratory 18ISL66

Commission Problem -Decision Table Test cases for input data


Input Data
Case Actual
Description Expected Output Status Comments
Id Locks Stocks Barrels Output

Terminate the input loop check for sales


1 Enter the value of Locks= -1 -1 if(sales=0) exit from program else
calculate commission

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

Dept. of ISE, BNMIT 2021-22 Page 57


Software Testing Laboratory 18ISL66
(i)Should display value of lock is not in
the range 1..70 (ii)Should display value of
8 Enter the invalid input for lock , -5 -8 -9 stocks is not in the range 1..80 (iii)Should
stocks and barrels
display value of barrel in not in the range
1..90
Total of locks,stocks and barrels is
Enter the valid input for lock, 15 updated if it is within a precondition limit
9 20 25 -
stocks and barrels 5 and calculate the sales and proceed to
commission

Commission Problem -Decision Table Test cases for commission calculation


Precondition : Locks = -1

Input Data Expected Output


Case Actual
Description Status Comments
Id Sales Commission Values Output

Terminate the program where commission 0


1 Check the value of sales 0
is zero
if sales value with in these range( 900
2 900 Then commission = 0.10*sales = 90
Sales > 0 AND Sales ≤ 1000 )
if sales value with in these range( Then commission = 0.10*1000 + 1600
3 1400
Sales > 1000 AND Sales ≤ 1800 ) 0.15*(sales - 1000)
if sales value with in these range( Then commission = 0.10*1000 + 3400
4 2500
Sales > 1800 0.15*800 + 0.20 *(sales - 1800)

Dept. of ISE, BNMIT 2021-22 Page 58


Software Testing Laboratory 18ISL66

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..

Data Flow Testing


Data flow testing is a technique used to detect improper use of data in a program. By looking data
usage, risky areas of code can be found and more test cases can be applied.To test data flow we devise
control flow graph. A data-flow graph (DFG) is a graph which represents data dependencies between a
number of operations.
Data Flow Anomalies
Data flow anomalies represent the rules which help to detect improper use of data. The notation
used to define these anomalies

 d – defined, created, initialized


 k – undefined, killed
 u – used
c – Computation use
p – Predicate use
 ~x - all prior actions are not of interest to x
 x~ - all post actions are not of interest to x
o Anomalies which shows normal use of data
~d Defined first
du define –> use
kd kill –> define
ud use –> define
uk use –> kill
uu use –> use
k~ kill last
u~ use last
Anomalies which shows bug and should be avoided in the programs
~u first use Bug. Data is used without definition.
~k first kill Bug. Data is killed without defining it.
dd define–define Bug. Redefinition of data.
dk define –> kill Bug. Data is killed without using it.
kk kill – kill Bug. Destroying already killed data.

Dept. of ISE, BNMIT 2021-22 Page 59


Software Testing Laboratory 18ISL66

ku kill – use Bug. Data is used after destroying it.


d~ define last Bug. Defining but not using it.

Program 9: (Dataflow Testing for commission calculation)


1.#include<stdio.h>
2. int main()
3. {
4. int locks, stocks, barrels, tlocks, tstocks, tbarrels;
5.float lprice,sprice,bprice,lsales,ssales,bsales,sales,comm;
6.lprice=45.0;
7.sprice=30.0;
8.price=25.0;
9.tlocks=0;
10.tstocks=0;
11.tbarrels=0;
12.printf("\nenter the number of locks and to exit the loop enter -1 for locks\n");
13.scanf("%d", &locks);
14.while(locks!=-1)
15.{
16.printf("enter the number of stocks and barrels\n");
17.scanf("%d%d",&stocks,&barrels);
18. tlocks=tlocks+locks;
19. tstocks=tstocks+stocks;
20. tbarrels=btarrels+barrels;
21. printf("\nenter the number of locks and to exit the loop enter -1 for locks\n");
22. scanf("%d",&locks);
23 }
24.printf("\ntotal locks = %d\”,tlocks);
25.printf(“total stocks =%d\n”,tstocks);
26.printf(“total barrels =%d\n",tbarrels);
27.lsales = lprice*tlocks;
28.ssales=sprice*tstocks;

Dept. of ISE, BNMIT 2021-22 Page 60


Software Testing Laboratory 18ISL66

29.bsales=bprice*tbarrels;
30.sales=lsales+ssales+bsales;

31.if(sales > 1800.0)


32{
33 comm=0.10*1000.0;
34 comm=comm+0.15*800;
35 comm=comm+0.20*(sales-1800.0);
36}
37 else if(sales > 1000)
38{
39 comm =0.10*1000;
40 comm=comm+0.15*(sales-1000);
41}
42 else
43 comm=0.10*sales;
44 printf("the commission is=%f\n",comm);
45 return 0;
46}

Dept. of ISE, BNMIT 2021-22 Page 61


Software Testing Laboratory 18ISL66
Test Case Name : Data Flow Testing for Commission Program
Experiment No : 9
Precondition : Enter -1 for locks to exit from input loop
Brief Description : Enter the locks, stocks and barrels > 0

Define /Use nodes for variables in the commission problem


Variable
Defined at node Used at Node
name
lprice 6 27
sprice 7 28
bprice 8 29
tlocks 9,18 18,24,27
tstocks 10,19 19,25,28
tbarrels 11,20 20,26,29
locks 13,22 14,18
stocks 17 19
barrels 17 20
lsales 27 30
ssales 28 30
bsales 29 30
sales 30 31,35,37,40,43

comm 33,34,35,39,40,43 34,35,40,44

Dept. of ISE, BNMIT 2021-22 Page 62


Software Testing Laboratory 18ISL66

Selected Define/Use Paths for Commission problem

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>

DEF(tlocks,16)) and 3 usage node(USE(tlocks,18), <9-10-11-12-13-14-15-16-17-18-19-20- -


4 (9, 27) No
USE(tlocks,24),USE(tlocks,27) 21-22-23-14-24-25-26-27>
(18, 18) <18-18> Yes -
(18, 24) <18-19-20-21-22-23-14-24> No -
(18, 27) <18-19-20-21-22-23-14-24-25-26-27> No -
Check for total stocks variable DEF((tstocks,10) and (10 , 19) <10-11-12-13-14-15-16-17-18-19> Yes -
5 DEF(tstocks,19)) and 3 usage node(USE(tstocks,19), <10-11-12-13-14-15-16-17-18-19-20-21- -
(10 , 25) No
USE(tstocks,25),USE(tstocks,28) 22-23-14-24-25>

Dept. of ISE, BNMIT 2021-22 Page 63


Software Testing Laboratory 18ISL66
<10-11-12-13-14-15-16-17-18-19-20-21- -
(10, 28) No
22-23-14-21-23-24-25-26-27-28>
(19 , 19) <19-19> Yes -
(19 , 25) <19-20-21-22-23-14-24-25> No -
(19 , 28) <19-20-21-22-23-14-24-25-26-27-28> No -
(11 , 20) <10-11-12-13-14-15-16-17-18-19> Yes -
-
<11-12-13-14-15-16-17-18-19-20-21-22-
(11,26) No
Check for total stocks variable DEF((tbarrels,11) and 23-14-24-25-26>
DEF(tbarrels,20)) and 3 usage <11-12-13-14-15-16-17-18-19-20-21-22-
6 (11,29) No
node(USE(tbarrelss,20), 23-14-24-25-26-27-28-29>
USE(tbarrels,26),USE(tbarrels,29) (20,20) <20-20> Yes
(20,26) <20-21-22-23-14-24-25-26> No
(20,29) <20-21-22-23-14-24-25-26-27-28-29> No
(13 , 14) <13-14> Yes -
check for locks variable (DEF(locks,13) ( 13 , 18) <13-14-15-16-17-18> Yes -
7
,DEF(locks,22) and USE(locks,14),USE(locks,18) (22 , 14) <22-23-14> Yes -
(22 , 18) <22-23-14-15-16-17-18> Yes -
Check for stocks variable (DEF(stocks,17) and -
8 (17 , 19) <17-18-19> Yes
USE(stocks,19)
Check for stocks variable (DEF(barrels,17) and -
9 (17,20) <17-18-19-20> Yes
USE(barrels,20)
Check for stocks variable (DEF(lsales,27) and -
10 (27,30) <27-28-29-30> yes
USE(lsales,30)

Dept. of ISE, BNMIT 2021-22 Page 64


Software Testing Laboratory 18ISL66
Check for stocks variable (DEF(ssales,28) and -
11 (28,30) <28-29-30> yes
USE(ssales,30)
Check for stocks variable (DEF(bsales,29) and -
12 (29,30) <29-30> yes
USE(bsales,30)
(30 ,31) <30-31> Yes -
Check for sales DEF(sales, 30) and USE(Sales, 31), (30 , 35) <30-31-32-33-34-35> Yes -
14 USE(Sales , 35), USE(Sales,37) , USE(Sales , 40) , (30 , 37) <<30-31-37> Yes -
USE(Sales,43) (30 , 40) <30-31-37-38-39-40> Yes -
(30 , 43) <30-31-37-42-43> Yes -

Check for Commission variable DEF(comm, ( (33,34,35),44) <33-34-35-44> Yes -

9 33,34,35) , DEF(comm,39,40) and DEF(comm,43) ((39 , 40) , 44) <39-40-44> Yes -


and USE(comm,44) (43 , 44 ) <43 - 44> Yes -

Dept. of ISE, BNMIT 2021-22 Page 65


Software Testing Laboratory 18ISL66

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, …

Dept. of ISE, BNMIT 2021-22 Page 66


Software Testing Laboratory 18ISL66
If all of these paths are executed we can be sure that every statement in the method has
been executed at least once and that every branch has been exercised for true and false
conditions. The number of tests that you need to ensure that all paths through the program are
exercised is the same as the cyclomatic complexity of the code fragment that is being tested.

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++)

Dept. of ISE, BNMIT 2021-22 Page 67


Software Testing Laboratory 18ISL66
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;
}

Binary Search function with line number


int binsrc(int x[],int low, int high, int key)
{
1. int mid;
2. while(low<=high)
{
3. mid=(low+high)/2;
4. if(x[mid]==key)
9. return mid;
5. else if(x[mid]<key)
6. low=mid+1;
else
7. high=mid-1;
8.}
9. return -1;
10.}

Dept. of ISE, BNMIT 2021-22 Page 68


Software Testing Laboratory 18ISL66

Program Graph – for Binary Search

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

Test Cases – Binary Search

Dept. of ISE, BNMIT 2021-22 Page 69


Software Testing Laboratory 18ISL66

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);
}
}

Dept. of ISE, BNMIT 2021-22 Page 70


Software Testing Laboratory 18ISL66
// 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”);
}

Dept. of ISE, BNMIT 2021-22 Page 71


Software Testing Laboratory 18ISL66
Quick sort function with line number

Independent Paths:
#Edges=18, #Nodes=13, #P=1
V(G)= E-N+2P = 18-13+2 = 7

Dept. of ISE, BNMIT 2021-22 Page 72


Software Testing Laboratory 18ISL66
Program Graph – Quick Sort
Independent Paths– Quick Sort
P1: A-B-M
P2: A-B-C-J-K-A
P3: A-B-C-J-K-L-A
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
Pre-Conditions/Issues:
Array has only one Element, Two Elements, Three Elements (6 Possibilities)
Array has Elements in ASC/DSC/Arbitrary( Any of the Permutations)
EX: 3 elements: 123, 132, 213, 231, 312, 321, + 222,111,333
Test Cases – Quick Sort
Case Input
Paths Expected output Actual output comments
id x[]
Single
Elements in
1 P1: A-B-M 5 sorted element in
sorted order 5
array
Two
Elements in
2 P2: A-B-C-J-K-A 5,3 Repeat and sort elements in
sorted order 3 ,5
array
Elements in Three
3 P3: A-B-C-J-K-L-A 5,2,1 Repeat and sort sorted order 1, 2 element in
,5 array
Elements in Element in
4 P4: A-B-C-D-F-H-C 1,2,3,4,5 Repeat and sort sorted order ascending
1,2,3,4,5 order
Elements in Element in
5 P5: A-B-C-D-F-H-I-C 5,4,3,2,1 Repeat and sort sorted descending
order5,4,3,2,1 order
Elements in Pivot is
6 P6: A-B-C-D-E-D-F-H 5,1,4,3,2 Repeat and sort sorted order minimum
1,2,3,4,5
Elements in Pivot is
P7: A-B-C-D-F-G-F-
7 1,3,4,2,5 Repeat and sort sorted maximum
H
order1,2,3,4,5

Dept. of ISE, BNMIT 2021-22 Page 73


Software Testing Laboratory 18ISL66
Program 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)
{
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;
}

Absolute Grading Program with Line Numbers and Program Graph

Dept. of ISE, BNMIT 2021-22 Page 74


Software Testing Laboratory 18ISL66

Independent Paths:
#Edges=25, #Nodes=18, #P=1
V(G)= E-N+2P = 25-18+2 = 09

P1: 1-2-3-11-12-17-18 A Grade


P2: 1-2-4-5-11-13-17-18 B Grade
P3: 1-2-4-6-7-11-14-17-18 C Grade
P4: 1-2-4-6-8-9-11-15-17-18 D Grade
P5: 1-2-4-6-8-10-11-16-17-18 E Grade
P6: 1-2-4-6-8-10-11-12-17-18
P7: 1-2-4-6-8-10-11-13-17-18
P8: 1-2-4-6-8-10-11-14-17-18
P9: 1-2-4-6-8-10-11-15-17-18

Pre-Conditions/Issues:
Percentage Per is a positive Float Number

Dept. of ISE, BNMIT 2021-22 Page 75


Software Testing Laboratory 18ISL66
Test Cases – Absolute Grading
EXPECTED ACTUAL
CASE ID PATHS INPUT STATUS
OUTPUT OUTPUT
Excellent
P1: 1-2-3-11-12- Grade:A
1 95 The percentage is Pass
17-18 Excellent
95 and grade is A
Very good
P2: 1-2-4-5-11- Grade:B
2 The percentage is Pass
13-17-18 85 Very good
85 and grade is B
Good
P3: 1-2-4-6-7-11- Grade:C
3 75 The percentage is Pass
14-17-18 Good
75 and grade is C
Average
P4: 1-2-4-6-8-9- Grade:D
4 65 The percentage is Pass
11-15-17-18 Average
65 and grade is D
Satisfactory
P5: 1-2-4-6-8-10- Grade:E
5 55 The percentage is Pass
11-16-17-18 satisfactory
55 and grade is E
P6: 1-2-4-6-8- - -
6 55 Fail
10-11-12-17-18
P7: 1-2-4-6-8- - - Fail
7 60
10-11-13-17-18
P8: 1-2-4-6-8- - - Fail
8 88
10-11-14-17-18
P9: 1-2-4-6-8- - - Fail
9 99
10-11-15-17-18

Open ended questions:

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

Dept. of ISE, BNMIT 2021-22 Page 76


Software Testing Laboratory 18ISL66
testing) that can be used for the same and derive different test cases, execute these test
cases and discuss the test results.

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.

Sample Viva Questions:


1. What is software testing?
2. Define error, fault, failure, incident, test case?
3. What are the approaches to identify test cases?
4. What is structural and functional testing?
5. What is black box testing?
6. What is white box testing?
7. What is boundary value analysis?
8. How many number of test cases does bva yield?
9. What are the values assumed for bva?
10. What are the limitations of bva?
11. What is robustness testing?
12. What is the maximum number of test cases generated by robust testing?
13. What is worst case testing?
14. What is the maximum number of test cases generated by worst case testing?
15. What is special value testing?
16. What is robust worst case testing?
17. What is the maximum number of test cases generated by robust worst case testing?
18. What is random testing?
19. What are equivalence classes?
20. What is equivalence class testing?
21. What are the different types of 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. What is triangle problem?
27. What is commission problem?

Dept. of ISE, BNMIT 2021-22 Page 77


Software Testing Laboratory 18ISL66
28. What is next date problem?
29. What is decision table testing?
30. What are the various parts of a decision table?
31. What is rule count?
32. What are the examples of functional testing?
33. What are the examples of structural testing?
34. What is path testing?
35. What is a DD-path?
36. What is a program graph?
37. What is predicate testing?
38. What is DD-path testing?
39. What are the different types of loops?
40. What is a strongly connected graph?
41. What is basic/Mc Cabe basic path testing?
42. What is cylomatic number?
43. What are the violations of structural programming?
44. What is the maximum cyclomatic complexity?
45. What is the minimum cyclomatic complexity?
46. What is dataflow testing?
47. What is define/use testing?
48. What is defining node?
49. What is usage node?
50. What is DU path?
51. What is a DC path?
52. What is All-definitions criterion and All-uses criterion?
53. What is All-P-uses/Some C-uses criterion?
54. What is slice based testing?
55. What is a slice?
56. What are the different forms of usage in USE relationship?
57. What are the two forms of definition nodes?
58. What are the various levels of testing?
59. What is system testing?
60. What is integration testing?
61. What are bottom-up and top-down approach?
62. What are drivers and stub?
63. What do you mean by executable specification?

Dept. of ISE, BNMIT 2021-22 Page 78


Software Testing Laboratory 18ISL66
64. What is context diagram?
65. What is a finite state machine diagram?
66. What is a decomposition tree?
67. What is a call graph?
68. What is decomposition based integration?
69. What is call-graph based integration?
70. What is bottom-up integration?
71. What is sandwich integration?
72. What is neighborhood integration?
73. What is pairwise integration?
74. What is path based integration?
75. What is a source node?
76. What is a sink node?
77. What is a module execution path?
78. What is a message?
79. What is a MM-path and a MM-path graph?
80. How do you compute cyclomatic complexity and MM-path complexity?
81. When does data quiescence occur?
82. Give the formula to find the number of stubs and drivers.

Dept. of ISE, BNMIT 2021-22 Page 79

You might also like