[go: up one dir, main page]

0% found this document useful (0 votes)
11 views45 pages

STQA File

The document outlines various testing approaches for solving the triangle problem, including Decision Table, Boundary Value Analysis, and Equivalence Class Partitioning. Each section includes a program implementation, test cases, and expected outcomes to determine if three integers can form different types of triangles. The document serves as a comprehensive guide for testing triangle classification algorithms.

Uploaded by

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

STQA File

The document outlines various testing approaches for solving the triangle problem, including Decision Table, Boundary Value Analysis, and Equivalence Class Partitioning. Each section includes a program implementation, test cases, and expected outcomes to determine if three integers can form different types of triangles. The document serves as a comprehensive guide for testing triangle classification algorithms.

Uploaded by

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

INDEX

TOPIC PAGE NO. REMARKS


S. NO
1. Decision Table approach for triangle problem
1-3

2. Boundary Value Analysis for triangle problem


4-6

3. Equivalence Class partitioning for triangle


7-9
problem

4. Dataflow Testing for Commission Problem


10-13

5. Boundary Value Analysis for Commission


Problem 14-18

6. Equivalence Class Partitioning for Commission


19-22
Problem
7. Decision Table for Commission Problem
23-25

8. Path testing of Binary Search .


26-28

9. Path Testing of Quick Sort


29-31
10. Path tesing for Absolute letter grading
32-34

11. Boundary Value Analysis for next date program


35-40

Equivalence class test for next date program


12
41-44
Program 1: Decision table approach for solving triangle problem
/* Design and develop a program in a language of your choice to solve the triangle problem
defined as follows : Accept three integers which are supposed to be the three sides of triangle and
determine if the three values represent an equilateral triangle, isosceles triangle, scalene triangle,
or they do not form a triangle at all. Derive test cases for your program based on decision-table
approach, execute the test cases and discuss the results *
#include <stdio.h>
int main()
{
int a, b, c;
char istriangle;

printf("Enter 3 integers which are sides of triangle:\n");


scanf("%d%d%d", &a, &b, &c);

printf("a=%d,\tb=%d,\tc=%d\n", a, b, c);

// To check if it is a triangle or not


if (a + b > c && b + c > a && c + a > b)
istriangle = 'y';
else
istriangle = 'n';

if (istriangle == 'y')
{
if ((a == b) && (b == c))
printf("Equilateral triangle\n");
else if ((a != b) && (a != c) && (b != c))
printf("Scalene triangle\n");
else
printf("Isosceles triangle\n");
}
else
{
printf("Not a triangle\n");
}

return 0;}

1
Experiment Number : 1

Test Case Name :Decision table for triangle problem


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
- - F T T T T T T T T
Conditio C3 : c < a + b
ns 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
Action a3 : Isosceles triangle X X X
s
a4 : Equilateral triangle X
a5 : Impossible X X X

Triangle Problem -Decision Table Test cases for input data

Input Data
Case Description Expected Output Actual Status
a b C
Id Output
Message should be
Enter the value of a, b and c
1 20 5 5 displayed can't form
Such that a is not less than sum
a
of two sides
triangle
Enter the value of a, b and c Message should be
2 Such that b is not less than sum 3 15 11 displayed can't form
of two sides and a is less than a
sum of other two sides triangle

2
Enter the value of a, b and c
Message should be
Such that c is not less than sum
3 4 5 20 displayed can't form
of two sides and
a triangle
a and b is less than sum of
other two sides
Should display the
Enter the value a, b and c
4 5 5 5 message
satisfying precondition and
Equilateral
a=b, b=c and c=a
triangle
Should display the
Enter the value a ,b and c
5 10 10 9 message Isosceles
satisfying precondition and a=b
triangle
and b ≠ c
Enter the value a, b and c Should display the
6 5 6 7
satisfying message Scalene triangle
precondition and a ≠b , b ≠ c and
c≠a

3
Program 2 (Boundary value analysis program)

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

#include <stdio.h>

int main()
{
int a, b, c, c1, c2, c3;
char istriangle;

do
{
printf("\nEnter 3 integers which are sides of triangle:\n");
scanf("%d%d%d", &a, &b, &c);

printf("\na = %d\tb = %d\tc = %d\n", 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 in the range of permitted value", a);
if (!c2)
printf("\nThe value of b = %d is not in the range of permitted value", b);
if (!c3)
printf("\nThe value of c = %d is not in the range of permitted value", c);

} while (!(c1 && c2 && c3));

// To check if it is a triangle or not


if (a + b > c && b + c > a && c + a > b)
istriangle = 'y';
else
istriangle = 'n';

if (istriangle == 'y')
{
if (a == b && b == c)
printf("Equilateral triangle\n");

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

Experiment Number : 2
Test Case Name :Boundary Value Analysis for triangle
Problem
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

Input
Actu
Case Description Data Expected Output Statu
al
Id Outp s
A b c
ut
Should display the message
1 Enter the min value for a , b and 1 1 1
Equilateral
c
triangle
Enter the min value for 2 items Message should be displayed can't
2 1 1 2
and form a
min +1 for any one item1 triangle
Enter the min value for 2 items Message should be displayed can't
3 1 2 1
and min +1 for any one form a triangle
item1
Enter the min value for 2 items Message should be displayed can't
4 2 1 1
and min +1 for any one form a triangle
item1
Enter the normal value for 2 Should display the message
5 5 5 1
items and 1 item is min Isosceles triangle

5
value

Enter the normal value for 2 Should display the message


6 5 1 5
items and 1 item is min Isosceles triangle
value
Enter the normal value for 2 Should display the message
7 1 5 5
items and 1 item is min Isosceles triangle
value
Should display the message
8 Enter the normal Value for a, b 5 5 5
Equilateral
and c
triangle
Enter the normal value for 2
9 5 5 10 Should display the message Not a
items and 1 item is max
triangle
value
Enter the normal value for 2 Should display the message Not a
10 5 10 5
items and 1 item is max triangle
value
Enter the normal value for 2 Should display the message Not a
11 10 5 5
items and 1 item is max triangle
value
Enter the max value for 2 items Should display the message
12 10 10 9
and max - 1 for any one Isosceles triangle
item
Enter the max value for 2 items Should display the message
13 10 9 10
and max - 1 for any one Isosceles triangle
item
Enter the max value for 2 items Should display the message
14 9 10 10
and max - 1 for any one Isosceles triangle
item
Should display the message
15 Enter the max value for a, b 10 10 10
Equilateral
and c
triangle

6
Program 3 (equivalence class partitioning program)

/* Design and develop a program in a language of your choice to solve the triangle problem defined
as follows : Accept three integers which are supposed to be the three sides of triangle and determine
if the three values represent an equilateral triangle, isosceles triangle, scalene triangle, or they do not
form a triangle at all. Derive test cases for your program based on equivalence class partitioning ,
execute the test cases and discuss the results */

