0% found this document useful (0 votes)
82 views53 pages

18isl67 New ST Manual

The document describes two programs - one for solving triangle types based on side lengths, and another for calculating sales commissions. For the triangle program, it outlines requirements to accept three side lengths, determine if a triangle can be formed, and if so identify the triangle type. It provides the design, algorithm, code, and test plan using boundary value analysis. For the commission program, it defines the sales and commission calculation problem, provides requirements, design including the algorithm and code. It also describes using boundary value analysis for testing, identifying equivalence classes based on input limits.

Uploaded by

Sameer Milan
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)
82 views53 pages

18isl67 New ST Manual

The document describes two programs - one for solving triangle types based on side lengths, and another for calculating sales commissions. For the triangle program, it outlines requirements to accept three side lengths, determine if a triangle can be formed, and if so identify the triangle type. It provides the design, algorithm, code, and test plan using boundary value analysis. For the commission program, it defines the sales and commission calculation problem, provides requirements, design including the algorithm and code. It also describes using boundary value analysis for testing, identifying equivalence classes based on input limits.

Uploaded by

Sameer Milan
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/ 53

SOFTWARE TESTING LABORATORY

//Program 1: boundary-value analysis 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 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.*/

REQUIREMENTS:
R1. The system should accept 3 positive integer numbers (a, b, c) which represents 3 sides
of the triangle.
R2. Based on the input should determine if a triangle can be formed or not.
R3. If the requirement R2 is satisfied then the system should determine the type of the
triangle, which can be
• Equilateral (i.e. all the three sides are equal)
• Isosceles (i.e Two sides are equal)
• Scalene (i.e All the three sides are unequal)
R4. Upper Limit for the size of any side is 10

DESIGN:
ALGORITHM:

