0% found this document useful (0 votes)
11 views

Software Quality and Testing LAB MANUAL

Uploaded by

Sachin Ranjan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Software Quality and Testing LAB MANUAL

Uploaded by

Sachin Ranjan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 48

INDEX

S.NO DATE TOPIC SIGNATURE

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
1 19/02/2024
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.
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,
2 8/04/2024 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.
Design and develop a program in a language of your choice
to solve the triangle problem defined as follows: Accept
3 10/04/2024 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.
Design, develop, code and run the program in any suitable
4 15/04/2024 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.
Design, develop, code and run the program in any suitable
language to solve the commission problem. Analyze it from
5 22/04/2024 the perspective of boundary value testing, derive different
test cases, execute these test cases and discuss the test
results.
Design, develop, code and run the program in any suitable
6 24/04/2024 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.
Design, develop, code and run the program in any suitable
7 29/04/2024 language to implement the quick sort algorithm. Determine
the basis paths and using them derive different test cases,
execute these test cases and discuss the test results.

Experiment 1: Triangle Problem Testing Technique: Decision Table Approach


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.

#include<stdio.h>
#include<conio.h>
int main()
{
int a,b,c;
printf("enter the sides of triangle\n");
scanf("%d%d%d",&a,&b,&c);
if((a+b)>c && (b+c)>a && (c+a)>b)
{
if(a==b && b==c)
printf("triangle is equilateral\n");
else if (a!=b && b!=c && c!=a)
printf("triangle is scalene\n");
else
printf("triangle is isosceles\n");
}

else
printf("triangle cannot be formed\n");

return 0;
}

Decision Table for Triangle Problem


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<c+a -- F T T T T T T T T T
C3: c<a+b -- -- F T T T T T T T T
Conditions
C4: a=b -- -- -- T T F F F T T F
C5: b=c -- -- -- T F T F F T F T
C6: c=a -- -- -- T F F T F F T T
A1: Not a triangle x x x
Actions
A2: Equilateral x
A3: Isosceles x x x
A4: Scalene x

A5: Impossible x x x
Test Cases using Decision Table for Triangle Program

Inputs
Test Description
Output Comments
cases A B C
Enter the values of a, b and c such that value of a is greater
Case 1 7 2 3 Not a triangle Valid
than sum of b and c.
Enter the values of a, b and c such that value of b is greater
Case 2 2 8 3 Not a triangle Valid
than sum of a and c.
Enter the values of a, b and c such that value of c is greater
Case 3 2 4 7 Not a triangle Valid
than sum of a and b.
Enter the values of a, b and c such that values of a,b and c
Case 4 5 5 5 Equilateral Valid
are equal.
Enter the values of a, b and c Such that value of a is equal to
Case 5 4 4 3 Isosceles Valid
value of b.
Enter the values of a, b and c such that value of b is equal to
Case 6 2 5 5 Isosceles Valid
value of c.
Enter the values of a, b and c such that value of a is equal to
Case 7 6 2 6 Isosceles Valid
value of c.
Enter the values of a, b and c such that values of a,b and c are
Case 8 2 3 4 Scalene Valid
different.
Enter the values of a, b and c such that value of a is equal to
Case 9 ? ? ? Impossible Valid
value of b and c but value of b is not equal to c.
Enter the values of a, b and c such that value of b is equal to
Case 10 value of c and value of c is equal to a but value of a not equal to
? ? ? Impossible Valid
b.
Enter the values of a, b and c such that value of a is equal
Case 11 to b and value of b is equal to value of c but value of a not
? ? ? Impossible Valid
equal to c.

Experiment 2: Triangle Problem Testing Technique: Boundary Value Analysis


Design and develop a program in a language of your choice to solve the triangle problem defined as follows: Accept
three integers which are supposed to be the three sides of a triangle and determine if the three values represent an
equilateral triangle, isosceles triangle, scalene triangle, or they do not form a triangle at all. Assume that the upper
limit for the size of any side is 10. Derive test cases for your program based on boundary-value analysis, execute the
test cases and discuss the results.

#include<stdio.h>
#include<conio.h
> int main( )
{
int
a,b,c,c1,c2,c3;

do
{
printf("enter the sides of triangle\n");
scanf("%d%d%d",&a,&b,&c);
c1=((a>=1) && (a<=10));
c2=((b>=1) && (b<=10));
c3=((c>=1) && (c<=10));
if(!c1)
printf("value of a is out of range");
if(!c2)
printf("value of b is out of range");

if(!c3)
printf("value of c is out of range");
}while(!c1 || !c2 || !c3);
if((a+b)>c && (b+c)>a &&
(c+a)>b)
{
if(a==b && b==c)
printf("Triangle is equilateral\n");
else if(a!=b && b!=c && c!=a)
printf("Triangle is scalene\
n"); else
printf("Triangle is isosceles\n");
}
else
printf("Triangle cannot be formed\n");
getch( );
return 0;
}
Boundary Value Analysis

Boundary value analysis focuses on the boundary of the input and output space to identify test
cases because errors tend to occur near the extreme values of an input variable. The basic idea is to use
input variables at their minimum, just above minimum, nominal, just below their maximum and
maximum.