#include <stdio.h>

int main()
{
int a, b, c, c1, c2, c3;
char istriangle;

do
{
printf("\nEnter 3 integers which are sides of triangle:\n");
scanf("%d%d%d", &a, &b, &c);

printf("\na=%d\tb=%d\tc=%d\n", 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 in the range of permitted value", a);
if (!c2)
printf("\nThe value of b=%d is not in the range of permitted value", b);
if (!c3)
printf("\nThe value of c=%d is not in the range of permitted value", c);

} while (!(c1 && c2 && c3));

// To check if it is a triangle or not


if (a + b > c && b + c > a && c + a > b)
istriangle = 'y';
else
istriangle = 'n';

if (istriangle == 'y')
{
if (a == b && b == c)
printf("Equilateral triangle\n");
else if ((a != b) && (a != c) && (b != c))
printf("Scalene triangle\n");
else
printf("Isosceles triangle\n");}
else { printf("Not a triangle\n"); } return 0;}
7
Experiment Number : 3
Test Case Name :Equivalence class Analysis for triangle problem

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 Equivalence class Testing


Case Input Actual Status Comme
Description Data Expected Output
Id Outpu nt
a b C t s
Should display the message
1 Enter the min value for a , b 5 5 5
Equilateral triangle
and c
Should display the message
2 Enter the min value for a , b 2 2 3
Isosceles
and c triangle
Should display the message
3 Enter the min value for a , b 3 4 5
Scalene
and c
triangle
Message should be displayed
4 Enter the min value for a , b 4 1 2
can't
and c
form a triangle

Weak Robust Equivalence class Testing


Enter one invalid input and Should display value of a is not
5 -1 5 5
two in the
valid value for a , b and c range of permitted values
Enter one invalid input and Should display value of a is not
6 5 -1 5
two in the
valid value for a , b and c range of permitted values
Enter one invalid input and Should display value of a is not
7 5 5 -1
two in the
valid value for a , b and c range of permitted values
Enter one invalid input and Should display value of a is not
8 11 5 5
two in the
valid value for a , b and c range of permitted values
Enter one invalid input and Should display value of a is not
9 5 11 5
two in the
valid value for a , b and c range of permitted values
Enter one invalid input and Should display value of a is not
10 5 5 11
two in the
valid value for a , b and c range of permitted values

8
Strong Robust Equivalence class Testing
Enter one invalid input Should display value of a is not
11 -1 5 5
and two in the
valid value for a , b and c range of permitted values
Enter one invalid input Should display value of a is not
12 5 -1 5
and two in the
valid value for a , b and c range of permitted values
Enter one invalid input Should display value of a is not
13 5 5 -1
and two in the
valid value for a , b and c range of permitted values
Should display value of a is not
Enter two invalid input in the
14 -1 -1 5 range of permitted values
and two valid value
for a , b and c Should display value of b is
not in the
range of permitted values
Should display value of b is
Enter two invalid input not in the
14 5 -1 -1 range of permitted values
and two valid value
for a , b and c Should display value of c is not
in the
range of permitted values
Should display value of a is not
Enter two invalid input in the
14 -1 5 -1 range of permitted values
and two valid value
for a , b and c Should display value of c is not
in the
range of permitted values
Should display value of a is not
in the
range of permitted values
15 Enter all invalid -1 -1 -1 Should display value of b is
inputs not in the
range of permitted values
Should display value of c is not
in the
range of permitted values

9
Program 4: (Dataflow Testing for commission calculation)

#include<stdio.h>
int main()
{
int locks, stocks, barrels, tlocks, tstocks, tbarrels;
float lprice,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\n");
scanf("%d", &locks);
while(locks!=-1) {
printf("enter the number of stocks and barrels\n");
scanf("%d%d",&stocks,&barrels);
tlocks=tlocks+locks;
tstocks=tstocks+stocks;
tbarrels=btarrels+barrels;
printf("\nenter the number of locks and to exit the loop enter -1 for locks\n");
scanf("%d",&locks);
}
printf("\ntotal locks = %d\”,tlocks);
printf(“total stocks =%d\n”,tstocks);
printf(“total barrels =%d\n",tbarrels);

lsales = lprice*tlocks;
ssales=sprice*tstocks;
bsales=bprice*tbarrels;
sales=lsales+ssales+bsales;
printf("\nthe total sales=%f\n",sales);
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

10
comm=0.10*sales;
printf("the commission is=%f\n",comm);
return 0;
}

Experiment No : 4
Test Case Name : Data Flow Testing for Commission Program
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 7 24
sprice 8 25
bprice 9 26
tlocks 10,16 16,21,24
tstocks 11,17 17,22,25
tbarrels 12,18 18,23,26
locks 13,19 14,16
stocks 15 17
barrels 15 18
lsales 24 27
ssales 25 27
bsales 26 27
sales 27 28,29,33,34,37,39
comm 31,32,33,36,37,39 32,33,37,42

11
Selected Define/Use Paths for Commission problem
Test variables
Definiti
case Description path(Begin Du paths Comme
on
id ning, End nts
clear
nodes)
?
Check for lock price variable <7-8-9-10-11-12-13-14-15-
1 (7 , 24) Yes
DEF(lprice,7) and 16-17-
USE(lprice,24) 18-19-20-21-22-23-24>
Check for Stock price variable <8-9-10-11-12-13-14-15-16-
2 (8 , 25) Yes
DEF(sprice,8) and 17-18-
USE(sprice,25) 19-20-21-22-23-24-25>
Check for barrel price variable <9-10-11-12-13-14-15-16-
3 (9 , 26) Yes
DEF(bprice,9) and 17-18-
USE(bprice,26) 19-20-21-22-23-24-25-26>
(10 , 16) <10-11-12-13-14-15-16> Yes
<10-11-12-13-14-15-16-17-
(10 , 21) No
18-19-
Check for total locks variable 20-14-21>
DEF((tlocks,10) and
4 <10-11-12-13-14-15-16-17-
DEF(tlocks,16)) and 3 usage (10 , 24) No
18-19-
node(USE(tlocks,16),USE(tlocks,21),
20-14-21-22-23-24>
USE(tlock s,24)
(16 , 16) <16-16> Yes
(16 , 21) <16-17-18-19-14-21> No

(16 , 24) <16-17-18-19-20-14-21-22- No


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

(17 , 25) <17-18-19-20-14-21-22-23- No


24-25>

12
Begin the
(13 , 14) <13-14> Yes
loop
check for locks variable
( 13 , 16) <13-14-15-16> Yes
6 ( DEF(locks,13)
,DEF(locks,19) (19 , 14) <19-20-14> Yes
and Repeat
(19 , 16) <19-20-14-15-16> Yes
USE(locks,14), the
USE(locks,16) loop
Check for stocks variable
7 (15 , 17) <15-16-17> Yes
(DEF(stocks,15) and
USE(stocks,17)
(27 ,28) <27-28> Yes
Check for sales DEF(sales, 27) and (27 , 29) <27-28-29> Yes
USE(Sales, 28), USE(Sales , 29), (27 , 33) <27-28-29-30-31-32-33> Yes
8
USE(Sales,33) , (27 , 34) <27-28-29-34> Yes
USE(Sales , 34) , USE(Sales,37) ,
(27 , 37) <27-28-29-34-35-36-37> Yes
USE(Sales , 39)
(27 , 39) <27-28-29-34-38-39> Yes
( (31,32,33),42) <31-32-33-42> Yes
Check for Commission variable
9 DEF(comm, 31,32,33) , ((34 , 35) , 42) <34-35-42> Yes
DEF(comm,34,35) and ((39 , 42 ) <39 - 42> Yes
DEF(comm,39) and
USE(comm,42)

13
Program 5, 6 and 7 ( Boundary , Equivalence and Decision Test Case for
Commission Problem)
/* Design. develop, code and run the program in nay suitable language to solve the commission
problem. Analyze it from the perspective of boundary value, derive 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\n");
else
{

14
temp = tlocks + locks;
if (temp > 70)
printf("New total locks = %d not in the range 1..70 so old\n", temp);
else
tlocks = temp;
}

printf("Total locks = %d\n", tlocks);

if (c2)
printf("Value of stocks not in the range 1..80\n");
else
{
temp = tstocks + stocks;
if (temp > 80)
printf("New total stocks = %d not in the range 1..80 so old\n", temp);
else
tstocks = temp;
}

printf("Total stocks = %d\n", tstocks);

if (c3)
printf("Value of barrels not in the range 1..90\n");
else
{
temp = tbarrels + barrels;
if (temp > 90)
printf("New total barrels = %d not in the range 1..90 so old\n", temp);
else
tbarrels = temp;
}

printf("Total barrels = %d\n", 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);

15
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 += 0.15 * 800;
comm += 0.20 * (sales - 1800.0);
}
else if (sales > 1000)
{
comm = 0.10 * 1000;
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;
}

16
Experiment Number : 5

Test Case Name : Boundary Value for Commission Problem


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.

Checking boundary value for locks, stocks and barrels and commission
Commission Problem Output Boundary Value Analysis Cases
Input Data Expected Actual
Case Output output Sta
Description
Id t
Tota Total Total Co Com
Sales Sale u Comment
l Stock Barrel m m
s s
Lock s s m- -
s issi ission
on
1 Enter the min value for locks, stocks 1 1 1 100 10 output minimum
and barrels
2 1 1 2 125 12.5 output
Enter the min value for 2 items and minimum +
min +1 for any one
3 1 2 1 130 13 output
item minimum +
4 2 1 1 145 14.5 output
minimum +
Enter the value sales approximately
5 mid value 5 5 5 500 50 Midpoint
between 100 to 1000
6 10 10 9 975 97.5 Border point -
Enter the values to calculate the
7 commission for sales nearly 10 9 10 970 97 Border point -
8 less than 1000 9 10 10 955 95.5 Border point -

9 Enter the values sales exactly equal to 10 10 10 1000 100 Border point
1000
10 10 10 11 1025 103.75 Border point +
Enter the values to calculate the
11 10 11 10 1030 104.5 Border point +
commission for sales nearly
12 greater than 1000 11 10 10 1045 106.75 Border point +

13 Enter the value sales approximately 14 14 14 1400 160 Midpoint


mid value between 1000 to 1800

17
14 Enter the values to calculate the 18 18 17 1775 216.25 Border point
-
commission for sales nearly
15 18 17 18 1770 215.5 Border point
less than 1800 -
16 17 18 18 1755 213.25 Border point
-
17 Enter the values sales exactly equal to 18 18 18 1800 220 Border
1800 point
18 18 18 19 1825 225 Border point
Enter the values to calculate the +
19 commission for sales nearly 18 19 18 1830 226 Border point
greater than 1800 +
20 19 18 18 1845 229 Border point
+
Enter the values normal value for lock,
21 stock and 48 48 48 4800 820 Midpoint
barrel
22 70 80 89 7775 1415 Output
Enter the max value for 2 items and maximum -
max - 1 for any one
23 item 70 79 90 7770 1414 Output
maximum -
24 69 80 90 7755 1411 Output
maximum -

25 Enter the max value for locks,stocks 70 80 90 7800 1420 Output


and barrels maximum
Output Special Value Test Cases
Input Data Expected Actual
Cas Output output
Description
e Tota Tota Total Commis Com
Id Sales Sale Statu Comment
l l Barrel si mi
s s
Lock Stock s on ssio
s s n
Enter the random values such that
1 11 10 8 995 99.5 Border point -
to calculate commission for sales
nearly less than 1000
Enter the random values such that
2 10 11 9 1005 100.75 Border point +
to calculate commission for sales
nearly greater than 1000
Enter the random values such that
3 18 17 19 1795 219.25 Border point -
to calculate commission for sales
nearly less than 1800
Enter the random values such that
4 18 19 17 180 221 Border
to calculate commission for sales
5 point +
nearly greater than 1800

18
Experiment Number : 6
Test Case Name :Equivalence Class for Commission Problem
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.
Checking boundary value for locks,stocks and barrels and
commission
Valid Classes

L1 ={LOCKS :1 <=LOCKS<=70}
L2 ={Locks=-1}(occurs if locks=-1 is used to control input iteration)
L3 ={stocks : 1<=stocks<=80}
L4= {barrels :1<=barrels<=90}

Invalid Classes

L3 ={locks: locks=0 OR locks<-1}


L4 ={locks: locks> 70}
S2 ={stocks : stocks<1}
S3 ={stocks : stocks >80}
B2 ={barrels : barrels <1}
B3 =barrels : barrels >90}

Commission Problem Output Equivalence Class Testing


( Weak & Strong Normal Equivalence Class )

Input Data Expected Actual


Case S
Description Output output Comm
Id t
To To To Com ent
Sales Commission Sal a
tal tal tal mi
es t
Lo Sto Bar ss
u
ck cks rels io
s
s n
Enter the value within the
1 35 40 45 3900 640
range for locks,stocks and
barrels

19
Weak Robustness equivalence Class
Cas Input Data St
Description Expected Output Actual Comm
e a
Locks Stock Barrel output ent
Id t
s s u
s

Terminates the input loop


WR1 Enter the value locks = -1 -1 40 45 and proceed to calculate
sales and commission ( if
Sales > 0)

Enter the value less than -1


WR2 0 40 45 Value of Locks not in the
or equal to
range 1..70
zero for locks and other
valid inputs

Enter the value greater


WR3 71 40 45 Value of Locks not in the
than 70 for locks and
range 1..70
other valid inputs

Enter the value less than


WR4 35 0 45 Value of stocks not in the
or equal than 0 for stocks
range 1..80
and other valid inputs

Enter the value greater


WR5 35 81 45 Value of stocks not in the
than 80 for stocks and
range 1..80
other valid inputs

Enter the value less than or


WR6 35 40 0 Value of Barrels not in the
equal 0 for barrels and
range 1..90
other valid inputs

Enter the value greater than


WR7 35 40 91 Value of Barrels not in the
90 for barrels and other
range 1..90
valid inputs

20
Strong Robustness equivalence Class
Case Input S
Description Expected Actual Comm
Id Data t
Output output ent
Locks Stock Barrel a
s s t
u
s

Enter the value less than -1


SR1 -2 40 45 Value of Locks not in the
for locks
and other valid inputs range 1..70

Enter the value less than or


SR2 35 -1 45 Value of stocks not in the
equal than
0 for stocks and other valid range 1..80
inputs

Enter the value less than or


SR3 35 40 -2 Value of Barrels not in
equal 0 for
barrels and other valid
the range 1..90
inputs

Enter the locks and stocks Value of Locks not in the


SR4 -2 -1 45 range 1..70
less than or equal to 0 and
other valid inputs
Value of stocks not in the
range 1..80

Enter the locks and barrel Value of Locks not in the


SR5 -2 40 -1
less than or equal to 0 and range 1..70
other valid inputs
Value of Barrels not in
the range 1..90

Enter the stocks and barrel Value of stocks not in the


SR6 35 -1 -1
less than or equal to 0 and range 1..80
other valid inputs Value of Barrels not in the
range 1..90
Value of Locks not in the
Enter the stocks and barrel range 1..70
SR7 -2 -2 -2
less than or equal to 0 and Value of stocks not in the
other valid inputs range 1..80
Value of Barrels not in the
range 1..90

21
Input Expected Actual
Case Data Output output
Description Id To To To Sa Com S
Sales Commission Comm
tal tal tal l m t
ent
Lo Sto Bar e iss a
cks cks rels io t
s n u
s
Enter the value for lock,
OR1 5 5 5 500 50
stocks and barrels where
0 < Sales < 1000
Enter the value for lock,
OR2 stocks and barrels where 15 15 15 1500 175
1000 < Sales < 1800
Enter the value for lock,
OR3 25 25 25 2500 360
stocks and barrels where
Sales < 1800

22
Experiment Number : 7

Test Case Name :Decision Table for Commission Problem


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.

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 X X X X X X
a5 : Calculate Sales X
a6: proceed to commission decision table X
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

23
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
Commission Problem -Decision Table Test cases for input data
Ca Input Act St Co
Description Data Expected Output
se ual a m
L S Bar
I o t r
Out t m
d c o els put u ent
k c s s
s k
s
Terminate the input loop check for sales
1 Enter the value of Locks= -1
if(sales=0) exit from program else
-1
calculate commission
Total of locks,stocks is updated if it is with
Enter the valid input for
2 20 30 -5 in a precondition limit and Should display
lock and stack and
value of barrels is not
invalid for barrels
in the range 1..90
Total of locks, barrels is updated if it is with
Enter the valid input for
3 15 -2 45 in a precondition limit and Should display
lock and barrels and
value of barrels is not
invalid for stocks
in the range 1..80
Total of stocks , barrels is updated if it is
Enter the valid input for
4 -4 15 16 with in a precondition limit and Should
lock and barrels and
display value of barrels is not
invalid for stocks
in the range 1..70
Total of locks is updated if it is with in a
Enter the valid input
precondition limit and (i)Should display value
5 for lock and invalid 15 80 100
of stock is not in the range
value for stocks and
1..80 (ii)Should display value of barrels is not
barrels
in the range 1..90
Total of stocks is updated if it is with in a
Enter the valid input
precondition limit and (i)Should display
6 for stocks and invalid 88 20 99
value of lock is not in the range
value for locks and
1..70 (ii)Should display value of barrels is not
barrels
in the range 1..90
Total of barrels is updated if it is with in a
Enter the valid input
20 precondition limit and (i)Should display
7 for barrels and invalid 100 25
0 value of lock is not in the range
value for locks and
1..70 (ii)Should display value of stocks is not
stocks
in the range 1..80
(i) Should display value of lock is not in the
Enter the invalid input for 40
8 -5 -9 range 1..70
lock , stocks and barrels 0
(ii) Should display value of stocks is not in
the range 1..80
(iii) Should display value of barrel in not in
the range 1..90
Total of locks,stocks and barrels is updated if
Enter the valid input for
9 15 20 25 it is with in a precondition limit and calculate
lock, stocks and barrels
the sales and proceed to commission

24
Commission Problem -Decision Table Test cases for commission calculation

Input Data Expected Output


Ca Act St Co
Description
s ual a m
e Sales Commission Out t m
I Values put u ent
d s s
Terminate the program where 0
1 Check the value of sales 0
commission is
zero
if sales value with in 900
2 these range( Sales > 0 900 Then commission = 0.10*sales = 90
AND Sales ≤
1000 )
if sales value with in 1600
Then commission = 0.10*1000 +
3 these range( Sales > 1400
0.15*(sales - 1000)
1000 AND Sales
≤ 1800 )
if sales value with in Then commission = 0.10*1000 + 3400
4 2500
these range( Sales > 0.15*800 +
1800 0.20 *(sales - 1800)

25
Program 8(Binary Search - Path Testing)
/* Design, develop a code and run the program in any suitable language to implement the binary
search algorithm. Determine the basis paths and using them derive different test cases execute
these test cases and discuss the test results */

#include <stdio.h>

int binsrc(int x[], int low, int high, int key)


{
int mid;
while (low <= high)
{
mid = (low + high) / 2;
if (x[mid] == key)
return mid;
if (x[mid] < key)
low = mid + 1;
else
high = mid - 1;
}
return -1;
}

int main()
{
int a[20], key, i, n, succ;
printf("Enter the n value: ");
scanf("%d", &n);

if (n > 0)
{
printf("Enter the elements in ascending order:\n");
for (i = 0; i < n; i++)
scanf("%d", &a[i]);

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 elements should be greater than zero\n");
}
return 0;
}

26
Binary Search function with line number
int binsrc(int x[],int low, int high, int key)
{
int mid; 1
while(low<=high) 2
{
mid=(low+high)/2;
if(x[mid]==key) 3
return mid; 8
if(x[mid]<key) 4
low=mid+1; 5
else
high=mid-1; 6
} 7
return -1; 8
} 9

Program Graph – for Binary Search

27
Test Cases – Binary Search

28
Program 9(Quick Sort-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);
}
}

// main program
int main()
{
int i, x[10];
printf("Enter the size of the array: ");
int n;
scanf("%d", &n);

29
printf("Enter the elements of the array:\n");
for (i = 0; i < n; i++)
scanf("%d", &x[i]);

quicksort(x, 0, n - 1);

printf("The elements in the sorted array are:\n");


for (i = 0; i < n; i++)
printf("%d ", x[i]);

printf("\nEnd of array is initialized.\n");


return 0;
}

Quick sort function with line number

30
Program Graph Quick Sort

Independent Paths– Quick Sort


P1: A-B-N
P2: A-B-C-J-K-B
P3: A-B-C-J-K-M-B
P4: A-B-C-D-F-H-C
P5: A-B-C-D-F-H-I-C
P6: A-B-C-D-E-D-F-H
P7: A-B-C-D-F-G-F-H
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

31
Program 10 (Absolute Letter Grading Path Testing)
/* 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;
}

32
Absolute Grading Program with Line Numbers and Program Graph
int main() Start
1
{
float per;
char grade; 2
1. scanf("%f",&per);
2. if(per>=90) 3
3. grade= 'A'; 4
4. else if(per>=80 && per<90)
5. grade ='B'; 5
6.
else if(per>=70 && per<80)
6
7. grade ='C';
8.
else if(per>=60 && per<70) 7
8
9. grade='D';
10. else grade='E'; 9
11. switch(grade) 10
12. {
13. case 'A': printf("\nEXCELLENT"); break;
14. case 'B':printf("\nVery Good"); break; 11
15. case 'C' : printf("\nGood"); break;
16. case 'D': printf("\nAbove Average"); break;
17. case 'E': printf("\n Satisfactory"); break; 13 14 15 16 17
18. }
19. printf("\t The percentage = %f and grade is %c ",per,grade);
20. return 0; 19
}
1 End
Independent Paths:
#Edges=25, #Nodes=18, #P=1
V(G)= E-N+2P = 25-18+2 = 09

P1: 1-2-4-6-8-10-11-17-19-20 E Grade


P2: 1-2-4-6-8-9-11-16-19-20 D Grade
P3: 1-2-4-6-7-11-15-19-20 C Grade
P4: 1-2-4-5-11-14-19-20 B Grade
P5: 1-2-3-11-13-19-20 A Grade
P6: 1-2-4-6-8-10-11-13-19-20
P7: 1-2-4-6-8-10-11-14-19-20
P8: 1-2-4-6-8-10-11-15-19-20
P9: 1-2-4-6-8-10-11-16-19-20

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

Test Cases – Absolute Grading

34
Program 11 and 12 ( Next date program)
/* Design,develop,code and run the program in any suitable language to implement the
NextDate function. Analyze it from the perspective boundary value testing and
equivalence class analysis. 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)
{
printf("value of day, not in the range 1...31\n");
flag='n';
}

if(month<1 || month>12)
{

35
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.......2013\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';
}
}
}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;

36
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)
tomm_day=day+1;
else
{
tomm_day=1;
tomm_month=1;
if(year==2013)
{
printf("the next day is out of boundary value of year\n");
tomm_year=year+1;
}
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; }

37
Experiment Number : 11

Test Case Name : Boundary Value Analysis test cases for Next date program
Test data : Enter the three integer value
Pre-condition : Month 1 to 12 , DAY 1 TO 31 AND YEAR 1812 TO 2013 / 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 2012 2013

Next date Output Boundary Value Analysis Cases


Input Expected Actual
Case Description Data Output output Status Comm
Id ent
Mont day year Mont day year Mo da yea
h h nth y r

1 Enter the min value 1 1 1812 1 2 1812


month,day and year
Enter the min+1 value for
2 year and min for month and 1 1 1813 1 2 1813
day
Enter the normal value for
3 year and min for month and 1 1 1912 1 2 1912
day
Enter the max -1 value for
4 year and min for month and 1 1 2012 1 2 2012
day
Enter the max value for year
5 and min for month and day 1 1 2013 1 2 2013

Enter the min+1 value of day


6 and min for 1 2 1812 1 3 1812
month and year
Enter the min+1 value for day
7 and year and min for month 1 2 1813 1 3 1813

38
Enter the min+1 value for
8 day , normal value for year 1 2 1912 1 3 1912
and min value for month
Enter the min+1 value for
9 day , max -1 value for year 1 2 2012 1 3 2012
and min value for month
Enter the min+1 value for
10 day , max value for year and 1 2 2013 1 3 2013
min value for month
Enter the normal value of
11 day and min for year and 1 15 1812 1 16 1812
month
Enter the normal value for
12 day and min+1 for year and 1 15 1813 1 16 1813
min for month
Enter the normal value for
13 day normal value for year and 1 15 1912 1 16 1912
min value for month
Enter the normal value for
14 day , max -1 value for year 1 15 2012 1 16 2012
and min value for month
Enter the normal value for
15 day , max value for year and 1 15 2013 1 16 2013
min value for month
Enter the max - 1 value of
16 day and min for day and 1 30 1812 1 31 1812
year
Enter the max -1 value for
17 day and min for month and 1 30 1813 1 31 1813
min+1 for year
Enter the max - 1 value for
18 day , normal value for year 1 30 1912 1 31 1912
and min value for month
Enter the max - 1 value for
19 day , max -1 1 30 2012 1 31 2012
value for year and min value
for month
Enter the max -1 value for
20 day , max value for year and 1 30 2013 1 31 2013
min value for month

39
Enter the max value of day
21
and min for year and month 1 31 1812 2 1 181
2
Enter the max value for day
22 and min for month and min + 1 31 1813 2 1 181
1 for year 3
Enter the max value for day ,
normal value for year and min 1 31 1912 2 1 191
value for month 2
Enter the max value for
24 day , max -1 value for year 1 31 2012 2 1 201
and min value for month 2
Enter the max value for
25 day , max value for year 1 31 2013 2 1 201
and min value for month 3

Next date Output Special value test cases


Input Data Expected Actual Statu
Case Description Output output s
Id Co
mont day year month day year mont da yea
m
h h y r
m
e
nt
Should
display the
1 Enter the D1, M1 and Y1 valid 12 31 1811
message
cases
value of the
year in range
1812..2013
2 Enter the D1, M1 and Y2 valid 12 31 2012 1 1 2013
cases
Should display the
3 Enter the D1, M1 and Y3 valid 12 31 2013 message Next is
cases out of boundary
2013

40
Experiment Number: 12

Test Case Name : Equivalence class test for Next Date program
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 ≤ 2013 }
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 > 2013}

Invalid cases Next date Output Equivalence Class Testing


( Weak and Strong Normal Equivalence Class )
Input Data Expected Actual
Case Description Output output Stat Comme
Id us nt
mont day year mont day yea mont da yea
h h r h y r

Enter the M1, D1 and Y1


6 15 1912 6 16 191
WN1,S valid cases 2
N1

41
( Weak Robustness Equivalence Class )
Comme
Input Expected Actual Stat
nt
Case Description Data Output output us
Id mon
mont day year month day year da yea
th
h y r
WR1 6 15 1912 6 16 1912
Enter the M1, D1 and Y1
cases
Should display the
message value of the
WR2 Enter the M2 , D1 and -1 15 1912 month not in the range
Y1 cases 1..12
Should display the
message value of the
WR3 Enter the M3 ,D1 and Y1 13 15 1912 month not in the range
cases 1..12
Should display the
WR4 Enter the M1, D2 and Y1 6 -1 1912 message value of the
cases day not in the range
1..31
Should display the
WR5 Enter the M1, D3 and Y1 6 32 1912 message value of the
cases day not in the range
1..31
Should display the
message value of the
WR6 Enter the M1, D1 and Y2 6 15 1811 year not in the range
cases 1812..2013
Should display the
message value
WR7 Enter the M1, D1 and Y3 6 15 2014 of the year not in the
cases range 1812..2013

42
(Strong Robustness Equivalence Class )
Ca Input Co
Description Data Expected Output Actual Stat
s m
mont day year output us
e me
h nt
I
d
Should display the message
SR1 Enter the M2 , D1 and -1 15 191
value of the month not
Y1 cases 2
in the range 1..12
Should display the message
SR2 Enter the M1, D2 and Y1 6 -1 191
value of the day not in
cases 2
the range 1..31
Should display the message
SR3 Enter the M1, D1 and Y2 6 15 181
value of the year not in
cases 1
the range 1812..2013
(i)Should display the message
value of the month
SR4 Enter the M2 , D2 and -1 -1 191
in range 1..12
Y1 cases 2
(ii) Should display the
message value of
the day in range
1..31
(i) Should display the
message value of
SR5 Enter the M1, D2 and 6 -1 181 the day in range
Y2 cases 1 1..31
(ii) Should display the
message value of the
year in range
1812..2013
(i)Should display the message
value of the month
SR6 Enter the M2, D1 and -1 15 181
in range 1..12
Y2 cases 1
(ii) Should display the
message value of the
year in range
1812..2013
(i)Should display the message
value of the month
in range 1..12

43
SR7 Enter the M2, D2 and -1 -1 181 (ii) Should display the
Y2 cases 1 message value of
the day in range
1..31
(iii) Should display the
message value of the
year in range
1812..2013

Some addition equivalence Boundary checking

Case Id Description Input Data Expected Output Actual output Stat Commen
us t
day mo year day mont year day mo year
nth h nth

1 Enter the D1, M1 and Y1 31 12 1811 Should display


valid cases the message
value of the year
in range
1812..2013

2 Enter the D1, M1 and Y2 31 12 2012 1 1 201


valid cases 3

3 Enter the D1, M1 and Y3 31 12 2013 Should display


valid cases the message Next
is out of
boundary 2013

44

You might also like