Software Testing Source Code
Software Testing Source Code
INDEX:
Sl. No. LIST OF PROGRAMS Page. No. Date
1. Design and develop a program in a language 1-7
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,
the test cases and discuss the results.
2. Design and develop a program in a language 8-12
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.
3. Design and develop a program in a language 13-18
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.
[1MV16MCA28] Page 1
SOFTWARE TESTING LABORATORY [16MCA48]
[1MV16MCA28] Page 2
SOFTWARE TESTING LABORATORY [16MCA48]
#include<stdio.h>
#include<conio.h>
void main()
{
inta,b,c;
clrscr();
printf("\nEnter the values for a,b and c:");
scanf("%d %d %d",&a,&b,&c);
if((a<=(b+c))&&(b<=(c+a))&&(c<=(a+b)))
{
printf("\nThis forms a triangle");
if((a==b)&&(a==c))
{
printf("\nThis is a Equilateral Triangle");
}
else if((a!=b) && (b!=c) && (c!=a))
{
printf("\nThis is a Scalene Triangle");
}
else
{
printf("\nThis is a Isosceles Triangle");
}
}
else
{
printf("\nThis will not form a triangle");
}
getch();
}
[1MV16MCA28] Page 3
SOFTWARE TESTING LABORATORY [16MCA48]
OUTPUT:
Test Case Name : Decision table for triangle problem
Program Number: 1
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 form a triangle
[1MV16MCA28] Page 4
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
[1MV16MCA28]
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
C4 : a = b - - - T T T T F F F F
Conditions
C5 : a = c - - - T T F F T T F F
SOFTWARE TESTING LABORATORY
C6 : b = c - - - T F T F T F T F
A2 : Scalene Triangle X
A3 : Isosceles Triangle X X X
Actions
A4 : Equilateral Triangle X
A5 : Impossible X X X
[16MCA48]
Page 5
Case Description Input Data Expected Actual Output Status Comments
ID Output
A B C
1 Enter the value of a,b 20 5 5 Message should This will not PASS Satisfied
and c such that a is be displayed form a triangle
[1MV16MCA28]
not less than sum of can’t form a
two sides triangle
2 Enter the value a,b, 3 15 11 Message should This will not PASS Satisfied
and c such that b is be displayed form a triangle
not less than sum of can’t form a
two sides and a is less triangle
than sum of other two
sides
3 Enter the value a,b, 4 5 20 Message should This will not PASS Satisfied
SOFTWARE TESTING LABORATORY
Page 6
precondition and a=b, Isosceles Triangle
b!=c Triangle
6 Enter the value a,b 5 6 7 Should display a This is a PASS Satisfied
and c satisfying message Scalene
precondition and Scalene Triangle
[1MV16MCA28]
a!=b, b!=c and c!=a Triangle
SOFTWARE TESTING LABORATORY
Page 7
SOFTWARE TESTING LABORATORY [16MCA48]
}
else
{
printf("\nThis will not form a triangle");
}
getch();
}
[1MV16MCA28] Page 8
SOFTWARE TESTING LABORATORY [16MCA48]
OUTPUT:
[1MV16MCA28] Page 9
Case Description Input Data Expected Output Actual Output Status Comments
ID
A B C
[1MV16MCA28]
1 Enter the min value 1 1 1 Should display This is a PASS Satisfied
for a, b and c the message Equilateral triangle
Equilateral
triangle
2 Enter the min value 1 1 2 Message should This will not form PASS Satisfied
for 2 items and be displayed a triangle
min+1 for any one can’t form a
item1 triangle
3 Enter the min value 1 2 1 Message should This will not form PASS Satisfied
SOFTWARE TESTING LABORATORY
Page 10
and 1 item is min Isosceles triangle
value
7 Enter the 1 5 5 Should display This is a Isosceles PASS Satisfied
nominalvalue for 2 the message triangle
items and 1 item is Isosceles triangle
min value
8 Enter the nominal 5 5 5 Should display This is a PASS Satisfied
[1MV16MCA28]
value for a, b and c the message Equilateral triangle
Equilateral
triangle
9 Enter the nominal 5 5 10 Should display This will not form PASS Satisfied
value for 2 items the message can’t a triangle
and 1 item is max form a triangle
value
SOFTWARE TESTING LABORATORY
10 Enter the nominal 5 10 5 Should display This will not form PASS Satisfied
value for 2 items the message can’t a triangle
and 1 item is max form a triangle
value
11 Enter the nominal 10 5 5 Should display This will not form PASS Satisfied
value for 2 items the message can’t a triangle
and 1 item is max form a triangle
value
12 Enter the max value 10 10 9 Should display This is a Isosceles PASS Satisfied
for 2 items and 1 the message triangle
item is max -1 for Isosceles triangle
[16MCA48]
Page 11
any one item
13 Enter the max value for 10 9 10 Should display This is a PASS Satisfied
2 items and max-1 for the message Isosceles
any one item Isosceles triangle triangle
[1MV16MCA28]
14 Enter the max value for 9 10 10 Should display This is a PASS Satisfied
2 items and max-1 for the message Isosceles
any one item Isosceles triangle triangle
15 Enter the max value for 10 10 10 Should display This is a PASS Satisfied
a,b and c the message Equilateral
Equilateral triangle
triangle
SOFTWARE TESTING LABORATORY
Page 12
SOFTWARE TESTING LABORATORY [16MCA48]
#include<stdio.h>
int main()
{
int a,b,c,c1,c2,c3;
char istriangle;
do
{
printf("\nEnter 3 integers which are sides of triangle");
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("\nValue of a is not the range of permitted value");
if (!c2)
printf("\nValue of b is not the range of permitted value");
if (!c3)
printf("\nValue of c is not the range of permitted value");
} while(!(c1 && c2 && c3));
printf("scalene triangle\n");
else
printf("isosceles triangle\n");
else
printf("Not a triangle\n");
return 0;
}
[1MV16MCA28] Page 14
SOFTWARE TESTING LABORATORY [16MCA48]
OUTPUT:
Test Case Name : Equivalence Class Analysis for triangle problem
Experiement Number : 3
Test Data : Enter 3 Integer Values( 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 values for a Equilateral, Isosceles,
Scalene
triangle or can’t form a triangle
[1MV16MCA28] Page 15
Case Description Input Data Expected Output Actual Output Status Comments
ID
A B C
[1MV16MCA28]
1 Enter the mid 5 5 5 Should display This is a PASS Satisfied
value for a, b the message Equilateral
and c Equilateral triangle
trianglle
2 Enter the min 2 2 3 Should display This is a PASS Satisfied
value for a, b the message Isosceles
and min+1 Isosceles triangle
for any one triangle
item
SOFTWARE TESTING LABORATORY
4 Enter the min 4 1 2 Message should This will not PASS Satisfied
value for 1 be displayed form a triangle
item and any can’t form a
Triangle Problem –Equivalence class Testing
Page 16
5 Enter one invlaid -1 5 5 Should display value of a is not PASS Satisfied
input and two valid value of a is not in the range of
value for a,b and c in the range of permitted values
permitted values
[1MV16MCA28]
6 Enter one invlaid 5 -1 5 Should display value of b is not PASS Satisfied
input and two valid value of b is not in the range of
value for a,b and c in the range of permitted values
permitted values
7 Enter one invlaid 5 5 -1 Should display value of c is not PASS Satisfied
input and two valid value of c is not in the range of
value for a,b and c in the range of permitted values
permitted values
8 Enter one invlaid 11 5 5 Should display value of a is not PASS Satisfied
SOFTWARE TESTING LABORATORY
Page 17
11 Enter one invalid -1 5 5 Should display value value of a is not PASS Satisfied
input and two valid of a is not in the in the range of
value for a,b and c range of permitted permitted values
values
12 Enter one invalid 5 -1 5 Should display value value of b is not PASS Satisfied
[1MV16MCA28]
input and two valid of b is not in the in the range of
value for a,b and c range of permitted permitted values
values
13 Enter one invalid 5 5 -1 Should display value value of c is not PASS Satisfied
input and two valid of a is not in the in the range of
value for a,b and c range of permitted permitted values
values
14 Enter two invalid -1 -1 5 Should display value value of a and b PASS Satisfied
inputs and one valid of a and b is not in is not in the
SOFTWARE TESTING LABORATORY
Page 18
the range of range of
permitted values permitted values
SOFTWARE TESTING LABORATORY [16MCA48]
4. 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.
2. #include<stdio.h>
3. int main()
4. {
5. int locks,stocks,barrels,tlocks,tstocks,tbarrels;
6. float lprice,sprice,bprice,lsales,ssales,bsales,sales,comm;
7. lprice=45.0;
8. sprice=30.0;
9. bprice=25.0;
10.tlocks=0;
11.tstocks=0;
12.tbarrels=0;
13.printf("\nEnter the number of locks and to exit the loop enter -1 for locks:");
scanf("%d",&locks);
14.while(locks!=-1) {
15.printf("\nEnter the number of Stocks and Barrels:");
scanf("%d %d",&stocks,&barrels);
16.tlocks=tlocks+locks;
17.tstocks=tstocks+stocks;
18.tbarrels=tbarrels+barrels;
19.printf("\nEnter the number of locks and to exit the loop enter -1 for locks:");
scanf("%d",&locks);
20.}
21.printf("\nTotal locks : %d",tlocks);
22.printf("\nTotal Stocks : %d",tstocks);
23.printf("\nTotal Barrels : %d",tbarrels);
24.lsales=lprice*tlocks;
25.ssales=sprice*tstocks;
26.bsales=bprice*tbarrels;
27.sales=lsales+ssales+bsales;
28.printf("\nThe total Sales : %f",sales);
29.if(sales>1800.0)
30.{
31.comm=0.10*1000.0;
32.comm=comm+0.15*800;
33.comm=comm+0.20*(sales-1800.0);
[1MV16MCA28] Page 19
SOFTWARE TESTING LABORATORY [16MCA48]
}
34.else if(sales>1000)
35.{
36.comm=0.10*1000;
37.comm=comm+0.15*(sales-1000);
}
38.else
39.comm=0.10*sales;
40.printf("\nThe commission is : %f",comm);
41.return 0;
42.}
[1MV16MCA28] Page 20
SOFTWARE TESTING LABORATORY [16MCA48]
OUTPUT:
[1MV16MCA28] Page 21
SOFTWARE TESTING LABORATORY [16MCA48]
[1MV16MCA28] Page 22
Test Description Variable Du-paths Definition Comments
ID path Clear?
[1MV16MCA28]
1 Check for lock price (7,24) <7-8-9-10-11-12-13-14-15-16-17- YES Satisfied
variable DEF(lprice,7) 18-19-20-21-22-23-24>
and USE(lprice,24)
2 Check for stock price (8,25) <8-9-10-11-12-13-14-15-16-17-18- YES Satisfied
variable DEF(sprice,8) 19-20-21-22-23-24-25>
and USE(sprice,25)
3 Check for barrel price (9,26) <9-10-11-12-13-14-15-16-17-18- YES Satisfied
SOFTWARE TESTING LABORATORY
Page 23
SE(tlocks,21),USE(tloc (16,24) <16-17-18-19-20-14-21-22-23-24> NO Satisfied
ks,24)
(11,17) <11,12,13,14,15,16,17> YES Satisfied
[1MV16MCA28]
19-20-21-14-21>
24-25>
(13,14) <13,14> YES Begin the
loop
(13,16) <13-14-15-16> YES Satisfied
Check for locks variable
(DEF(locks,13), DEF(locks,19) (19,14) <19-20-14> YES Satisfied
6
and USE(locks,14),USE(locks,16) (19,16) <19-20-14-15-16> YES Repeat
the loop
Check for stocks variable (15,17) <15-16-17> YES Satisfied
(DEF(stocks,15) and
7
SE(stocks,17)
[16MCA48]
Page 24
8 Check for sales DEF(sales,27) (27,28) <27-28> YES Satisfied
[1MV16MCA28]
and USE(sales,28),
USE(sales,29), USE(sales,33), (27,29) <27-28-29> YES Satisfied
USE(sales,34), USE(sales,37),
USE(sales,39) (27,33) <27-28-29-30-31-32- YES Satisfied
33>
(27,34) <27-28-29-34> YES Satisfied
37>
(27,39) <27-28-29-34-38-39> YES Satisfied
Page 25
SOFTWARE TESTING LABORATORY [16MCA48]
5. Design, develop, code and run the program in any suitable language to
solve the commission problem. Analyze it from the perspective of
boundary value testing, derive different test cases, execute these test
cases and discuss the test results.
#include<stdio.h>
int main()
{
intlocks,stocks,barrels,tlocks,tstocks,tbarrels;
floatlprice,sprice,bprice,lsales,ssales,bsales,sales,comm;
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:");
scanf("%d",&locks);
while(locks!=-1)
{
printf("\nEnter the number of Stocks and Barrels:");
scanf("%d %d",&stocks,&barrels);
tlocks=tlocks+locks;
tstocks=tstocks+stocks;
tbarrels=tbarrels+barrels;
printf("\nEnter the number of locks and to exit the loop enter -1 for
locks:");
scanf("%d",&locks);
}
printf("\nTotal locks : %d",tlocks);
printf("\nTotal Stocks : %d",tstocks);
printf("\nTotal Barrels : %d",tbarrels);
lsales=lprice*tlocks;
ssales=sprice*tstocks;
bsales=bprice*tbarrels;
sales=lsales+ssales+bsales;
printf("\nThe total Sales : %f",sales);
if(sales>1800.0)
[1MV16MCA28] Page 26
SOFTWARE TESTING LABORATORY [16MCA48]
{
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("\nThe commission is : %f",comm);
return 0;
}
[1MV16MCA28] Page 27
SOFTWARE TESTING LABORATORY [16MCA48]
OUTPUT:
[1MV16MCA28] Page 28
Input data Expected Actual Status Comment
Output Output
Case Description
ID Total Total Total Sales Com Sales Com
Cases
locks stock Barrels m. m.
1 Enter the min value 1 1s 1 100 10 100 10 PASS Output
[1MV16MCA28]
for locks, stocks and minimum
barrels
2 1 1 2 125 12.5 125 12.5 PASS
6 between
Enter the100 to 1000
values to 10 10 9 975 97.5 975 97.5 PASS
calculate the
7 10 9 10 970 97 970 97 PASS Border
commission for sales
point
8 nearly less than 1000 9 10 10 955 95.5 955 95.5 PASS
-
9 Enter the values 10 10 10 1000 100 1000 100 PASS Border
sales exactly equal to point
1000
10 Enter the values to 10 10 11 1025 103. 1025 103. PASS Border
calculate the 75 75 point
Commission Problem Output for Boundary Value analysis
Page 29
12 1000 11 10 10 1045 106. 1045 106. PASS
75 75
13 Enter the value sales approx. mid value 14 14 14 1400 160 1400 160 PASS Midpoint
between 1000 and 1800
14 18 18 17 1775 216 1775 216 PASS
.25 .25
15 Enter the values to calculate the
[1MV16MCA28]
18 17 18 1770 215 1770 215 PASS
commission for sales nearly less than
16 .5 .5 Border
1800
17 18 18 1755 213 1755 213 PASS point
.25 .25 -
17 Enter the values sales exactly equal to 18 18 18 1800 220 1800 220 PASS Border
1000 point
18 18 18 19 1825 225 1825 225 PASS
19 Enter the values to calculate the 18 19 18 1830 226 1830 226 PASS Border
SOFTWARE TESTING LABORATORY
Page 30
25 Enter the max value for locks, stocks 70 80 90 7800 142 7800 142 PASS Output
and barrels 0 0 maximum
Case Input Data Expected Actual Status Comment
ID Output Output
Description
Total Total Total Sales Com Sales Com
locks stocks barrels m. m.
[1MV16MCA28]
Enter the random 11 10 8 995 99.5 995 99.5 PASS Border
values such that to point
calculate commission
-
1 for sales nearly less
than 1000
Enter the random 10 11 9 1005 100. 1005 100. PASS Border
values such that to 75 75 point
calculate commission
+
SOFTWARE TESTING LABORATORY
Page 31
SOFTWARE TESTING LABORATORY [16MCA48]
6. Design, develop, code and run the program in any suitable language to
solve the commission problem. Analyze it from the perspective of
equivalence class testing, derive different test cases, execute these test
cases and discuss the test results.
#include<stdio.h>
int main()
{
int locks, stocks, barrels, tlocks, tstocks, tbarrels;
floatlprice, 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
{
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 ");
[1MV16MCA28] Page 32
SOFTWARE TESTING LABORATORY [16MCA48]
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");
scanf("%d",&locks);
}
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)
{
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)
{
[1MV16MCA28] Page 33
SOFTWARE TESTING LABORATORY [16MCA48]
comm =0.10*1000;
comm=comm+0.15*(sales-1000);
}
else
comm=0.10*sales;
[1MV16MCA28] Page 34
SOFTWARE TESTING LABORATORY [16MCA48]
OUTPUT:
[1MV16MCA28] Page 35
[1MV16MCA28]
Case Description Input Data Expected Actual Status Comment
ID Output Output
Total Total Total Sales Com Sales Com
locks stocks barrels m. m.
Enter the value 35 40 45 3900 640 3900 640 PASS Satisfied
SOFTWARE TESTING LABORATORY
within the
range for locks,
1 stocks and
barrels
Weak & Strong Normal Equivalence Class
Commission Problem Output Equivalence Class Testing
[16MCA48]
Page 36
Case Description Input Data Expected Output Actual Output Status Comment
ID
loc stoc barr
ks ks els
[1MV16MCA28]
WR1 Enter the value -1 40 45 Terminates the Terminates the PASS Satisfied
locks= -1 input loop and program
proceed to
calculate sales and
commission (if
sales>0)
WR2 Enter the value 0 40 45 Value of Locks not Value of locks is PASS Satisfied
less than -1 or in the range 1…70 not in the range
SOFTWARE TESTING LABORATORY
Page 37
WR5 Enter the value 35 81 45 Value of Socks not Value of stocks PASS Satisfied
greater than 80 in the range 1…80 is not in the range
for stocks and of 1…80
other valid inputs
[1MV16MCA28]
WR6 Enter the value 35 40 0 Value of barrels Value of barrels PASS Satisfied
less than or equal not in the range not in the range
to zero for barrels 1…90 1…90
and other valid
inputs
WR7 Enter the value 35 40 91 Value of barrels Value of barrels PASS Satisfied
greater than 90 not in the range not in the range
SOFTWARE TESTING LABORATORY
Page 38
Case Description Input Data Expected Output Actual Output Status Comment
ID
loc stoc barr
ks ks els
[1MV16MCA28]
SR1 Enter the value -2 40 45 Value of Locks not Value of Locks PASS Satisfied
less than -1 for in the range 1…70 not in the range
locks and other 1…70
valid inputs
SR2 Enter the value 35 -1 45 Value of Socks not Value of Socks PASS Satisfied
less than or equal in the range 1…80 not in the range
to zero for stocks 1…80
SOFTWARE TESTING LABORATORY
inputs
SR4 Enter the value -2 -1 45 Value of Locks not Value of Locks PASS Satisfied
less than or equal in the range 1…70 not in the range
to zero for locks 1…70
and stocks and Value of Stocks Value of Stocks
other valid input not in the range not in the range
[16MCA48]
Page 39
1…80 1…80
SR5 Enter the value -2 40 -1 Value of Locks not Value of Locks not PASS Satisfied
less than or equal in the range 1…70 in the range 1…70
to zero for locks
and barrels and Value of barrels Value of barrels
[1MV16MCA28]
other valid input not in the range not in the range
1…90 1…90
SR6 Enter the value 35 40 0 Value of barrels Value of barrels PASS Satisfied
less than or equal not in the range not in the range
to zero for barrels 1…90 1…90
and stocks and
other valid inputs Value of Stocks Value of Stocks
not in the range not in the range
SOFTWARE TESTING LABORATORY
1…80 1…80
SR7 Enter the value -2 -2 -2 Value of Locks not Value of Locks not PASS Satisfied
less than or equal in the range 1…70 in the range 1…70
to zero for locks ,
stocks and barrels
Value of Stocks Value of Stocks
not in the range not in the range
1…80 1…80
Page 40
Case Input Data Expected Actual Status Comment
ID Output Output
Description
[1MV16MCA28]
locks stocks barrels m. m.
Enter the value for 15 15 15 1500 175 1500 175 PASS Satisfied
locks, stocks and
barrels where
OR2 1000<sales<1800
Enter the value for 25 25 25 2500 360 2500 360 PASS Satisfied
locks, stocks and
OR3 sales<1800
[16MCA48]
Page 41