Considering Triangle program, we have three variables a, b and c. Each variables value ranges from 1 to
10.

Variables Min Min+ Nom Max- Max


a 1 2 5 9 10
b 1 2 5 9 10
c 1 2 5 9 10

Boundary Value Analysis = 4n+1 test cases, where n is number of variables

In Triangle program for BVA, we start by taking nominal values for a and b variables then cross product
it with values min, min-, nom, max- and max values of variable c. similarly keeping nominal values for
variables a and c, we cross product it with min, min-, nom, max-, max values of variable b. Again
keeping variable b and c as nominal combine with 5 values of a. By this we get 15 te st cases in
which a test case with all nominal values for a, b and c is repeated thrice, so we discard 2 duplicate
such cases and finally we get 15-2=13 test cases which is equal to BVA i.e., 4(3)+1=13.

Test cases using Boundary value analysis for Triangle Program

Inputs
Test
Description Output Comments
cases A B C

BVA1 Enter the values of a(nom),b(nom) and c(min) 5 5 1 Isosceles Valid


BVA 2 Enter the values of a(nom),b(nom) and c(min+) 5 5 2 Isosceles Valid

BVA 3 Enter the values of a(nom),b(nom) and c(nom) 5 5 5 Equilateral Valid


BVA 4 Enter the values of a(nom),b(nom) and c(max-) 5 5 9 Isosceles Valid

BVA 5 Enter the values of a(nom),b(nom) and c(max) 5 5 10 Triangle cannot be formed Valid
BVA 6 Enter the values of a(nom),b(min) and c(nom) 5 1 5 Isosceles Valid

BVA 7 Enter the values of a(nom),b(min+) and c(nom) 5 2 5 Isosceles Valid


BVA 8 Enter the values of a(nom),b(max-) and c(nom) 5 9 5 Isosceles Valid

BVA 9 Enter the values of a(nom),b(max) and c(nom) 5 10 5 Triangle cannot be formed Valid
BVA 10 Enter the values of a(min),b(nom) and c(nom) 1 5 5 Isosceles Valid

BVA 11 Enter the values of a(min+),b(nom) and c(nom) 2 5 5 Isosceles Valid

BVA 12 Enter the values of a(max-),b(nom) and c(nom) 9 5 5 Isosceles Valid

BVA 13 Enter the values of a(max),b(nom) and c(nom) 10 5 5 Triangle cannot be formed Valid
Experiment 3: Triangle Problem Testing Technique: Equivalence Class Testing

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 the upper limit
for the size of any side is 10. Derive test cases for your program based on equivalence class partitioning, execute the
test cases and discuss the results.

#include<stdio.h>
#include<conio.h>
int main()
{
int a,b,c,c1,c2,c3; do
{
printf("enter the sides of triangle\n");
scanf("%d%d%d",&a,&b,&c);
c1=((a>=1) && (a<=10));
c2=((b>=1) && (b<=10));
c3=((c>=1) && (c<=10));
if(!c1)
printf("value of a is out of range"); if(!
c2)
printf("value of b is out of range");
if(!c3)
printf("value of c is out of range");
}while(!c1 || !c2 || !c3);
if((a+b)>c && (b+c)>a && (c+a)>b)
{
if(a==b && b==c)
printf("triangle is equilateral\n");
else if(a!=b && b!=c && c!=a)
printf("triangle is scalene\n");
else
printf("triangle is isosceles\n");
}
else
printf("triangle cannot be formed \n");
getch( );
return 0;
}
Equivalence Class Test For The Triangle Program Output

Equivalence Classes are as follows:


R1={<a,b,c>:the triangle with sides a,b and c is Equilateral}

R2={<a,b,c>:the triangle with sides a,b and c is Isosceles}

R3={<a,b,c>:the triangle with sides a,b and c is Scalene}

R4={<a,b,c>:sides a,b and c do not form a Triangle}

Weak Normal /Strong Normal

Inputs Expected
Test cases Description Comments
A B C output
Enter the valid values for a, b and c from output
WN/SN1 equivalence classes.
5 5 5 Equilateral Valid

Enter the valid values for a, b and c from output


WN/SN2 equivalence classes.
5 5 3 Isosceles Valid

Enter the valid values for a, b and c from output


WN/SN3 equivalence classes.
5 3 4 Scalene Valid

Enter the valid values for a, b and c from output Triangle cannot be
WN/SN4 equivalence classes.
10 1 1 formed
Valid

Weak Robust
Test Inputs Expected
Description Comments
cases A B C output
Enter the valid values for b and c from output Value of a is not Triangle cannot be
WR 1 equivalence classes and invalid value for a. -1 5 5 in a range formed
Enter the valid values for a and c from output Value of b is not Triangle cannot be
WR 2 equivalence classes and invalid value for b. 3 -1 4 in a range formed
Enter the valid values for a and b from output Value of c is not Triangle cannot be
WR 3 10 10 -1
equivalence classes and invalid value for c. in a range formed
Enter the valid values for b and c from output Value of a is not Triangle cannot be
WR 4 equivalence classes and invalid value for a. 11 3 3 in a range formed
Enter the valid values for a and c from output Value of b is not Triangle cannot be
WR 5 equivalence classes and invalid value for b. 5 11 6 in a range formed
Enter the valid values for a and b from output Value of c is not Triangle cannot be
WR 6 9 10 11
equivalence classes and invalid value for c. in a range formed