Step 1: Input a, b & c i.e three integer values which represent three sides of the triangle.
Step 2: if (a < (b + c)) and (b < (a + c)) and (c < (a + b) then do step 3
else
print not a triangle. do step 6.
Step 3: if (a=b) and (b=c) then
Print triangle formed is equilateral. do step 6.
Step 4: if (a ≠ b) and (a ≠ c) and (b ≠ c) then
Print triangle formed is scalene. do step 6.
Step 5: Print triangle formed is Isosceles.
Step 6: stop

DEPARTMENT OF ISE 1
SOFTWARE TESTING LABORATORY

PROGRAM CODE:

#include<stdio.h>
int main()
{
int a, b, c;
printf("Enter three sides of the triangle");
scanf("%d%d%d", &a, &b, &c);
if((a > 10) || (b > 10) || (c > 10))
{
printf("Out of range");
exit(0);
}
if((a<b+c)&&(b<a+c)&&(c<a+b))
{
if((a==b)&&(b==c))
{
printf("Equilateral triangle");
}
else if((a!=b)&&(a!=c)&&(b!=c))
{
printf("Scalene triangle");
}
else
printf("Isosceles triangle");

}
else
{
printf(“triangle cannot be formed”);
}
return 0;
}

DEPARTMENT OF ISE 2
SOFTWARE TESTING LABORATORY

TESTING:

1. Technique used: Boundary value analysis


2. Test Case design
The maximum limit of each sides a, b, and c of the triangle is 10 units according to
requirement R4. So a, b and c lies between

0≤a≤10
0≤b≤10
0≤c≤10

Equivalence classes for a:


E1: Values less than 1.
E2: Values in the range.
E3: Values greater than 10.

Equivalence classes for b:


E4: Values less than 1.
E5: Values in the range.
E6: Values greater than 10.

Equivalence classes for c:


E7: Values less than 1.
E8: Values in the range.
E9: Values greater than 10.

From the above equivalence classes we can derive the following test cases using boundary
value analysis approach.

TC Test Case Input Data Expected Actual Status


Id Description Output Output
a b C

EXECUTION:
Execute the program against the designed test cases and complete the table.

RESULT:
Thus, the program for the solving triangle problem is designed, developed and programmed.
Also derived the test cases and executed the test cases using boundary value analysis approach and
the results are verified.

DEPARTMENT OF ISE 3
SOFTWARE TESTING LABORATORY

//Program2: boundary-value analysis for solving Commission problem

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

REQUIREMENTS:

Problem Definition: The Commission Problem includes a salesperson in the former Arizona Territory
sold rifle locks, stocks and barrels made by a gunsmith in Missouri. Cost includes

Locks- $45
Stocks- $30
Barrels- $25
The salesperson had to sell at least one complete rifle per month and production limits were such that the
most the salesperson could sell in a month was 70 locks, 80 stocks and 90 barrels.
After each town visit, the sales person sent a telegram to the Missouri gunsmith with the number of locks,
stocks and barrels sold in the town. At the end of the month, the sales person sent a very short telegram
showing --1 lock sold. The gunsmith then knew the sales for the month were complete and computed
the salesperson’s commission as follows:
On sales up to(and including) $1000= 10%,On the sales up to(and includes) $1800= 15%, On the sales
in excess of $1800= 20%. The commission program produces a monthly sales report that gave the total
number of locks, stocks and barrels sold, the salesperson’s total dollar sales and finally the commission.

DESIGN:

ALGORITHM:

STEP 1: Define lockPrice=45.0, stockPrice=30.0, barrelPrice=25.0


STEP 2: Input locks

STEP 3: while(locks!=-1) ‘input device uses -1 to indicate end of data goto STEP 12

STEP 4:input (stocks, barrels)

STEP 5: compute lockSales, stockSales, barrelSales and sales

STEP 6: output(“Total sales:” sales)

STEP 7: if (sales > 1800.0) goto STEP 8 else goto STEP 9

STEP 8: commission=0.10*1000.0;
commission=commission+0.15 *800.0;
commission = commission + 0.20 * (sales-1800.0)

DEPARTMENT OF ISE 4
SOFTWARE TESTING LABORATORY

STEP 9: if (sales > 1000.0) goto STEP 10 else goto STEP 11

STEP 10: commission=0.10* 1000.0; commission=commission + 0.15 * (sales-1000.0)

STEP 11: commission=0.10* sales

STEP 12: Output (“Commission is $”, commission)

STEP 13: exit

PROGRAM CODE:
#include<stdio.h>
int main()
{
int locks, stocks, barrels, t_sales, flag = 0;
float commission;
printf("Enter the total number of locks");
scanf("%d",&locks);
if ((locks <= 0) || (locks > 70))
{
flag = 1;
}
printf("Enter the total number of stocks");
scanf("%d",&stocks);
if ((stocks <= 0) || (stocks > 80))
{
flag = 1;
}
printf("Enter the total number of barrelss");
scanf("%d",&barrels);
if ((barrels <= 0) || (barrels > 90))
{
flag = 1;
}
if (flag == 1)
{
printf("invalid input");
exit(0);
}
t_sales = (locks * 45) + (stocks * 30) + (barrels * 25);
if (t_sales <= 1000)
{
commission = 0.10 * t_sales;

DEPARTMENT OF ISE 5
SOFTWARE TESTING LABORATORY

}
else if (t_sales < 1800)
{
commission = 0.10 * 1000;
commission = commission + (0.15 * (t_sales - 1000));
}
else
{
commission = 0.10 * 1000;
commission = commission + (0.15 * 800);
commission = commission + (0.20 * (t_sales - 1800));
}
printf("The total sales is %d \n The commission is %f",t_sales, commission);
return;
}

TESTING:

Technique used: Boundary value analysis

‘Boundary value analysis’ testing technique is used to identify errors at boundaries rather than finding
those exist in center of input domain.

Boundary value analysis is a next part of Equivalence partitioning for designing test cases where test
cases are selected at the edges of the equivalence classes.

BVA: Procedure

1. Partition the input domain using unidimensional partitioning. This leads to as many partitions as
there are input variables. Alternately, a single partition of an input domain can be created using
multidimensional partitioning. We will generate several sub-domains in this step.
2. Identify the boundaries for each partition. Boundaries may also be identified using special
relationships amongst the inputs.
3. Select test data such that each boundary value occurs in at least one test input.
4. BVA: Example: Create equivalence classes

Test Case design:

The Commission Problem takes locks, stocks and barrels as input and checks it for validity. If it is
valid, it returns the commission as its output. Here we have three inputs for the program, hence n =3.
Since BVA yields (4n +1) test cases according to single fault assumption theory, hence we can say
that the total number of test cases will be (4*3+1)=12+1=13.

DEPARTMENT OF ISE 6
SOFTWARE TESTING LABORATORY

The b o u n d a r y v a l u e test cases can be generated over output by using following constraints:

C1: Sales up to (and including) $1000= 10% commission


C2: Sales up to (and includes) $1800= 15% commission
C3: Sales in excess of $1800= 20% commission
Equivalence classes for 10% Commission:
E1: Sales less than 1000.
E2: Sales equals to 1000.
Equivalence classes for 15% Commission:
E3: Sales greater than 1000 and less than 1800.
E4: Sales equals to 1800
Equivalence classes for 20% Commission:
E5: Sales greater than 1800

From the above equivalence classes we can derive the test cases using boundary value analysis
approach.
TC Id Test Case Input Data Expected Output Actual
Statu
Sales (Commission)
Description Locks Stocks Barrels Output s

EXECUTION:
Execute the program against the designed test cases and complete the table.

RESULT:

Thus, the program for the solving commission problem is designed, developed and
programmed. Also derived the test cases and executed the test cases using boundary value analysis
approach and the results are verified.

DEPARTMENT OF ISE 7
SOFTWARE TESTING LABORATORY

//Program3: boundary-value analysis for solving NextDate function.

/*Design, develop, code and run the program in any suitable language to implement
the NextDate function. Analyze it from the perspective of boundary value testing,
derive different test cases, execute these test cases and discuss the test results.*/

REQUIREMENTS:

Problem Definition: "Next Date" is a function consisting of three variables like: month, date and
year. It returns the date of next day as output. It reads current date as input date.

The constraints are

C1: 1 ≤ month ≤ 12
C2: 1 ≤ day ≤ 31
C3: 1812 ≤ year ≤ 2012.

If any one condition out of C1, C2 or C3 fails, then this function produces an output "value of month
not in the range 1...12".

Since many combinations of dates can exist, hence we can simply displays one message for this
function: "Invalid Input Date".

A very common and popular problem occurs if the year is a leap year. We have taken into consideration
that there are 31 days in a month. But what happens if a month has 30 days or even 29 or 28 days?

A year is called as a leap year if it is divisible by 4, unless it is a century year. Century years are leap
years only if they are multiples of 400. So, 1992, 1996 and 2000 are leap years while 1900 is not a
leap year.

DESIGN:

ALGORITHM:

STEP 1: Input date in format DD.MM.YYYY

STEP2: if MM is 01, 03, 05,07,08,10 do STEP3 else STEP6

STEP3: if DD < 31 then do STEP4 else if DD=31 do STEP5


else output(Invalid Date);

STEP4: tomorrowday=DD+1 goto STEP18

STEP5: tomorrowday=1; tomorrowmonth=month + 1 goto STEP18

STEP6: if MM is 04, 06, 09, 11 do STEP7

STEP7: if DD<30 then do STEP4 else if DD=30 do STEP5

DEPARTMENT OF ISE 8
SOFTWARE TESTING LABORATORY

else output(Invalid Date);

STEP8: if MM is 12

STEP9: if DD<31 then STEP4 else STEP10

STEP10: tomorrowday=1, tommorowmonth=1, tommorowyear=YYYY+1;


goto STEP18

STEP11: if MM is 2

STEP12: if DD<28 do STEP4 else do STEP13

STEP13: if DD=28 & YYYY is a leap do STEP14 else STEP15

STEP14: tommorowday=29 goto STEP18

STEP15: tommorowday=1, tomorrowmonth=3, goto STEP18

STEP16: if DD=29 then do STEP15 else STEP17

STEP17: output (“Cannot have feb”, DD); STEP19

STEP18: output (tomorrowday, tomorrowmonth, tomorrowyear);

STEP19: exit

PROGRAM CODE:

#include<stdio.h>
int main()
{
int td,tm,ty;
int d,m,y;
printf("enter todays date in the form of MM,DD,YYYY\n");
scanf("%d%d%d",&m,&d,&y);
td=d;
tm=m;
ty=y;
if(m==1||m==3||m==5||m==7||m==8||m==10)
{
if((d<31)&&(d>0))
{
td=d+1;
}
else if(d==31)
{

DEPARTMENT OF ISE 9
SOFTWARE TESTING LABORATORY

td=1;
tm=m+1;
}

else
{
printf("day out of range\n");
}
}
else if(m==4||m==6||m==9||m==11)
{
if(d<30)
{
td=d+1;
}
else
{
td=1;
tm=m+1;
}
}
else if(m==12)
{
if(d<31)
{
td=d+1;
}
else
{
td=1;
tm=1;
ty=y+1;
printf("%d is over\n",y);
}
}
else if(m==2)
{
if(d<28)
{
td=d+1;
}
else
{
if(d==28)
{

DEPARTMENT OF ISE 10
SOFTWARE TESTING LABORATORY

if((y%4)!=0)
{
td=1;
tm=m+1;
}
else
{
td=d+1;
}
}
else
{
if(d==29)
{
td=1;
tm=m+1;
}
else
{
printf("invalid date in feb\n");
}
}
}
}
else
{
printf("month out of range\n");
}
printf("%d\%d\%d",tm,td,ty);
}

TESTING:

Technique used: Boundary value analysis

‘Boundary value analysis’ testing technique is used to identify errors at boundaries rather than finding
those exist in center of input domain.

Boundary value analysis is a next part of Equivalence partitioning for designing test cases where test
cases are selected at the edges of the equivalence classes.

Test Case design:


The Next Date program takes date as input and checks it for validity. If it is valid, it returns the next
date as its output. Here we have three inputs for the program, hence n = 3.
Since BVA yields (4n + 1) test cases according to single fault assumption theory, hence we can

DEPARTMENT OF ISE 11
SOFTWARE TESTING LABORATORY

say that the total number of test cases will be (4*3+1)=12+1=13.

The boundary value test cases can be generated by using following constraints

C1: 1 ≤MM ≤ 12
C2: 1 ≤ DD ≤ 31
C3: 1812 ≤ YYYY ≤ 2012.

Here from these constraints we can extract the test cases using the values of MM, DD, and YYYY.
The following equivalence classes can be generated for each variable.

Equivalence classes for MM:


E1: Values less than 1.
E2: Values in the range.
E3: Values greater than 12.
Equivalence classes for DD:
E4: Values less than 1.
E5: Values in the range.
E6: Values greater than 31.
Equivalence classes for YYYY:
E7: Values less than 1812.
E8: Values in the range.
E9: Values greater than 2012.

From the above equivalence classes we can derive the test cases using boundary value analysis
approach.

TC Test Case Input Data Expected Actual Status


Id Description MM DD YYYY Output Output

EXECUTION:
Execute the program against the designed test cases and complete the table.

RESULT:
Thus, the program for the solving NextDate function is designed, developed and programmed. Also
derived the test cases and executed the test cases using boundary value analysis approach and the
results are verified.

DEPARTMENT OF ISE 12
SOFTWARE TESTING LABORATORY

//Program4: Equivalence Class partitioning 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 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.*/
REQUIREMENTS:

R1. The system should accept 3 positive integer numbers (a, b, c) which represents 3 sides
of the triangle.
R2. Based on the input should determine if a triangle can be formed or not.
R3. If the requirement R2 is satisfied then the system should determine the type of the
triangle, which can be
• Equilateral (i.e. all the three sides are equal)
• Isosceles (i.e. two sides are equal)
• Scalene (i.e. All the three sides are unequal)
R4. Upper Limit for the size of any side is 10

DESIGN:

Form the given requirements we can draw the following conditions:


C1: a<b+c?
C2: b<a+c?
C3: c<a+b?
C4: a=b?
C5: a=c?
C6: b=c?
According to the property of the triangle, if any one of the three conditions C1, C2 and C3
are not satisfied then triangle cannot be constructed. So only when C1, C2 and C3 are true
the triangle can be formed, then depending on conditions C4, C5 and C6 we can decide
what type of triangle will be formed. (i.e requirement R3).

DEPARTMENT OF ISE 13
SOFTWARE TESTING LABORATORY

PROGRAM CODE:

#include <stdio.h>
void main()
{
int a,b,c,d1,d2,d3,istry;
printf("enter the three sides of the triangle within the rang\n");
scanf("%d%d%d",&a,&b,&c);
d1=((1<=a)&&(a<=10));
d2=((1<=b)&&(b<=10));
d3=((1<=c)&&(c<=10));
if(!d1)
{
printf("a is out of range\n");
}
if(!d2)
{
printf("b is out of range\n");
}
if(!d3)
{
printf("c is out of range\n");
}
else
{
printf(“Side a is:%d”,a);
printf(“Side b is:%d”,b);
printf(“Side c is:%d”,c);
if(a<(b+c) && b<(a+c) && c<(a+b))
{
istry=1;

if(istry==1)
{
if((a==b)&&(b==c))
{
printf("triangle is equilateral\n");
}
else
{
if((a!=b)&&(a!=c)&&(b!=c))
{
printf("the triangle is scalene\n");
}
else
{
printf("the triangle is isoceles\n");

DEPARTMENT OF ISE 14
SOFTWARE TESTING LABORATORY

}
}
}
else
{
printf("triangle not possible\n");
}
}
}

TESTING:

1. Technique used: Equivalence class partitioning


2. Test Case design

Equivalence class partitioning technique focus on the Input domain, we can obtain a richer
set of test cases. What are some of the possibilities for the three integers, a, b, and c? They
can all be equal, exactly one pair can be equal.
The maximum limit of each side a, b, and c of the triangle is 10 units according to
requirement R4. So a, b and c lies between
0≤a≤10
0≤b≤10
0≤c≤10
Weak normal a n d s t r o n g n o r m a l equivalence class test cases:

TC Test Case Input Data Expected Output Actual Status


Id Description a b c Output
1 WN1,SN1 5 5 5 Equilateral Triangle
2 WN2,SN2 5 5 1 Isosceles Triangle
3 WN3,SN3 5 4 6 Scalene Triangle
4 WN4,SN4 8 4 1 Triangle cannot be formed

Weak Robust equivalence class test cases:

TC Test Case Input Data Expected Output Actual Status


Id Description a b c Output
1 WR1 -1 5 5 a is out of range
2 WR2 5 -1 5 b is out of range
3 WR3 5 5 -1 c is out of range
4 WR4 11 5 5 a is out of range
5 WR5 5 11 5 b is out of range
6 WR6 5 5 11 c is out of range

DEPARTMENT OF ISE 15
SOFTWARE TESTING LABORATORY

Strong Robust equivalence class test cases:

TC Test Case Input Data Expected Output Actual Status


Id Description a b c Output
1 SR1 -1 5 5 a is out of range
2 SR2 5 -1 5 b is out of range
3 SR3 5 5 -1 c is out of range
4 SR4 -1 -1 5 a, b is out of range
5 SR5 -1 5 -1 a ,c is out of range
6 SR6 5 -1 -1 b, c is out of range
7 SR7 -1 -1 -1 a,b,c is out of range

EXECUTION:
Execute the program against the designed test cases and complete the table.

RESULT:

Thus, the program for the solving triangle problem is designed, developed and programmed.
Also derived the test cases and executed the test cases using Equivalence Class partitioning
approach and the results are verified.

DEPARTMENT OF ISE 16
SOFTWARE TESTING LABORATORY

//Program5: Equivalence Class testing for solving Commission problem.

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

REQUIREMENTS:

Problem Definition: The Commission Problem includes a salesperson in the former Arizona
Territory sold rifle locks, stocks and barrels made by a gunsmith in Missouri. Cost includes:
Locks- $45
Stocks- $30
Barrels- $25

The salesperson had to sell at least one complete rifle per month and production limits were such
that the most the salesperson could sell in a month was 70 locks, 80 stocks and 90 barrels.
After each town visit, the sales person sent a telegram to the Missouri gunsmith with the number
of locks, stocks and barrels sold in the town. At the end of the month, the sales person sent a very
short telegram showing -1 lock sold.
The gunsmith then knew the sales for the month were complete and computed the
salesperson’s commission as follows: On sales up to (and including) $1000= 10%, On the sales up
to (and includes) $1800= 15% , On the sales in excess of $1800= 20%. The commission program
produces a monthly sales report that gave the total number of locks, stocks and barrels sold, the
salesperson’s total dollar sales and finally the commission.

DESIGN:

PROGRAM CODE:

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

DEPARTMENT OF ISE 17
SOFTWARE TESTING LABORATORY

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

c1=(locks<=0||locks>70);

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

else

temp=tstocks+stocks;

if(temp>80)

DEPARTMENT OF ISE 18
SOFTWARE TESTING LABORATORY

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;

DEPARTMENT OF ISE 19
SOFTWARE TESTING LABORATORY

comm=comm+0.20*(sales-1800.0);

else if(sales > 1000)

comm =0.10*1000;

comm=comm+0.15*(sales-1000);

else

comm=0.10*sales;

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

else

printf("there is no sales\n");

return 0;

TESTING:

1. Technique used: Equivalence class partitioning


2. Test Case design

The input domain of the commission problem is naturally partitioned by the limits on locks,
stocks and barrels. These equivalence classes are exactly those that would also be identified
by traditional equivalence class testing.
The first class is the valid input; the other two are invalid. The input domain equivalence classes
lead to very unsatisfactory sets of test cases. Equivalence classes defined on the output range of
the commission function will be an improvement.

The valid classes of the input variables are:


L1 = {locks: 1≤locks≤70}
L2 = {locks = -1} (occurs if locks = -1 is used to control input iteration)
S1 = {stocks:1≤stocks≤80}
B1 = {barrels: 1≤barrels≤90}
The corresponding invalid classes of the input variables are:
L3 = {locks: locks = 0 OR locks < -1}

DEPARTMENT OF ISE 20
SOFTWARE TESTING LABORATORY

L4 = {locks: locks > 70}


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

One problem occurs, however. The variables lock are also used as a sentinel to indicate no
more telegrams. When a value of -1 is given for locks, the while loop terminates, and the values
of totallocks, totalstocks and totalbarrels are used to compute sales, and then commission.
Expect for the names of the variables and the interval endpoint values, this is identical to our
first version of the NextDate function. therefore we will have exactly one weak normal
equivalence class test case and again, it is identical to the strong normal equivalence class test
case. Note that the case for locks = -1 just terminates the iteration.

Weak normal and Strong normal equivalence class test cases:

TC Test Case Input Data Sales Expected Actual Status


Id Description Locks Stocks Barrels Output(Commission) Output

1 WN,SN 10 10 10 1000 100

Weak Robust equivalence class test cases:

TC Test Case Input Data Sales Expected Actual Status


Id Description Locks Stocks Barrels Output(Commission) Output
1 WR1 -1 - - - there is no sales
2 WR2 -2 40 45 - Value of locks not in
the range of 1…….70
3 WR3 71 40 45 - Value of locks not in
the range of 1…….70
4 WR4 35 -1 45 - Value of stocks not in
the range of 1…….80
5 WR5 35 81 45 - Value of stocks not in
the range of 1…….80
6 WR6 35 40 -1 - Value of barrels not in
the range of 1…….90
7 WR7 35 40 91 - Value of barrels not in
the range of 1…….90

DEPARTMENT OF ISE 21
SOFTWARE TESTING LABORATORY

Strong Robust equivalence class test cases:

TC Test Case Input Data Sales Expected Actual Status


Id Description Locks Stocks Barrels Output(Commission) Output
1 WR1 -2 40 45 - Value of locks not in the
range of 1…….70
2 WR2 35 -1 45 - Value of stocks not in the
range of 1…….80
3 WR3 35 40 -2 - Value of barrels not in
the range of 1…….90
4 WR4 -2 -1 45 - Value of locks not in the
range of 1…….70
Value of stocks not in the
range of 1…….80
5 WR5 35 -1 -1 - Value of stocks not in the
range of 1…….80
Value of barrels not in
the range of 1…….90
6 WR6 -2 -1 -1 - Value of locks not in the
range of 1…….70
Value of stocks not in the
range of 1…….80
Value of barrels not in
the range of 1…….90

EXECUTION:
Execute the program against the designed test cases and complete the table.

RESULT:

Thus, the program for the solving commission problem is designed, developed and
programmed. Also derived the test cases and executed the test cases using Equivalence Class
partitioning approach and the results are verified.

DEPARTMENT OF ISE 22
SOFTWARE TESTING LABORATORY

//Program6: Equivalence Class testing for NextDate function.

/*Design, develop, code and run the program in any suitable language to
implement the NextDate function. Analyze it from the perspective of equivalence
class value testing, derive different test cases, execute these test cases and discuss
the test results.*/

REQUIREMENTS:

Problem Definition: "Next Date" is a function consisting of three variables like: month, date
and year. It returns the date of next day as output. It reads current date as input date.

The constraints are

C1: 1 ≤ month ≤ 12
C2: 1 ≤ day ≤ 31
C3: 1812 ≤ year ≤ 2012.

If any one condition out of C1, C2 or C3 fails, then this function produces an output "value of
month not in the range 1...12". Since many combinations of dates can exist, hence we can
simply displays one message for this function: "Invalid Input Date". A very common and
popular problem occurs if the year is a leap year. We have taken into consideration that there
are 31 days in a month. But what happens if a month has 30 days or even 29 or 28 days ?

A year is called as a leap year if it is divisible by 4, unless it is a century year. Century years are
leap years only if they are multiples of 400. So, 1992, 1996 and 2000 are leap years while 1900
is not a leap year.

DESIGN:

PROGRAM CODE:

#include<stdio.h>
int main()
{
int td,tm,ty;
int d,m,y,c1,c2,c3;
printf("enter todays date in the form of MM,DD,YYYY\n");
scanf("%d%d%d",&m,&d,&y);
c1=(1<=d)&&(d<=31);
c2=(1<=m)&&(m<=12);
c3=(1812<=y)&&(y<=2012);
if(!c1)
{
printf("date out of range");
}
else if(!c2)

DEPARTMENT OF ISE 23
SOFTWARE TESTING LABORATORY

{
printf("month out of range");
}
else if(!c3)
{
printf("year out of range");
}
else if(!c1||!c2||!c3)
{
exit(1);
}
else
{
td=d;
tm=m;
ty=y;
if(m==1||m==3||m==5||m==7||m==8||m==10)
{
if(d<31)
{
td=d+1;
}
else
{
td=1;
tm=m+1;
}
}
if(m==4||m==6||m==9||m==11)
{
if(d<30)
{
td=d+1;
}
else
{
if(d==30)
{
td=1;
tm=m+1;
}
else
{
printf(“Invalid input date\n”);
}
}
}

if(m==12)
{

DEPARTMENT OF ISE 24
SOFTWARE TESTING LABORATORY

if(d<31)
{
td=d+1;
}
else
{
td=1;
tm=1;
ty=y+1;
printf("%d is over\n",y);
}
}
if(m==2)
{
if(d<28)
{
td=d+1;
}
else
{
if(d==28)
{
if((y%4)!=0)
{
td=1;
tm=m+1;
}
else
{
td=d+1;
}
}
else
{
if(d==29)
{
td=1;
tm=m+1;
}
else
{
printf("invalid date in feb\n");
}
}
}
}
printf("%d|%d|%d",tm,td,ty);
}
}

DEPARTMENT OF ISE 25
SOFTWARE TESTING LABORATORY

TESTING:

1. Technique used: Equivalence class partitioning


2. Test Case design

The NextDate function is a function which will take in a date as input and produces as output
the next date in the Georgian calendar. It uses three variables (month, day and year) which
each have valid and invalid intervals.

Weak and Strong Normal Equivalence Class test cases:

TC Test Case Input Data Expected Actual Status


Id Description MM DD YYYY Output Output
1 Testing for Valid 6 15 1900 6/16/1900
input changing
the day within the
month.

Since the number of variables is equal to the number of valid classes, only one weak normal
equivalence class test case occurs, which is the same as the strong normal equivalence class
test case.

Weak Robust Equivalence Class test cases:

TC Test Case Input Data Expected Actual


Id Description Output Output Status
MM DD YYYY
1 Testing for Valid input 6 15 1900 6/16/1900
changing the day
within the month.
2 Testing for Invalid 6 -1 1900 date out of range
Day, day with
negative number it is
not possible.
3 Testing for Invalid 3 33 1900 date out of range
Day, day with
negative number it is
not possible.
4 Testing for -1 15 1900 month out of
Invalid Month, range
month with negative
number it is not
possible.

DEPARTMENT OF ISE 26
SOFTWARE TESTING LABORATORY

5 Testing for 13 15 1900 month out of


Invalid month, range
month with out of
range i.e., MM=13 it
should be MM<=12
6 Testing for Year, year 6 15 1811 Year out of range
is out of range
YYYY=1811, it
should be <=1812
7 Testing for Year, year 6 14 2013 Year out of range
is out of range
YYYY=1899, it
should be <=1812

Strong Robust Equivalence Class Test cases:

TC Test Case Input Expected Actual Status

m Data Output Output


Id Description d y

1 Testing for Month is not in range month out of range


-1 15 1900
m=-1
2 Testing for Day is not in range d=-1 6 -1 1900 day out of range

3 Testing for Year is not in 6 15 1899 year out of range


range y=1899
4 Testing for Day and month is not in -1 -1 1900 Day, month out of
range m=-1, d=-1 range
5 Testing for Day is not in range and 6 -1 1811 Day, year out of
Year is not in range d=-1 range
6 Testing for Day and month is not in -1 15 1811 month , year out
range m=-1, y=-1 of range
7 Testing for Day is not in range and -1 -1 1811 month, day and year
Year is not in range d=-1 not in the range

EXECUTION:
Execute the program against the designed test cases and complete the table.

RESULT:

Thus, the program for the NextDate function is designed, developed and programmed. Also
derived the test cases and executed the test cases using Equivalence Class partitioning approach
and the results are verified.

DEPARTMENT OF ISE 27
SOFTWARE TESTING LABORATORY

//Program7: 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 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.*/
REQUIREMENTS:

R1. The system should accept 3 positive integer numbers (a, b, c) which represents 3
sides of the triangle. Based on the input it should determine if a triangle can be formed or not.
R2. If the requirement R1 is satisfied then the system should determine the type of the triangle,
which can be
• Equilateral (i.e. all the three sides are equal)
• Isosceles (i.e Two sides are equal)
• Scalene (i.e All the three sides are unequal)
else suitable error message should be displayed. Here we assume that user gives three positive
integer numbers as input.
DESIGN

Form the given requirements we can draw the following conditions: C1: a<b+c?
C2: b<a+c?
C3: c<a+b?
C4: a=b?
C5: a=c?
C6: b=c?
According to the property of the triangle, if any one of the three conditions C1, C2 and C3 are
not satisfied then triangle cannot be constructed. So only when C1, C2 and C3 are true the
triangle can be formed, then depending on conditions C4, C5 and C6 we can decide what
type of triangle will be formed. (i.e requirement R2).
DESIGN:

PROGRAM CODE:

#include<stdio.h>
int main()
{
int a, b, c;
printf("Enter three sides of the triangle");
scanf("%d%d%d", &a, &b, &c);
if((a<b+c)&&(b<a+c)&&(c<a+b))
{

DEPARTMENT OF ISE 28
SOFTWARE TESTING LABORATORY

if((a==b)&&(b==c))
{
printf("Equilateral triangle");
}
else if((a!=b)&&(a!=c)&&(b!=c))
{
printf("Scalene triangle");
}
else
printf("Isosceles triangle");

else
{
printf("triangle cannot be formed");
}
return 0;
}

TESTING:

Technique Used: Decision Table Approach


Decision Table-Based Testing has been around since the early 1960’s; it is used to depict
complex logical relationships between input data. A Decision Table is the method used
to build a complete set of test cases without using the internal structure of the program in
question. In order to create test cases we use a table to contain the input and output values
of a program.

DEPARTMENT OF ISE 29
SOFTWARE TESTING LABORATORY

The decision table is as given below:


Condition Entries (Rules)
Conditions R R
R1 R2 R3 R4 R5 R6 R7 R8 R9
10 11
C1: a<b+c? F T T T T T T T T T T
C2: b<a+c? -- F T T T T T T T T T
C3: c<a+b? -- -- F T T T T T T T T
C4: a=b? -- -- -- F T T T F F F T
C5: a=c? -- -- -- T F T F T F F T
C6: b=c? -- -- -- T T F F F T F T
Actions Action Entries
a1: Not a
Triangle X X X

a2: Scalene X
a3: Isosceles X X X
a4: Equilateral X
a5: Impossible X X X

The “--“ symbol in the table indicates don’t care values. The table shows the six conditions and
5 actions. All the conditions in the decision table are binary; hence, it is called as “Limited Entry
decision table”.
Each column of the decision table represents a test case. That is, The table is read as follows:
Action: Not a Triangle
1. When condition C1 is false we can say that with the given ‘a’ ‘b’ and ‘c’
values, it’s Not a triangle.
2. Similarly condition C2 and C3, if any one of them are false, we can say that with the
given ‘a’ ‘b’ and ‘c’ values it’s Not a triangle.
Action: Impossible
3. When conditions C1, C2, C3 are true and two conditions among C4, C5, C6 is true, there
is no chance of one conditions among C4, C5, C6 failing. So we can neglect these rules.
Example: if condition C4: a=b is true and C5: a=c is true .Then it is impossible, that
condition C6: b=c will fail, so the action is Impossible.
Action: Isosceles
4. When conditions C1, C2, C3 are true and any one condition among C4, C5 and C6 is
true with remaining two conditions false then action is Isosceles triangle.
Example: If condition C4: a=b is true and C5: a=c and C6: b=c are false, it means two

DEPARTMENT OF ISE 30
SOFTWARE TESTING LABORATORY

sides are equal. So the action will be Isosceles triangle.


Action: Equilateral
5. When conditions C1, C2, C3 are true and also conditions C4, C5 and C6 are true then,
the action is Equilateral triangle.
Action: Scalene
6. When conditions C1, C2, C3 are true and conditions C4, C5 and C6 are false i.e sides a,
b and c are different, then action is Scalene triangle.
Number of Test Cases = Number of Rules.

Using the decision table we obtain 11 functional test cases: 3 impossible cases,
3 ways of failing the triangle property, 1 way to get an equilateral triangle, 1 way to get a
scalene triangle, and 3 ways to get an isosceles triangle.
Deriving test cases using Decision Table Approach:
Test Cases:
TC Test Case Description Expected Output Actual
a b c Status
ID Output
1 Testing for Requirement 1 4 1 2 Not a Triangle
2 Testing for Requirement 1 1 4 2 Not a Triangle
3 Testing for Requirement 1 1 2 4 Not a Triangle
4 Testing for Requirement 2 5 5 5 Equilateral
5 Testing for Requirement 2 2 2 3 Isosceles
6 Testing for Requirement 2 2 3 2 Isosceles
7 Testing for Requirement 2 3 2 2 Isosceles
8 Testing for Requirement 2 3 4 5 Scalene

EXECUTION:
Execute the program against the designed test cases and complete the table.

RESULT:
Thus, the program for solving the triangle problem is designed, developed and programmed. Also
derived the test cases and executed the test cases using decision table approach and the results are
verified.

DEPARTMENT OF ISE 31
SOFTWARE TESTING LABORATORY

//Program8: Decision-table approach for solving commission problem.

/*Design, develop, code and run the program in any suitable language to solve
the commission problem. Analyze it from the perspective of decision table-based
testing, derive different test cases, execute these test cases and discuss the test
results.*/
REQUIREMENTS:
R1: The system should read the number of Locks, Stocks and Barrels sold in a month.
(i.e 1≤ Locks≤ 70)
(i.e 1Stocks ≤ 80)
(i.e 1 ≤ Barrels ≤ 90).
R2: If R1 is satisfied the system should compute the salesperson’s commission depending on the
total number of Locks, Stocks & Barrels sold else it should display suitable error message.
Following is the percentage of commission for the sales done:
10% on sales up to (and including) $1000
15% on next $800
20% on any sales in excess of $1800
Also the system should compute the total dollar sales. The system should output salespersons
total dollar sales, and his commission.

DESIGN:
Form the given requirements we can draw the following conditions:
C1: 1≤locks≤70? Locks = -1? (occurs if locks = -1 is used to control input iteration).
C2: 1≤stocks≤80?
C3: 1≤barrels≤90?

C4: sales>1800?

Here C1 can be expanded as:


C1a: 1≤locks
C1b: locks≤70
C5: sales>1000?
C6: sales≤1000?

DEPARTMENT OF ISE 32
SOFTWARE TESTING LABORATORY

PROGRAM CODE:
#include<stdio.h>
int main()
{
int locks, stocks, barrels, t_sales, flag = 0;
float commission;
printf("Enter the total number of locks");
scanf("%d",&locks);
if ((locks <= 0) || (locks > 70))
{
flag = 1;
}
printf("Enter the total number of stocks");
scanf("%d",&stocks);
if ((stocks <= 0) || (stocks > 80))
{
flag = 1;
}
printf("Enter the total number of barrels");
scanf("%d",&barrels);
if ((barrels <= 0) || (barrels > 90))
{
flag = 1;
}
if (flag == 1)
{
printf("invalid input");
exit(0);
}
t_sales = (locks * 45) + (stocks * 30) + (barrels * 25);
if (t_sales <= 1000)
{
commission = 0.10 * t_sales;
}
else if (t_sales < 1800)
{
commission = 0.10 * 1000;
commission = commission + (0.15 * (t_sales - 1000));

}
else

DEPARTMENT OF ISE 33
SOFTWARE TESTING LABORATORY

{
commission = 0.10 * 1000;
commission = commission + (0.15 * 800);
commission = commission + (0.20 * (t_sales - 1800));
printf("The total sales is %d \n The commission is %f",t_sales, commission);
return;
}
}

TESTING:
Technique Used: Decision Table Approach
The decision table is given below

Conditions Condition Entries (Rules)


C1: 1≤locks≤70? F T T T T T
C2: 1≤stocks≤80? -- F T T T T
C3: 1≤barrels≤90? -- -- F T T T
C4: sales>1800? -- -- -- T F F
C5: sales>1000? -- -- -- -- T F
C6: sales≤1000? -- -- -- -- -- T
Actions Action Entries
a1: com1 = 0.10*Sales X
a2: com2 =com1+0.15*(sales-1000) X
a3: com3 =com2+0.20*(sales-1800) X
a4: Out of Range. X X X

Using the decision table we get 6 functional test cases: 3 cases out of range, 1 case each for
sales greater than $1800, sales greater than $1000, sales less than or equal to $1000.

DERIVING TEST CASES USING Decision Table Approach:


Test Cases:

DEPARTMENT OF ISE 34
SOFTWARE TESTING LABORATORY

TC ID Test Case Expected Actual


Description Locks Stocks Barrels Output Output Status
Testing for
1 Requirement 1 -2 40 45 invalid input
Condition 1 (C1)
Testing for invalid input
2 Requirement 1 90 40 45
Condition 1 (C1)
Testing for invalid input
3 Requirement 1 35 -3 45
Condition 2 (C2)
Testing for invalid input
4 Requirement 1 35 100 45
Condition 2 (C2)
Testing for invalid input
5 Requirement 1 35 40 -10
Condition 3 (C3)
Testing for invalid input
6 Requirement 1 35 40 150
Condition 3 (C3)
Testing for 5 5 5
7 Requirement 2 500 a1:50
Testing for
8 Requirement 2 15 15 15 1500 a2: 175
Testing for
9 Requirement 2 25 25 25 2500 a3: 360

EXECUTION:
Execute the program against the designed test cases and complete the table.

RESULT:

Thus, the program for solving the commission problem is designed, developed and programmed.
Also derived the test cases and executed the test cases using decision table approach and the
results are verified.

DEPARTMENT OF ISE 35
SOFTWARE TESTING LABORATORY

//Program9: Dataflow testing for solving commission problem.


/*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.*/
REQUIREMENTS:

Problem Definition: The Commission Problem includes a salesperson in the former Arizona
Territory sold rifle locks, stocks and barrels made by a gunsmith in Missouri. Cost includes

Locks- $45
Stocks- $30
Barrels- $25
The salesperson had to sell at least one complete rifle per month and production limits
were such that the most the salesperson could sell in a month was 70 locks, 80 stocks and 90
barrels. After each town visit, the sales person sent a telegram to the Missouri gunsmith
with the number of locks, stocks and barrels sold in the town. At the end of the month, the
salesperson sent a very short telegram showing -1 lock sold. The gunsmith then knew the
sales for the month were complete and computed the salesperson’s commission as follows:
On sales up to(and including) $1000= 10%
On the sales up to(and includes) $1800= 15%
On the sales in excess of $1800= 20%.
The commission program produces a monthly sales report that gave the total number of
locks, stocks and barrels sold, the salesperson’s total dollar sales and finally the commission.

DESIGN :

Price:

Locks-$45
Stocks-$30
Barrels-$25

Range:
1<=locks<=70
1<=Stocks<=80
1<=barrels<=90

Commision:
On sales up to(and including) $1000= 10% commision
On the sales up to(and includes) $1800= 15% commision
On the sales in excess of $1800= 20% commision

DEPARTMENT OF ISE 36
SOFTWARE TESTING LABORATORY

PROGRAM CODE:

1 //Program 4: (Dataflow Testing for commission calculation)


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\n");
scanf("%d", &locks);
14 while(locks!=-1) {
15 printf("enter the number of stocks and barrels\n");
scanf("%d%d",&stocks,&barrels);
16 tlocks=tlocks+locks;
17 tstocks=tstocks+stocks;
18 tbarrels=btarrels+barrels;
19 printf("\nenter the number of locks and to exit the loop enter -1 for locks\n");
scanf("%d",&locks);
20 }
21 printf("\ntotal locks = %d\”,tlocks);
22 printf(“total stocks =%d\n”,tstocks);
23 printf(“total barrels =%d\n",tbarrels);

24 lsales = lprice*tlocks;
25 ssales=sprice*tstocks;
26 bsales=bprice*tbarrels;
27 sales=lsales+ssales+bsales;
28 printf("\nthe total sales=%f\n",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);
}
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("the commission is=%f\n",comm);
41 return 0;
42 }

DEPARTMENT OF ISE 37
SOFTWARE TESTING LABORATORY

Define /Use nodes for variables in the commission problem:

Variable name Defined at node Used at Node


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

Selected Define/Use Paths:

Test Description variables path Du paths Definitio Comm


case (Beginning, n clear ? ents
id End nodes)

1 Check for lock (7 , 24) <7-8-9-10-11-12- Yes


price variable 13-14-15-16-17-
DEF(lprice,7) 18-19-20-21-22-
and 23-24>
USE(lprice,24
)
2 Check for Stock price (8,25) <8-9-10-11-12- Yes
variable DEF(sprice,8) and 13-14-15-16-17-
USE(sprice,25) 1819-20-21-22-
23-24-25>
3 Check for barrel price (9,26) <9-10-11-12-13- Yes
variable DEF(bprice,9)and 14-15-16-17-
USE(bprice,26) 1819-20-21-22-
23-24-25-26>
4 Check for total locks (10 ,16) <10-11-12-13-14- Yes
variable DEF((tlocks,10) 15-16>
and DEF(tlocks,16)) and
3 usage (10 , 21) <10-11-12-13-14- No
node(USE(tlocks,16), 15-16-17-18-19-
20-14-21>

DEPARTMENT OF ISE 38
SOFTWARE TESTING LABORATORY

USE(tlocks,21),USE(tlocks (10 , 24) <10-11-12-13-14- No


,24) 15-16-17-18-
1920-14-21-22-
23-24>
(16 , 16) <16-16> Yes
(16 , 21) <16-17-18-19-14- No
21>
(16 , 24) <16-17-18-19-20- No
14-21-22-23-24>
5 Check for total stocks (11 , 17) <11-12-13-14-15- Yes
variable DEF((tstocks,11) 16-17>
and DEF(tstocks,17)) and 3
(11 , 22) <11-12-13-14-15- No
usage
16-17-18-19-20-
node(USE(tstocks,17),USE
21-14-21>
(tstocks,22),USE(tstocks,2
5) (11, 25) <11-12-13-14-15- No
16-17-18-19-20-
21-14-21-23-24-
25>
(17 , 17) <17-17> Yes
(17 , 22) <17-18-19-20-14- No
21-22>
(17 , 25) <17-18-19-20-14- No
21-22-23-24-25>
6 check for locks variable ( (13 , 14) <13-14> Yes Begin
DEF(locks,13) the
,DEF(locks,19) and loop
USE(locks,14),USE(locks,
( 13 , 16) <13-14-15-16> Yes
16)
(19 , 14) <19-20-14> Yes
(19 , 16) <19-20-14-15- Yes Repeat
16> the
loop

7 Check for stocks variable (15 , 17) <15-16-17> Yes


(DEF(stocks,15) and
USE(stocks,17)
8 Check for sales DEF(sales, (27 ,28) <27-28> Yes
27) and USE(Sales, 28),
USE(Sales , 29), (27 , 29) <27-28-29> Yes
USE(Sales,33) , USE(Sales (27 , 33) <27-28-29-30-31- Yes
, 34) , USE(Sales,37) , 32-33>
USE(Sales , 39)
(27 , 34) <27-28-29-34> Yes
(27 , 37) <27-28-29-34-35- Yes
36-37>

DEPARTMENT OF ISE 39
SOFTWARE TESTING LABORATORY

(27 , 39) <27-28-29-34-38- Yes


39>
9 Check for Commission ((31,32,33),42) <31-32-33-42> Yes
variable DEF(comm,
31,32,33) , ((36 , 37) , 42) <36-37-42> Yes Yes
DEF(comm,34,35) and (39 , 42 ) <39 - 42> Yes Yes
DEF(comm,39) and
USE(comm,42)

EXECUTION:
Execute the program against the designed test cases and complete the table.

RESULT:

Thus, the program for solving the commission problem is designed, developed and programmed.
Also derived the test cases and executed the test cases using data flow testing and the results are
verified.

DEPARTMENT OF ISE 40
SOFTWARE TESTING LABORATORY

//Program 10: binary search algorithm using basis path testing


/*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.*/
REQUIREMENTS:
R1: The system should accept ‘n’ number of elements and key element that is to be searched
among ‘n’ elements..
R2: Check if the key element is present in the array and display the position if present otherwise
print unsuccessful search.

DESIGN:
We use integer array as a data structure to store ‘n’ number of elements. Iterative
programming technique is used.
ALGORITHM:

Step 1: Input value of ‘n’. Enter ‘n’ integer numbers in array int mid;
Step 2: Initialize low = 0, high = n -1
Step 3: until ( low <= high ) do
mid = (low + high) / 2
if ( a[mid] == key )
then do Step 5
else if ( a[mid] > key ) then do
high = mid - 1
else
low = mid + 1
Step 4: Print unsuccessful search do step 6.
Step 5: Print Successful search. Element found at position mid+1.
Step 6: Stop.

DEPARTMENT OF ISE 41
SOFTWARE TESTING LABORATORY

PROGRAM CODE:
1. #include<stdio.h>
2. int main()
3. {
4. int a[20],n,low,high,mid,key,i,flag=0;
5. printf("Enter the value of n:\n");
scanf("%d",&n);
6. if(n>0)
7. {
8. printf("Enter %d elements in ASCENDING order\n",n);
9. for(i=0;i<n;i++)
10. {
scanf("%d",&a[i]);
11. }
12. printf("Enter the key element to be searched\n");
scanf("%d",&key);
13. low=0;
14. high=n-1;
15. while(low<=high)
16. {
17. mid=(low+high)/2;
18. if(a[mid]==key)
19. {
20. flag=1;
21. break;
22. }
23. else if(a[mid]<key)
24. low=mid+1;
25. else
26. high=mid-1;
27. }
28. if(flag==1)
29. printf("Successful search\n Element found at Location%d\n",mid+1);
30. else
31. printf("Key Element not found\n");
32. }
33. else
34. printf("Wrong input");
35. }

DEPARTMENT OF ISE 42
SOFTWARE TESTING LABORATORY

TESTING:
Technique Used: Basis Path Testing
Basis path testing is a form of Structural testing (White Box testing).
The method devised by McCabe to carry out basis path testing has four steps.
These are:
1. Compute the program graph.
2. Calculate the cyclomatic complexity.
3. Select a basis set of paths.
4. Generate test cases for each of these paths.

Program graph:

DEPARTMENT OF ISE 43
SOFTWARE TESTING LABORATORY

Using the program graph we derive (Decision-to-Decision) DD path graph for binary search program:

Program Graph DD – Path


Nodes Name

The cyclomatic complexity of a connected graph is provided by the formula


V(G) = e – n + 2p.
The number of edges is represented by e, the number of nodes by n and the number of connected
regions by p.
If we apply this formula to the graph given below, the number of linearly independent circuits is:
Number of edges =
Number of nodes =
Number of connected regions =
V(G) =
According to cyclomatic complexity feasible basis path are:

DEPARTMENT OF ISE 44
SOFTWARE TESTING LABORATORY

DERIVING TEST CASES USING BASIS PATH TESTING:


The last step is to devise test cases for the basis paths.
TEST CASES:
TC Test Case Value array Expected Actual
ID Description of ‘n‘ elements key Output Output Status
Testing for
1 requirement 1 Path P1

Testing for
2 requirement 2 Path P2
Testing for
3 requirement 2 Path P3

EXECUTION:
Execute the program against the designed test cases and complete the table.

RESULT:

Thus, the program for solving the binary search problem is designed, developed and programmed. Also
derived the test cases and executed the test cases using basis path testing method and the results are verified.

DEPARTMENT OF ISE 45
SOFTWARE TESTING LABORATORY

//Program 10: Quicksort algorithm using basis 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.*/
REQUIREMENTS:

R1: The system should accept ‘n’ number of elements.


R2: Identify the pivot element then sort the n number of elements.

DESIGN:
We use integer array as a data structure to store ‘n’ number of elements. Iterative programming
technique is used.

PROGRAM CODE:

1. #include<stdio.h>
2. void quicksort(int [],int,int);
3. int main()
4. {
5. int num[50],i,j,n;
6. printf(“Enter number of elements:”);
7. scanf(“%d”,&n);
8. printf(“\nEnter the elements:”);
9. for(i=0;i<n;i++)
10. scanf(“%d”,&num[i]);
11. quicksort(num,0,n-1);
12. printf(“\nArray after sorting:”);
13. for(i=0;i<n;i++)
14. printf(“%d”,num[i]);
15. printf(“\n”);
16. }
17. void quicksort(int num[],int first,int last)
18. {
19. int i,j,pivot,temp;
20. if(first<last)
21. {
22. pivot=first;
23. i=first;
24. j=last;
25. while(i<j)
26. {
27. while(num[i]<=num[pivot]&&i<last)
28. i++;
29. while(num[j]>num[pivot])

DEPARTMENT OF ISE 46
SOFTWARE TESTING LABORATORY

30. j--;
31. if(i<j)
32. {
33. temp=num[i];
34. num[i]=-num[j];
35. num[j]=temp;
36. }
37. }
38. temp=num[pivot];
39. num[pivot]=num[j];
40. num[j]=temp;
41. quicksort(num,first,j-1);
42. quicksort(num,j+1,last);
43. }
44. }

TESTING:
Technique Used: Basis Path Testing
Basis path testing is a form of Structural testing (White Box testing).
The method devised by McCabe to carry out basis path testing has four steps.
These are:
1. Compute the program graph.
2. Calculate the cyclomatic complexity.
3. Select a basis set of paths.
4. Generate test cases for each of these paths.

Program graph:

DEPARTMENT OF ISE 47
SOFTWARE TESTING LABORATORY

Using the program graph we derive (Decision-to-Decision) DD path graph for binary search program:

Program Graph DD – Path


Nodes Name

The cyclomatic complexity of a connected graph is provided by the formula


V(G) = e – n + 2p.
The number of edges is represented by e, the number of nodes by n and the number of connected
regions by p.
If we apply this formula to the graph given below, the number of linearly independent circuits is:
Number of edges =
Number of nodes =
Number of connected regions =
V(G) =
According to cyclomatic complexity feasible basis path are:

DEPARTMENT OF ISE 48
SOFTWARE TESTING LABORATORY

DERIVING TEST CASES USING BASIS PATH TESTING:


The last step is to devise test cases for the basis paths.
TEST CASES:

Expected output
Test Case Array Actual
TC ID Value of i Status
Description elements Array output

1 Testing for
path P1
2 Testing for
path P2
3 Testing for
path P3

EXECUTION:
Execute the program against the designed test cases and complete the table.

RESULT:

Thus, the program for solving the quicksort algorithm is designed, developed and programmed. Also
derived the test cases and executed the test cases using basis path testing method and the results are
verified.

DEPARTMENT OF ISE 49
SOFTWARE TESTING LABORATORY

//Program 12: Absolute letter grading procedure using basis 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.*/

REQUIREMENTS:
R1: The system should accept marks of 6 subjects, each marks in the range 1 to 100.
i.e., for example, 1<=marks<=100
1<=kannada<=100
1<=maths<=100 etc.
R2: If R1 is satisfied ,comp average of marks scored and percentage of the same and depending on
percentage display the grade.

DESIGN:
We can use the total percentage of marks to grade the student marks.
<35 && 0> of percentage make it as FAIL
avmar<=40 && avmar >35 make it as Grade C
avmar<=50 && avmar>40 make it as Grade C+
avmar<=60 && avmar>50 make it as Grade B
avmar<=70 && avmar>60 make it as Grade B+
avmar<=80 && avmar>70 make it as Grade A
avmar<=100 && avmar>80 make it as Grade A+

PROGRAM CODE
1. #include<stdio.h>
2. main()
3. {
4. float kan,eng,hindi,maths,science, sst,avmar;
5. printf("Letter Grading\n");
6. printf("SSLC Marks Grading\n");
7. printf("Enter the marks for Kannada:");
8. scanf("%f",&kan);
9. printf("enter the marks for English:");
10. scanf("%f",&eng);
11. printf("enter the marks for Hindi:");
12. scanf("%f",&hindi);
13. printf("enter the marks for Maths");
14. scanf("%f",&maths);
15. printf("enter the marks for Science:");
16. scanf("%f",&science);

DEPARTMENT OF ISE 50
SOFTWARE TESTING LABORATORY

17. printf("enter the marks for Social Science:");


18. scanf("%f",&sst);
19. avmar=(kan+eng+hindi+maths+science+sst)/6.25;
20. printf("the average marks are=%f\n",avmar);
21. if((avmar<35)&&(avmar>0))
22. printf("fail");
23. else if((avmar<=40)&&(avmar>35))
24. printf("Grade C");
25. else if((avmar<=50)&&(avmar>40))
26. printf("Grade C+");
27. else if((avmar<=60)&&(avmar>50))
28. printf("Grade B");
29. else if((avmar<=70)&&(avmar>60))
30. printf("Grade B+");
31. else if((avmar<=80)&&(avmar>70))
32. printf("Grade A");
33. else if((avmar<=100)&&(avmar>80))
34. printf("Grade A+");
35. }

TESTING:

PROGRAM GRAPH:

DEPARTMENT OF ISE 51
SOFTWARE TESTING LABORATORY

Using the program graph we derive (Decision-to-Decision) DD path graph for absolute
letter grading procedure:

Program Graph DD – Path


Nodes Name

The cyclomatic complexity of a connected graph is provided by the formula


V(G) = e – n + 2p.
The number of edges is represented by e, the number of nodes by n and the number of
connected regions by p.
If we apply this formula to the graph given below, the number of linearly independent
circuits is:
Number of edges =
Number of nodes =
Number of connected regions =
V(G) =
According to cyclomatic complexity feasible basis path are:

DEPARTMENT OF ISE 52
SOFTWARE TESTING LABORATORY

DERIVING TEST CASES USING BASIS PATH TESTING:


The last step is to devise test cases for the basis paths.
TEST CASES:

Expected Actual
TC ID Test Description Input Status
Outpu Output
1 Testing for path P1 t
2 Testing for path P2
3 Testing for path P3

EXECUTION:
Execute the program against the designed test cases and complete the table.

RESULT:

Thus, the program for implementing absolute letter grading procedure is designed, developed
and programmed. Also derived the test cases and executed the test cases using basis path
testing method and the results are verified.

DEPARTMENT OF ISE 53

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy