Sanya Gupta - F-10 (ST LAB FILE)
Sanya Gupta - F-10 (ST LAB FILE)
S.NO AIM
1 Consider a program for the determination of nature of roots of a quadratic equation. Its input is a triple of
positive integers a, b, c and values may be from interval [0,100]. The program output may have one of the
following words:
Not a Quadratic Equation
Real Roots
Imaginary Roots
Equal Roots
Design Boundary value Test Cases.
2 Write a program in C/C++ to find the area of a Triangle, Rectangle, Square and a Circle. Perform
Equivalence Testing on it.
3 Write a Program in C/C++ to calculate the value of ab. Perform Decision Table Based Testing on it
4 Write a program in C/C++ to compute previous date. We are given the present date as input. Perform
Decision Table Based Testing on it
5 Write a program in C/C++ to read three sides of a triangle and to check whether the triangle is Isosceles,
Equilateral or Scalene
6 Write a program in C\C++ to compute total salary of an employee given his/her basic salary. The slab is
given below:
HRA = 30 % of basic
DA=80% of basic
MA = Rs. 100/-
TA = Rs. 800/-
I.tax = Rs. 700/-
PF = Rs. 780/- Also find out the path graph and cyclomatic complexity.
7 Draw the DD Path graph for the Practical No 6 (Write a program in C\C++ to compute total salary of an
employee given his/her basic salary. The slab is given below:
HRA = 30 % of basic
DA=80% of basic
MA = Rs. 100/-
TA = Rs. 800/-
I.tax = Rs. 700/-
PF = Rs. 780/-)
8 Write a program to read the marks of 10 students in five subjects. Find the average and allot the grades.
Draw its graph matrix and find its V(G)
9 Write a program to read the marks of 10 students in five subjects. Find the average and allot the grades.
Apply data flow testing on the above program.
Program –
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a, b, c, d;
cout<<"The Quadratic Equation is of the type a(x^2)+bx+c = 0 "<<endl;
cout<<"Enter the value of 'a'"<<endl;
cin>>a;
cout<<"Enter the value of 'b'"<<endl;
cin>>b;
cout<<"Enter the value of 'c'"<<endl;
cin>>c;
d = (b*b) - 4*a*c;
if((a<0) || (b<0) || (c<0) || (a>100) || (b>100) || (c>100))
cout<<"Invalid input"<<endl;
else if(a == 0)
cout<<"Not a Quadratic Equation"<<endl;
else if(d == 0)
cout<<"Roots are Equal"<<endl;
else if(d < 0)
cout<<"Imaginary Roots"<<endl;
else
cout<<"Real Roots"<<endl;
getch();
}
OUTPUT:
Practical No – 2
Objective – Write a program in C/C++ to find the area of a Triangle, Rectangle, Square and a Circle. Perform
Equivalence Testing on it.
Theory:
In this method the input domain data is divided into different equivalence data classes. This method is typically used to
reduce the total number of test cases to a finite set of testable test cases, still covering maximum requirements. In
short it is the process of taking all possible test cases and placing them into classes. One test value is picked from each
class while testing. Test cases with other values from any class should give you the same result. We have selected one
representative from every input class to design our test cases. Test case values are selected in such a way that largest
number of attributes of equivalence class can be exercised. Equivalence partitioning uses fewest test cases to cover
maximum requirements.
Test cases: In Equivalence class testing, we find two types of equivalence classes; input domain and output domain;
Input domain is formed from one valid sequence and two invalid sequences. The output domain is obtained from
different types of output of a problem.
For Triangle:
Input domain:
I1 = {h : h<=0}
I2 = {h : H>200}
I3 = {h : 1<=h<=200}
I4 = {b : b<=0}
I5 = {b : b>200}
I6 = {b : 1<=b<=200}
Test cases:
Test case ID h b Expected output
1. 0 100 Invalid input
2. 100 100 5000
3. 201 100 Invalid input
4. 100 0 Invalid input
5. 100 100 5000
6. 100 201 Invalid input
Output domain:
Input domain:
I1={s : s<=0}
I2={s : s>200}
I3={s : 1<=s<=200}
Test cases:
Test case ID S Expected output
1. 0 Invalid input
2. 100 10000
3. 201 Invalid input
Output domain:
For Rectangle:
Input domain:
I1 = { l : l <=0}
I2 = { l : l>200}
I3 = { I : 1<=l <=200}
I4 = { b : b<=0}
I5 = { b : b>200}
I6 = { b : 1<=b<=200}
Test cases:
Test case ID l B Expected output
1. 0 100 Invalid input
2. 100 100 10000
3. 201 100 Invalid input
4. 100 0 Invalid input
5. 100 100 10000
6. 100 201 Invalid input
Output domain:
For Circle:
Input domain:
I1 = {r: r<=0}
I2 = {r : r>200}
I3 = { r: 1<=r<=200}
Test cases:
Test Cases r Expected output
1. 0 Invalid input
2. 100 31400
3. 201 Invalid input
Output domain:
Program -
#include<iostream.h>
#include<conio.h>
#include<process.h>
void main()
{
clrscr();
int ch;
char c;
float b,h,a;
1: cout<<"Enter your choice";
cout<<"\n 1. Triangle";
cout<<"\n 2. Square";
cout<<"\n 3. Rectangle";
cout<<"\n 4. Circle";
cout<<"\n 5. Exit\n";
cin>>ch;
switch(ch)
{
case 1: b: cout<<"\Enter the base of the triangle (1-200)";
cin>>b;
if((b<=0)||(b>200))
{
cout<<"\n Invalid entry for base \n";
goto b;
}
h: cout<<"\n Enter the height of the triangle (1-200)";
cin>>h;
if((h<=0)||(h>200))
{
cout<<"\n Invalid height\n Enter the valid height (1-200)";
goto h;
}
a= 0.5*b*h;
cout<<"\n The area is : "<<a;
cout<<"\n Want to enter more?(y/n)";
cin>>c;
if((c=='y')||(c=='y'))
goto 1;
break;
case 2 : s: cout<<"\n Enter the side of the squre (1-200)";
cin>>b;
if((b<=0)||(b>200))
{
cout<<"\n Invalid entry for base \n";
goto s;
}
a=b*b;
cout<<"\n The area is :"<<a;
cout<<"\n Want to enter more?(y/n)";
cin>>c;
if((c=='y')||(c=='y'))
goto 1;
break;
case 3: d: cout<<"\n Enter the Base of the rectangle (1-200)";
cin>>b;
if((b<=0)||(b>200))
{
cout<<"\n Invalid entry for base \n";
goto d;
}
p: cout<<"\n Enter the height of the rectangle (1-200)";
cin>>h;
if((h<=0)||(h>200))
{
cout<<"\n Invalid Height \n Enter the height (1-200)";
goto p;
}
a=b*h;
cout<<"\n The area is :"<<a;
cout<<"\n Want to enter more?(y/n)";
cin>>c;
if((c=='y')||(c=='y'))
goto 1;
break;
case 4 : t: cout<<"\n Enter the radius of the circle (1-200)";
cin>>b;
if((b<=0)||(b>200))
{
cout<<"\n Invalid entry for radius \n";
goto t;
}
a=3.14*b*b;
cout<<"\n The area is :"<<a;
cout<<"\n Want to enter more?(y/n)";
cin>>c;
if((c=='y')||(c=='y'))
goto 1;
break;
case 5 : exit(0);
break;
default :cout<<"\n Wrong Choice:";
goto 1;
}
getch();
}
Output
Practical No – 3
Objective – Write a Program in C/C++ to calculate the value of ab. Perform Decision Table Based Testing on it.
Theory - A decision table is a good way to deal with different combination inputs with their associated outputs and
also called cause-effect table. Reason to call cause-effect table is an associated logical diagramming technique called
’cause-effect graphing that is basically use to derive the decision table. Decision table testing is black box test design
technique to determine the test scenarios for complex business logic. We can apply Equivalence Partitioning and
Boundary Value Analysis techniques to only specific conditions or inputs. Although, if we have dissimilar inputs that
result in different actions being taken or secondly, we have a business rule to test that there are different combination
of inputs which result in different actions. We use decision table to test these kinds of rules or logic.Decision tables
are very much helpful in test design technique – it helps testers to search the effects of combinations of different inputs
and other software states that must correctly implement business rules. Also, provides a regular way of stating complex
business rules, that’s helpful for developers as well as for testers. Testing combinations can be a challenge, as the
number of combinations can often be huge. It assists in development process with developer to do a better job. Testing
with all combination might be unrealistic or unfeasible. We have to be happy with testing just a small subset of
combinations but making the option of which combinations to test and which to leave out is also significant. If you do
not have a efficient way of selecting combinations, an arbitrary subset will be used and this may well result in an
ineffective test effort. A decision table is basically an outstanding technique used in both testing and requirements
management. It is a structured exercise to prepare requirements when dealing with complex business rules. Also, used
in model complicated logic.
Test cases: Decision Table Based testing is useful for describing situations in which a number of combinations of
actions are taken for different conditions. There are four parts of a decision table; condition stub, action stub, condition
entries and action entries.
Conditions are:
C1 : a = 0, b = 0
C2 : a = -ve, b = +ve
C3 : a = +ve, b = -ve
C4 : a = -ve, b = -ve
C5 : a = +ve, b = +ve
C6 : a = 0,b = integer
C7 : b = 0, a = integer
C8 : a = -ve, b= -ve odd
Actions:
A1 : Domain error
A2 : Negative output
A3 : output =1
A4 : positive output
A5 : output = 0
Condition R1 R2 R3 R4 R5 R6 R7 R8
C1 T - - - - - - -
C2 - T - - - - - -
C3 -- - - T - - - -
C4 - - -- - T - - -
C5 - - - - - T - -
C6 - - - - - - T -
C7 - - - - - - - T
C8 - - T - - - - -
Action
A1 X
A2 X X
A3 X
A4 X X X
A5 X
Program –
#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{
clrscr();
int a,b;
float c;
char ch;
1: cout<<"To Calculate 'a to the power b' \n";
cout<<"Enter the value of 'a' \n";
cin>>a;
cout<<"Enter the value of 'b' \n";
cin>>b;
c=pow(a,b);
cout<<endl<<c;
cout<<"\n Want to enter again? (y/n)";
cin>>ch;
if((ch=='y')||(ch=='y'))
goto 1;
getch();
}
Output
Practical No – 4
Objective – Write a program in C/C++ to compute previous date. We are given the present date as input.
Perform Decision Table Based Testing on it.
Theory:
A decision table is a good way to deal with different combination inputs with their associated outputs and also called
cause-effect table. Reason to call cause-effect table is an associated logical diagramming technique called ’cause-effect
graphing that is basically use to derive the decision table. Decision table testing is black box test design technique to
determine the test scenarios for complex business logic. We can apply Equivalence Partitioning and Boundary Value
Analysis techniques to only specific conditions or inputs. Although, if we have dissimilar inputs that result in different
actions being taken or secondly, we have a business rule to test that there are different combination of inputs which
result in different actions. We use decision table to test these kinds of rules or logic.Decision tables are very much
helpful in test design technique – it helps testers to search the effects of combinations of different inputs and other
software states that must correctly implement business rules. Also, provides a regular way of stating complex business
rules, that’s helpful for developers as well as for testers. Testing combinations can be a challenge, as the number of
combinations can often be huge. It assists in development process with developer to do a better job. Testing with all
combination might be unrealistic or unfeasible. We have to be happy with testing just a small subset of combinations
but making the option of which combinations to test and which to leave out is also significant. If you do not have a
efficient way of selecting combinations, an arbitrary subset will be used and this may well result in an ineffective test
effort. A decision table is basically an outstanding technique used in both testing and requirements management. It is a
structured exercise to prepare requirements when dealing with complex business rules. Also, used in model
complicated logic.
Test cases:
Program –
#include<stdio.h>
#include<conio.h>
int main()
{
int day, month, year, flag=0;
printf("Enter the day value:");
scanf("%d",&day);
printf("Enter the month value:");
scanf("%d",&month);
printf("Enter the year value:");
scanf("%d",&year);
if(year>=1900 && year<=2025)
{
if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)
{
if(day>=1 && day<=31)
{
flag=1;
}
else
{
flag=0;
}
}
else if(month==2)
{
int rval=0;
if(year%4==0)
{
rval=1;
if((year%100)==0 && (year%400)!=0)
{
rval=0;
}
}
if(rval==&&(day>=1 &&day <=29))
{
flag=1;
}
else if (day>=1 &&day <=28)
{
flag=1;
}
else
{
flag=0;
}
}
if(flag)
{
if(day==1)
{
if(month==1)
{
year--;
day=31;
month=12;
}
else if(month==3)
{
int rval=0;
if(year%4==0)
{
rval=1;
if((year%100)==0 &&(year%400)!=0)
{
rval=0;
}
}
if(rval==1)
{
day=29;
month--;
}
else
{
day=28;
month--;
}
}
else if(month==2||month==4||month==6||month==9||month==11)
{
day=31;
month--;
}
else
{
day=30;
month--;
}
}
else
{
day--;
}
printf(" The next data is : %d-%d-%d",day,month,year);
}
else
{
printf(" The entered data is invalid: %d-%d-%d",day,month,year);
}
getch();
return 1;
}
}
Output:
Practical No – 5
Objective – Write a program in C/C++ to read three sides of a triangle and to check whether the triangle is
Isosceles, Equilateral or Scalene.
Perform Path Testing on it and deduce:
a) Flow Graph
b) DD Path Graph
c) Independent Graph
d) Cyclomatic Complexity
Theory:
Path testing is an approach to testing where you ensure that every path through a program has been executed at least
once. You normally use a dynamic analyzer tool or test coverage analyser to check that all of the code in a program
has been executed. However, testing all paths does not mean that you will find all bugs in a program. Many bugs arise
because programmers have forgotten to include some processing in their code, so there are no paths to execute. Some
bugs are also related to the order in which code segments are executed. For example, if segments a, b and c are executed
<a, b, c>, then the program may work properly. However, if they are executed <a, c, b> then an error may arise. It is
practically impossible to test all orders of processing as well as all program paths.
1. Flow Graph:It shows that how the control and data is flow from one node to another node. The flow graph
for the following program is given below:
2. DD path graph:
Flow Graph Nodes DD Path Graph Corr. Nodes Remarks
1 to 9 A Sequential
10 B Decision
11 C Decision
12,13 D Sequential
14 E Two edges are joined here
15,16,17 F Sequential nodes
18 G Decision nodes plus joining of two edges
19 H Decision nodes
20,21 I Sequential nodes
22 J Decision nodes
23,24 K Sequential nodes
25,26,27 L Sequential nodes
28 M Three edges combined here
29 N Decision nodes
30,31 O Sequential nodes
32,33,34 P Sequential nodes
35 Q Three edges combined here
36,37 R Sequential nodes with exit node
3. Independent path: It is a path in the flow graph that has at least one edge that has not been traversed before
in another path.
1. ABFGNPQR
2. ABFGNOQR
3. ABCEGNPQR
4. ABCDGINOQR
5. ABFGHIMQR
6. ABFGHJKMQR
7. ABFGHJLMQR
4. Cyclomatic complexity: To calculate the cyclomatic complexity we calculate the following formula:
V(G) = e – n + 2P
Where V(G): Cyclomatic Metric of Graph G with ‘n’ vertices, ‘e’ edges and P connected components.
Program –
#include<stdio.h>
#include<conio.h>
1 int main()
2{
3 int a,b,c,validinput=0;
4 printf("Enter the side ‘a’ value");
5 scanf("%d",&a);
6 printf("Enter the side ‘b’ value");
7 scanf("%d",&b);
8 printf("Enter the side ‘c’ value");
9 scanf("%d",&c);
10 if((a>0)&&(a<=100)&&(b>0)&&(b<=100)&&(c>0)&&(c<=100)){
11 if(((a+b)>c)&&((c+a)>b)&&((b+c)>a)){
12 validinput=1;
13 }
14 }
15 else{
16 validinput=-1;
17 }
18 if(validinput==1){
19 if((a==b)&&(b==c)){
20 printf("The triangle is equilateral");
21 }
22 else if((a==b)||(b==c)||(c==a)){
23 printf("The triangle is isosceles");
24 }
25 else{
26 printf("The triangle is scalene");
27 }
28 }
29 else if(validinput==0){
30 printf("The value do not constitute the triangle");
31 }
32 else{
33 printf("The input belongs to invalid range");
34 }
35 getch();
36 return 1;
37 }
Output
Practical No – 6
Objective - Write a program in C\C++ to compute total salary of an employee given his/her basic salary. The slab is
given below:
HRA = 30 % of basic
DA=80% of basic
MA = Rs. 100/-
TA = Rs. 800/-
I.tax = Rs. 700/-
PF = Rs. 780/- Also find out the path graph and cyclomatic complexity.
Theory:
Cyclomatic complexity is a source code complexity measurement that is being correlated to a number of coding errors.
It is calculated by developing a Control Flow Graph of the code that measures the number of linearly-independent
paths through a program module.
Lower the Program's cyclomatic complexity, lower the risk to modify and easier to understand. It can be
represented using the below formula. Cyclomatic Complexity or the Structural Complexity of the program
can be deduced by using following formulae :
V(G) = e – n + 2P
Where V(G): Cyclomatic Metric of Graph G with ‘n’ vertices, ‘e’ edges and P connected components.
Path Graph:
8
9
1
0
1
1
1
2
1
3
1
4
1
5
1
6
1
7
Program –
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
1 void main()
2 {
3 cout<<"Enter the basic salary of the employee";
4 float bs;
5 cin>>bs;
6 int hra,da,ma=100,itax=700, pf=780,ta=800;
7 hra=0.3*bs;
8 da=0.8*bs;
9 cout<<"\nHouse allowance: rs."<<hra;
10 cout<<"\nDarkness allowance: rs."<<da;
11 cout<<"\nmedical allowance: rs."<<ma;
12 cout<<"\ntravel allowance: rs."<<ta;
13 cout<<"\nIncome tax rs."<<itax;
14 cout<<"\nprovidend fund: rs."<<pf;
15 float netsal =(bs+hra+da+ta-itax-pf);
16 cout<<"The net selary of the employee is : "<<netsal;
17 }
Output:
Practical No – 7
Objective – Draw the DD Path graph for the Practical No 6 (Write a program in C\C++ to compute total salary of an
employee given his/her basic salary. The slab is given below:
HRA = 30 % of basic
DA=80% of basic
MA = Rs. 100/-
TA = Rs. 800/-
I.tax = Rs. 700/-
PF = Rs. 780/-)
Theory - A decision-to-decision path (DD-Path) is a path chain in a program graph such that
• Initial and terminal nodes are distinct
• Every interior node has indeg =1 and outdeg = 1
• The initial node is 2-connected to every other node in the path
• No instances of 1- or 3-connected nodes occur.
Path Graph:
7 9
8 1
0
1
1
1
2
1
3
1
4
1
5
1
6
1
7
1
8
1
9
2
0
2
1
2
Program – 2
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
1 void main()
2 {
3 cout<<"Enter the basic salary of the employee";
4 float bs;
5 cin>>bs;
6 if(bs<=0){
7 cout<<”Invalid Salary”<<endl;
8 }
9 else{
10 int hra,da,ma=100,itax=700, pf=780,ta=800;
11 hra=0.3*bs;
12 da=0.8*bs;
13 cout<<"\nHouse allowance: rs."<<hra;
14 cout<<"\nDarkness allowance: rs."<<da;
15 cout<<"\nmedical allowance: rs."<<ma;
16 cout<<"\ntravel allowance: rs."<<ta;
17 cout<<"\nIncome tax rs."<<itax;
18 cout<<"\nprovidend fund: rs."<<pf;
19 float netsal = =(bs+hra+da+ta-itax-pf);
20 cout<<"The net selary of the employee is : "<<netsal;
21 }
22 }
Output
Practical No – 8
Objective - Write a program to read the marks of 10 students in five subjects. Find the average and allot the grades.
Draw its graph matrix and find its V(G).
Theory:
Cyclomatic complexity is a source code complexity measurement that is being correlated to a number of coding errors.
It is calculated by developing a Control Flow Graph of the code that measures the number of linearly-independent
paths through a program module.
Lower the Program's cyclomatic complexity, lower the risk to modify and easier to understand. It can be represented
using the below formula. Cyclomatic Complexity or the Structural Complexity of the program can be deduced by
using following formulae:
V(G) = e – n + 2P
Where V(G): Cyclomatic Metric of Graph G with ‘n’ vertices, ‘e’ edges and P connected components.
Program –
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
#include<string.h>
struct student
{
char sname[10];
float marks[5];
float total,avg;
char grade;
}s[10];
void main()
{ 1
int i;
for(i=1;i<10;i++) 2
{
cout<<"\n Enter the name of the student"<<i<<"\t"; 3
gets(s[i].sname); 4
for(int j=0;j<5;j++) 5
{
cout<<"\n Enter the marks in subject"<<j<<"\t"; 6
cin>>s[i].marks[j]; 7
}
for(j=0;j<5;j++) 8
{
s[i].total=s[i].total+s[i].marks[j]; 9
}
s[i].avg=s[i].total/5; 10
cout<<"\n The average of student"<<i<<"is:"<<s[i].avg; 11
if(s[i].avg>90.0) 12
s[i].grade='O'; 13
else if((s[i].avg<90.0)&&(s[i].avg>=85.0)) 14
s[i].grade='A'; 15
else if((s[i].avg<85.0)&&(s[i].avg>=80.0)) 16
s[i].grade='B'; 17
else if((s[i].avg<80.0)&&(s[i].avg>=70.0)) 18
s[i].grade='C'; 19
else 20
s[i].grade='D'; 21
cout<<"\n The grade of student" <<i<<"\t"<<s[i].grade; 22
} 23
} 24
Graph matrix:
A B C D E F G H I J K L
A - 1 - - -- - - - - - - 1
B - - 1 1 - - - - - - - -
C - - - - - - - - - - - 1
D - -- - -- 1 1 - - - - - -
E - - - - - - - - - - -- 1
F - - - - - - - -- 1 - - -
G - - - - - - - - - - - -
H - - - - - - - - - - - -
I - -- - - - - - - - 1 1 -
J - - - - - - - - - - - 1
K -- - - - - - - - - - -- 1
L - - - - - - - - - - - -
OUTPUT:
Practical No – 9
Objective - Write a program to read the marks of 10 students in five subjects. Find the average and allot the grades.
Apply data flow testing on the above program.
Theory:
Data flow testing is a family of test strategies based on selecting paths through the program's control flow in order to
explore sequences of events related to the status of variables or data objects. Dataflow Testing focuses on the points
at which variables receive values and the points at which these values are used.
Program –
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
#include<string.h>
struct student
{
char sname[10];
float marks[5];
float total,avg;
char grade;
}s[10];
void main() 1
{
int i;
for(i=1;i<10;i++) 2
{
cout<<"\n Enter the name of the student"<<i<<"\t"; 3
gets(s[i].sname); 4
for(int j=0;j<5;j++) 5
{
cout<<"\n Enter the marks in subject"<<j<<"\t"; 6
cin>>s[i].marks[j]; 7
}
for(j=0;j<5;j++) 8
{
s[i].total=s[i].total+s[i].marks[j]; 9
}
s[i].avg=s[i].total/5; 10
cout<<"\n The average of student"<<i<<"is:"<<s[i].avg; 11
if(s[i].avg>90.0) 12
s[i].grade='O'; 13
else if((s[i].avg<90.0)&&(s[i].avg>=85.0)) 14
s[i].grade='A'; 15
else if((s[i].avg<85.0)&&(s[i].avg>=80.0)) 16
s[i].grade='B'; 17
else if((s[i].avg<80.0)&&(s[i].avg>=70.0)) 18
s[i].grade='C'; 19
else 20
s[i].grade='D'; 21
cout<<"\n The grade of student" <<i<<"\t"<<s[i].grade; 22
} 23
} 24
The du-paths are identified and are named by their beginning and end nodes using the variable as follows:
What is Selenium?
Selenium is a free (open source) automated testing suite for web applications across
differentbrowsers and platforms. It is quite similar to HP Quick Test Pro (QTP)
only that Selenium focuses on automating web-based applications.
Selenium is not just a single tool but a suite of software's, each catering to different
testing needsof an organization. It has four components.
WebDriver
Selenium Grid