Strong Robust
Test Inputs Expected
Description Comments
cases A B C output
Enter the valid value for b from output equivalence Values of a and c Triangle cannot be
SR 1 classes and invalid values for a and c.
-1 3 -1 are not in range formed
Enter the valid value for a from output equivalence Values of b and c Triangle cannot be
SR 2 classes and invalid values for b and c.
5 -1 -1 are not in range formed
Enter the valid value for c from output equivalence Values of a and b Triangle cannot be
SR 3 classes and invalid values for a and b.
-1 -1 10 are not in range formed
Enter the valid value for a from output equivalence Values of b and c Triangle cannot be
SR 4 classes and invalid values for b and c.
7 11 11 are not in range formed
Enter the valid value for c from output equivalence Values of a and b Triangle cannot be
SR 5 classes and invalid values for a and b.
11 11 10 are not in range formed
Enter the valid value for b from output equivalence Values of a and c Triangle cannot be
SR 6 classes and invalid values for a and c.
11 5 11 are not in range formed

Enter the valid values for b and c from output Values of a is not Triangle cannot be
SR 7 equivalence classes and invalid value for a.
-1 5 5 in range formed
Enter the valid values for a and c from output Values of b is not Triangle cannot be
SR 8 equivalence classes and invalid value for b.
10 -1 10 in range formed
Enter the valid values for a and b from output Values of c is not Triangle cannot be
SR 9 equivalence classes and invalid value for c.
7 6 -1 in range formed
Enter the valid values for b and c from output Values of a is not Triangle cannot be
SR 10 equivalence classes and invalid value for a.
11 5 4 in range formed
Enter the valid values for a and c from output Values of b is not Triangle cannot be
SR 11 equivalence classes and invalid value for b.
2 11 3 in range formed
Enter the valid values for a and b from output Values of c is not Triangle cannot be
SR 12 equivalence classes and invalid value for c.
3 4 11 in range formed
Values of a, b and
Triangle cannot be
SR 13 Enter the invalid value for a, b and c. 11 11 11 c are not in a
formed
range
Values of a, b and
Triangle cannot be
SR 14 Enter the invalid value for a, b and c. -1 -1 -1 c are not in a
formed
range

Experiment 4: Commission Problem Testing Technique: Dataflow Testing


Design, develop, code and run the program in any suitable language to solve the commission problem. Analyse it
from the perspective of dataflow testing, derive different test cases, execute these test cases and discuss the test
results.
#include<stdio.h>
#include<conio.h>
int main()
{
int c1,c2,c3,temp;
int locks,stocks,barrels,totallocks,totalstocks,totalbarrels;
float lockprice,stockprice,barrelprice,locksales,stocksales,barrelsales,sales,com;
lockprice=45.0;
stockprice=30.0;
barrelprice=25.0;
totallocks=0;
totalstocks=0;
totalbarrels=0;
clrscr();
printf("Enter the number of locks and to exit press -1\n");
scanf("%d",&locks);
while(locks != -1)
{
c1=(locks<=0 || locks>70);
printf("\nEnter the number of stocks and barrels\n");
scanf("%d %d",&stocks,&barrels);
c2=(stocks<=0 || stocks>80);
c3=(barrels<=0 || barrels>90);
if(c1)
printf("\nValue of locks are not in the range of 1..............70\n");
else
{
temp=totallocks+locks;
if(temp>70)
printf("New totallocks = %d not in the range of 1........70\n",temp);
else
totallocks=temp;
}
printf("Total locks = %d",totallocks);
if(c2)
printf("\n Value of stocks not in the range of 1.........80\n");
else
{
temp=totalstocks+stocks;
if(temp>80)
printf("\nNew total stocks = %d not in the range of 1..........80",temp);
else
totalstocks=temp;
}
printf("\nTotal stocks = %d",totalstocks);
if(c3)
printf("\n Value of barrels not in the range of 1.........90\n");
else
{
temp=totalbarrels+barrels;
if(temp>90)
printf("\nNew total barrels = %d not in the range of 1..........90\n",temp);
else
totalbarrels=temp;
}
printf("\nTotal barrels=%d", totalbarrels);
printf("\nEnter the number of locks and to exit press -1\n");
scanf("%d",&locks);
}
printf("\n Total locks = %d",totallocks);
printf("\n Total stocks = %d",totalstocks);
printf("\n Total barrels = %d",totalbarrels);
locksales=totallocks*lockprice;
stocksales=totalstocks*stockprice;
barrelsales=totalbarrels*barrelprice;
sales=locksales+stocksales+barrelsales;
printf("\n Total sales = %f",sales);
if(sales>1800)
{
com=0.10*1000;
com=com+(0.15*800);
com=com+0.20*(sales-1800);
}
else if(sales>1000)
{
com=0.10*1000;
com=com+0.15*(sales-1000);
}
else
com=0.10*sales;
printf("\nCommission = %f",com);
getch();
return 0;
}
Define/ Use Nodes for variables in the commission problem

Variable Defined at node Used at node

lockprice 8 63

stockprice 9 64

barrelprice 10 65

totallocks 11,32 28,34,60,63

totalstocks 12,43 39,45,61,64

totalbarrels 13,54 50,56,62,65

Locks 16,58 17,19,28

stocks 21 22,39

barrels 21 23,50

locksales 63 66

stocksales 64 66

barrelsales 65 66

Sales 66 67,68,72,74,77,80

Com 70,71,72,76,77,80 71,72,77,81


Define /Use paths with definition clear status

Variables
Test (beginning DC
Description DU paths
id ,end path ?
nodes)
Check for lockprice variable 8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,26,27,28,29,
1 DEF(ocklprice,8) 31,32,33,34,35,37,38,39,40,42,43,44,45,46,48,49
And USE(lockprice,63) <8,63> YES
,50,51,53,54,55,56,57,58,59,60,61,62,63

Check for stockprice 9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,26,


2 variable DEF(stockprice,9) 27,28,29,31,32,33,34,35,37,38,39,40,42,43,44,45,
And USE(stockprice,64) <9,64> YES
46,48,49,50,51,53,54,55,56,57,58,59,60,61,62,63,64

Check for barrelprice variable 10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,26,27,28,


3 DEF(barrelprice,10) 29,31,32,33,34,35,37,38,39,40,42,43,44,45,46,
And USE(barrelprice,65) <10,65> YES
48,49,50,51,53,54,55,56,57,58,59,60,61,62,63,64,65
11,12,13,14,15,16,17,18,19,20,21,22,23,24,26,27,28
<11,28> YES

11,12,13,14,15,16,17,18,19,20,21,22,23,24,26,27,28,29,31,32,33,34
<11,34> NO
Check for totallocks
variable 11,12,13,14,15,16,17,18,19,20,21,22,23,24,26,27,28,29,31,32,33,34,35,37
4 DEF(totallocks,11,32) <11,60> ,38,39 ,40,42,43 ,44,45,46,48,49,50,51,53,54,55,56,57,58,59,60 NO
And USE(totallocks,
28,34,60,63)
11,12,13,14,15,16,17,18,19,20,21,22,23,24,26,27,28,29,31,32,33,34,35,37
,38,39 ,40,42,43 ,44,45,46,48,49,50,51,53,54,55,56,57,58,59,60,61,62,63
<11,63> NO

32,33,34,35,37,38,39,40,42,43,44,45,46,48,49,50,51,53,54,55,56,57,58,17
<32,28> ,18,19,20,21,22,23,24,26,27,28 YES
<32,34> 32,33,34

YES
<32,60> 32,33,34,35,37,38,39,40,42,43,44,45,46,48,49,50,51,53,54,
55,56,57,58,59, 60
YES

<32,63> 32,33,34,35,37,38,39,40,42,43,44,45,46,48,49,50,51,
53,54,55,56,57,58,59 ,60,61,62,63 YES

12,13,14,15,16,17,18,19,20,21,22,23,24,26,27,28,29,31
<12,39>
,32,33,34,35,37,38,39

YES
<12,45>
12,13,14,15,16,17,18,19,20,21,22,23,24,26,27,28,29
,31,32,33,34,35,37,38,39,40,42,43,44,45 NO

<12,61>
Check for totalstocks 12,13,14,15,16,17,18,19,20,21,22,23,24,26,27,28,29
variable ,31,32,33,34,35,37,38,39,40,42,43,44,45,46,48,49
5 DEF(totalstocks,12,43)
,50,51,53,54,55,56,57,58,59,60,61 NO
And USE(totalstocks,
39,45,61,64)
12,13,14,15,16,17,18,19,20,21,22,23,24,26,27,28,29
<12,64>
,31,32,33,34,35,37,38,39,40,42,43,44,45,46,48,49
,50,51,53,54,55,56,57,58,59,60,61,62,63,64 NO

<43,45>
43,44,45
YES
<43,61> 43,44,45,46,48,49,50,51,53,54,55,56,57,58,59,60,61 YES

<43,64> 43,44,45,46,48,49,50,51,53,54,55,56,57,58,59,60,61,62,63,64 YES

<13,50> 13,14,15,16,17,18,19,20,21,22,23,24,26,27,28,29
YES
,31,32,33,34,35,37,38,39,40,42,43,44,45,46,48,49,50

<13,56> 13,14,15,16,17,18,19,20,21,22,23,24,26,27,28,29
NO
,31,32,33,34,35,37,38,39,40,42,43,44,45,46,48,49
,50,51,53,54,55,56

<13,62> 13,14,15,16,17,18,19,20,21,22,23,24,26,27,28,29,
NO
Check for totalbarrels 31,32,33,34,35,37,38,39,40,42,43,44,45,46,48,49,
variable
DEF(totalbarrels,13,54) 50,51,53,54,55,56,57,58,59,60,61,62
6
And USE(totalbarrels,
50,56,62,65) <13,65> 13,14,15,16,17,18,19,20,21,22,23,24,26,27,28,29,
31,32,33,34,35,37,38,39,40,42,43,44,45,46,48,49, NO
50,51,53,54,55,56,57,58,59,60,61,62,63,64,65

<54,56> 54,55,56 YES

<54,62> 54,55,56,57,58,59,60,61,62 YES

<54,65> 54,55,56,57,58,59,60,61,62,63,74,65 YES


<16,17> 16,17 YES
<16,19> 16,17,18,19 YES
Check for locks variable
<16,28> 16,17,18,19,20,21,22,23,24,26,27,28 YES
7 DEF(locks,16,58)
<58,17> 58,17 YES
And USE(locks,17,19,28)
<58,19> 58,17,18,19 YES
<58,28> 58,17,18,19,20,21,22,23,24,26,27,28 YES
Check for stocks variable
<21,22> 21,22 YES
8 DEF(stocks,21)
<21,39> 21,22,23,24,26,27,28,29,31,32,33,34,35,37,38,39 YES
And USE(stocks,22,39)
Check for barrels variable 21,22,23
<21,23>
9 DEF(barrels,21)
21,22,23,24,25,26,27,28,29,31,32,33,34,35,37,38,39,40,42,43,44,45,
<21,50> YES
And USE(barrels,23,50) 46,47,48,49,50
Check for lockpsales variable
10 DEF(locksales,63) <63,66> 63,64,65,66
And USE(locksales,66) YES

Check for stocksales variable


11 DEF(stocksales,64) <64,66> 64,65,66
And USE(stocksales,66) YES

Check for barrelsales


variable
12 DEF(barrelsales,65) <65,66> 65,66
YES
And USE(barrelsales,66)
<66,67> 66,67 YES
Check for sales variable
DEF(sales,66) <66,68> 66,67,68 YES
13 And <66,72> 66,67,68,69,70,71,72 YES
USE(sales,67,68,72,74,77,8 0) <66,74> 66,67,68,74 YES
<66,77> 66,67,68,74,75,76,77 YES
<66,80> 66,67,68,74,79,80 YES
<70,71> 70,71 NO
<70,72> 70,71,72 NO
<70,81> 70,71,72,73,81 NO
Check for commission <71,72> 71,72 NO
variable
<71,81> 71,72,73,81 NO
14 DEF(com,70,71,72,76,77,8
0) <72,81> 72,73,81 YES
And USE (com,71,72,77,81) <76,77> 76,77 NO
<76,81> 76,77,78,81 NO
<77,81> 77,78,81 YES
<80,81> 80,81 YES

Note

In above Du-Paths, some paths like

<70,77>,<71,71>,<71,77>,<72,71>,<72,72>,<72,77>,<76,71>,<76,72>,<77,71>,<77,71>,<77,77>,
<80,70>,<80,72>,<80,77>,<80,77> are not possible to be formed. So they are not considered in above table
Experiment 5: Commission Problem Testing Technique: Boundary Value Analysis

Design, develop, code and run the program in any suitable language to solve the commission problem. Analyse it
from the perspective of boundary value testing, derive different test cases, execute these test cases and discuss the
test results.

#include<stdio.h>
#include<conio.h>
int main()
{
int c1,c2,c3,temp;
int locks,stocks,barrels,totallocks,totalstocks,totalbarrels;
float
lockprice,stockprice,barrelprice,locksales,stocksales,barrelsales,sales,com;
lockprice=45.0;
stockprice=30.0;
barrelprice=25.0;
totallocks=0;
totalstocks=0;
totalbarrels=0;
clrscr();
printf("Enter the number of locks and to exit press 1\n");
scanf("%d",&locks);
while(locks != -1)
{

c1=(locks<=0 || locks>70);
printf("\nEnter the number of stocks and barrels\n");
scanf("%d %d",&stocks,&barrels);
c2=(stocks<=0 || stocks>80);
c3=(barrels<=0 || barrels>90);

if(c1)
printf("\nValue of locks are not in the range of 1.70\n");
else
{
temp=totallocks+locks;
if(temp>70)
printf("New totallocks = %d not in the range of 1.70\n",temp);
else
totallocks=temp;
}
printf("Total locks = %d",totallocks);
if(c2)
printf("\n Value of stocks not in the range of 1.80\n");
else
{
temp=totalstocks+stocks;

if(temp>80)
printf("\nNew total stocks = %d not in the range of 1.80",temp);
else
totalstocks=temp;
}
printf("\nTotal stocks = %d",totalstocks);
if(c3)
printf("\n Value of barrels not in the range of 1.90\n");
else
{
temp=totalbarrels+barrels;
if(temp>90)
printf("\nNew total barrels = %d not in the range of 1.90\n",temp);
else
totalbarrels=temp;
}
printf("\nTotal barrels=%d", totalbarrels);
printf("\nEnter the number of locks and to exit press -1\n");
scanf("%d",&locks);
}
printf("\n Total locks = %d",totallocks);
printf("\n Total stocks = %d",totalstocks);
printf("\n Total barrels = %d",totalbarrels);

locksales=totallocks*lockprice;
stocksales=totalstocks*stockprice;
barrelsales=totalbarrels*barrelprice;
sales=locksales+stocksales+barrelsales;
printf("\n Total sales = %f",sales);
if(sales>1800)
{
com=0.10*1000;
com=com+(0.15*800);
com=com+0.20*(sales-
1800);
}
else if(sales>1000)
{
com=0.10*1000;
com=com+0.15*(sales-1000);
}
else
com=0.10*sales; printf("\
nCommission = %f",com); getch();
return 0;
}
Considering Commission program, we have three input variables lock, stock and barrels.

Range of value for locks= 1-70, stocks= 1-80 and barrels= 1-90

Variables Min Min+ Nom Max- Max


locks 1 2 35 69 70
stocks 1 2 40 79 80
barrels 1 2 45 89 90

Considering output variable sales we have 3 slots for calculating commission. i.e., if sales are below
1000, com is 10%, if sales are 1001 to 1800 then com is 15% and if sales are greater than 1801, com is
20%.

Sales Min Min+ Nom Max- Max


locks, stocks, barrrels locks, stocks, barrrels locks, stocks, barrrels locks, stocks, barrrels locks, stocks, barrrels

2,1,1 9,10,10
1-1000 1,1,1 1,2,1 5,5,5 10,9,10 10,10,10
1,1,2 10,10,9
11,10,10 12,10,10 17,18,18
1001-1800 10,11,10 10,12,10 14,14,14 18,17,18 18,18,18
10,10,11 10,10,12 18,18,17
19,18,18 20,18,18 69,80,90
1801- above 18,19,18 18,20,18 48,48,48 70,79,90 70,80,90
18,18,19 18,18,20 70,80,89
Test cases for commission program using INPUT Boundary value analysis
Test Inputs Output Comm
cases
Description ents
Locks Stocks Barrels Sales Com
BVA1 Enter the values for locks(nom), stocks(nom) and barrels(min) 35 40 1 2800 420 Valid

BVA2 Enter the values for locks(nom), stocks(nom) and barrels(min+) 35 40 2 2825 425 Valid

BVA3 Enter the values for locks(nom), stocks(nom) and barrels(nom) Valid
35 40 45 3900 640

BVA4 Valid
Enter the values for locks(nom), stocks(nom) and barrels(max-) 35 40 89 5000 860

BVA5 Valid
Enter the values for locks(nom), stocks(nom) and barrels(max) 35 40 90 5025 865

BVA6 Valid
Enter the values for locks(nom), stocks(min) and barrels(nom) 35 1 45 2730 406

BVA7 Enter the values for locks(nom), stocks(min+) and barrels(nom) Valid
35 2 45 2760 412

BVA8 Valid
Enter the values for locks(nom), stocks(max-) and barrels(nom) 35 79 45 5070 874

BVA9 Valid
Enter the values for locks(nom), stocks(max) and barrels(nom) 35 80 45 5100 880

BVA10 Enter the values for locks(min), stocks(nom) and barrels(nom) Valid
1 40 45 2370 334

BVA11 Enter the values for locks(min+), stocks(nom) and barrels(nom) Valid
2 40 45 2415 343

BVA12 Enter the values for locks(max-), stocks(nom) and barrels(nom) Valid
69 40 45 5430 946

BVA13 Enter the values for locks(max), stocks(nom) and barrels(nom) Valid
70 40 45 5475 955
Test cases for commission program using OUTPUT Boundary value analysis

Test Inputs Output Comm


Description
cases Locks Stocks Barrels Sales Com ents
Enter the values for locks(min), stocks(min) and
BVA1 1 1 1 100 10 Valid
barrels(min) for the range 100 to 1000
Enter the values for locks(min+), stocks(min) and
BVA2 2 1 1 145 14.5 Valid
barrels(min) for the range 100 to 1000
Enter the values for locks(min), stocks(min+) and
BVA3 1 2 1 130 13 Valid
barrels(min) for the range 100 to 1000
Enter the values for locks(min), stocks(min) and
BVA4 1 1 2 125 12.5 Valid
barrels(min+) for the range 100 to 1000
Enter the values for locks(nom), stocks(nom) and
BVA5 5 5 5 500 50 Valid
barrels(nom) for the range 100 to 1000
Enter the values for locks(max-), stocks(max) and
BVA6 9 10 10 955 95.5 Valid
barrels(max) for the range 100 to 1000
Enter the values for locks(max), stocks(max-) and
BVA7 10 9 10 970 97.0 Valid
barrels(max) for the range 100 to 1000
Enter the values for locks(max), stocks(max) and
BVA8 10 10 9 975 97.5 Valid
barrels(max-) for the range 100 to 1000
Enter the values for locks(max), stocks(max) and
BVA9 10 10 10 1000 100 Valid
barrels(max) for the range 100 to 1000
Enter the values for locks(min), stocks(min) and
BVA10 11 10 10 1045 106.75 Valid
barrels(min) for the range 1000 to 1800
Enter the values for locks(min), stocks(min+) and
BVA11 10 11 10 1030 104.5 Valid
barrels(min) for the range 1000 to 1800
Enter the values for locks(min), stocks(min) and
BVA12 10 10 11 1025 103.75 Valid
barrels(min+) for the range 1000 to 1800
Enter the values for locks(min+), stocks(min) and
BVA13 12 10 10 1090 113.5 Valid
barrels(min) for the range 1000 to 1800
Enter the values for locks(min), stocks(min+) and
BVA14 10 12 10 1060 109 Valid
barrels(min) for the range 1000 to 1800
Enter the values for locks(min), stocks(min) and
BVA15 10 10 12 1050 107.5 Valid
barrels(min+) for the range 1000 to 1800
Enter the values for locks(nom), stocks(nom) and
BVA16
barrels(nom) for the range 1000 to 1800 14 14 14 1400 160 Valid
Enter the values for locks(max-), stocks(max) and
BVA17
barrels(max) for the range 1000 to 1800 17 18 18 1755 213.25 Valid
Enter the values for locks(max), stocks(max-) and
BVA18
barrels(max) for the range 1000 to 1800
18 17 18 1770 215.5 Valid
Enter the values for locks(max), stocks(max) and
BVA19
barrels(max-) for the range 1000 to 1800 18 18 17 1775 216.25 Valid
Enter the values for locks(max), stocks(max) and
BVA20
barrels(max) for the range 1000 to 1800 18 18 18 1800 220 Valid
Enter the values for locks(min), stocks(min) and
BVA21
barrels(min) for the range > 1800 19 18 18 1845 229 Valid
Enter the values for locks(min), stocks(min) and
BVA22
barrels(min) for the range > 1800 18 19 18 1830 226 Valid
Enter the values for locks(min), stocks(min) and
BVA23
barrels(min) for the range > 1800
18 18 19 1825 225 Valid
Enter the values for locks(min+), stocks(min) and
BVA24
barrels(min) for the range > 1800 20 18 18 1890 238 Valid
Enter the values for locks(min), stocks(min+) and
BVA25
barrels(min) for the range > 1800 18 20 18 1860 232 Valid
Enter the values for locks(min), stocks(min) and
BVA26
barrels(min+) for the range > 1800 18 18 20 1850 230 Valid
Enter the values for locks(nom), stocks(nom) and
BVA27
barrels(nom) for the range > 1800 48 48 48 4800 820 Valid
Enter the values for locks(max-), stocks(max) and
BVA28
barrels(max) for the range > 1800
69 80 90 7755 1411 Valid
Enter the values for locks(max), stocks(max-) and
BVA29
barrels(max) for the range > 1800 70 79 90 7770 1414 Valid
Enter the values for locks(max), stocks(max) and
BVA30
barrels(max-) for the range > 1800 70 80 89 7775 1415 Valid
Enter the values for locks(max), stocks(max) and
BVA31
barrels(max) for the range > 1800 70 80 90 7800 1420 Valid
Experiment 6: Binary Search Testing Technique: Basis paths
Design, develop, code and run the program in any suitable language to implement the binary search algorithm.
Determine the basis paths and using them derive different test cases, execute these test cases and discuss the test
results.
#include<stdio.h>
int binsrc(int x [ ],int low,int high,int key)
{
int mid;
while(low<=high)
{
mid=(low+high)/2;
if(x[mid]==key)
return mid;
elseif(x[mid]<key)
low=mid+1;
else
high=mid-1;
}
return -1;
}
int main()
{
int a[20],key,i,n,succ;
printf("Enter the n value up to max of 20");
scanf("%d",&n);
if(n>0)
{
printf("enter the elements in ascending order\n"); for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("enter the key element to be searched\n");
scanf("%d",&key);
succ=binsrc(a,0,n-1,key); if(succ>=0)
printf("Element found in position=%d\n",succ+1);
else
printf("Element not found \n");
}
else
printf("Number of element should be greater than zero\n");

return 0;

}
Program Graph

1 2 3 4

14
7

8 9

11
15
10

12

13
DD Path graph

NODE DD-paths
S
1-3 A A

4 B
5,6 C
B
7 D
8 I
9 E
C
10 G
11,12 F
13 H
14 J
D
15 K J

I E

K G F

H
McCabe’s Basis path method
Considering DD-Path graph of the program, first we need to find Baseline path. A baseline path
consists of maximum number of decision nodes. Using Baseline path we start flipping each
decision node for finding new paths.
Considering Binary search program
Considering DD-Path graph of Binary search function, function starts at node A and Ends at node K.
First, Base Line path is formed by considering all decision nodes as shown below.

Baseline Path: A B C DE FH B J K.

Nodes which are bold and large are decision nodes. Now start flipping each decision node.
Flipping at B : A B J K.
Flipping at D : A B C D I K.
Flipping at E : A B C D E G H B J.

Cyclomatic Complexity

V(G) =e-n+2p
Where,
e is number of edges in DD-Path graph.
n is number of nodes in DD-Path graph.
p is number of regions connected.(always 1)
Number of linearly independent paths for a given graph G = 13-11+2(1)= 4 Test cases
Test Cases for Binary Search Program

Test Input
Cases Description Expected Output Comment
N Array elements Key
Infeasible because low>high
Enter the basis path consisting of 2 {5,10} 4 means from B to J then K which
TC1 Valid
all decision nodes 1 {10} 5 means no elements left which is
ABCDEFHBJK. not true in any case.
Infeasible because low>high
Enter the basis path consisting of means from B to J then K which
TC2 0 --------- ---- Invalid
all decision nodes ABJK. means no elements left which is
not true in any case.
2 {5,10} 10 Element found in position 2
Enter the basis path consisting of
TC3 3 {5,10,15} 10 Element found in position 2 Valid
all decision nodes ABCDIK.
5 {5,10,15,20,25} 15 Element found in position 3
Infeasible because low>high
Enter the basis path consisting of 2 {5,10} 15 means from B to J then K which
TC4 Invalid
all decision nodes 1 {10} 12 means no elements left which is
ABCDEGHBJK. not true in any case.

Note
Path B J K indicates fail of while (low<=high) condition. Because when there is one element in the
array, then low will b equal to high (i.e., low=high). Similarly when there are more than one elements in
the array low will be greater than high (i.e., low>high). So low>high means there no elements in the
array. So in above table paths containing B J K are considered as infeasible.
Experiment 7: Quick Sort Testing Technique: Path Testing
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);
}
}

int main()
{
int a[20],i,key,n;
printf("enter the size of the array max of 20 elements");
scanf("%d",&n);
if(n>0)
{
printf("enter the elements of the array");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
quicksort(a,0,n-1);
printf("the elements in the sorted array is:\n");
for(i=0;i<n;i++)
print f("%d\t",a[i]);
}
else

printf(“size of array is invalid\n”);


}
return 0;

Cyclomatic Complexity
V(G) =e-n+2p
or
V(G) =e-n+p (for closed closed graph)
Where,
e is number of edges in DD-Path
graph.
n is number of nodes in DD-Path
graph.
p is number of regions connected.
(always 1)
Number of linearly independent paths (Test cases) for a given graph G = 23-17+(1)

= 6+1

= 7 Test cases
Program graph
1 2 3 4 5 6 7 8

28
9

26
10

27 22 11

12 13
23

14

24 15
21

16
25

17

18

19

20
DD path graph

NODE DDPATH B
S S
1 A
2-3 B C N
4 C
5-8 D
9 E D
10 F
11 G
12 H O E
13 I
14 J
15 K F
16-20 L P
21 M G
22-25 N
26 P I
27 Q Q H
28 O K
J
M
L
McCabe’s Basis path method
Considering DD-Path graph of the program, first we need to find Baseline path. A baseline path
consists of maximum number of decision nodes. Using Baseline path we start flipping each
decision node for finding new paths.

Considering Quick Sort program


Considering DD-Path graph of Quick sort function, function starts at node A and Ends at node O.
First, Base Line path is formed by considering all decision nodes as shown below.

Baseline Path: AB CDE F GIK MENABCO P A B C O.

Nodes which are bold and large are decision nodes. Now start flipping each decision node.

Flipping at C : A B C O.
Flipping at E : A B C D E N A B C O.
Flipping at G : ABCDEFGHGIKMENAB
C O. Flipping at I : A BCDEFGIJ IKMENA
B C O. Flipping at K : ABCDEFGIKLMEN
A B C O.
Flipping at P : A B C D E F G I K L M E N A B C O P A B C O.
Test Cases for Quick Sort Program
Test Number of
Cases Description elements Array Elements Comment
(n)
Enter the basis path consisting of all decision Infeasible because path from G to I means no
TC1 nodes ----
elements in array. Invalid
ABCDEFGIKMENABCOPABCO.
Enter the basis path consisting of all decision
TC2 nodes ABCO.
1 {9} Valid
Path C to D indicates if(first<last) is condition
Enter the basis path consisting of all decision is true. So at first iteration
TC3 nodes ABCDENABCO.
---- while(x[i]<=x[pivot]&&i<last) condition also Invalid
should be true and path E to F should be
present. But we have EN so Infeasible
Enter the basis path consisting of all decision
TC4 nodes 2 {5,4 } Valid
ABCDEFGHGIKMENABCO.
Enter the basis path consisting of all decision Infeasible because path from G to I means no
TC5 nodes ---- elements in array. Invalid
ABCDEFGIJIKMENABCO.
Enter the basis path consisting of all decision Infeasible because path from G to I means no
TC6
nodes ABCDEFGIKLMENABCO.
----
elements in array. Invalid

Enter the basis path consisting of all decision Infeasible because path from G to I means no
TC7 nodes ----
elements in array. Invalid
ABCDEFGIKLMENABCOPABCO.
Note
If given array contains a single element, then first=last, if(first<last) condition is true indicates there are more
than one elements in the given array. Even when there will be single element While(x[i]<=x[pivot]&&i<last)
condition will get executed at least once, because x[i]=x[pivot] is also considered. So path there should be
one path G to H present for any feasible solution. So in above table paths containing G to I are all if
feasible.

You might also like