Software Lab
Software Lab
Deemed to be University
(Declared under Distinct Category by Ministry of Education, Government of India)
NAAC ACCREDITED WITH A++ GRADE
A
Lab Report
On
SOFTWARE ENGINEERING (2230423)
In fulfilment of the requirement for the award of the degree
SUBMITTED BY
Vaibhav Shivhare
(0901IO221074)
IV Semester, 2nd Year
Internet of Things (IoT)
SUBMITTED TO
Ms.SURBHI GUPTA
Dr Dhananjay Bisen
Session: 2023-24
Experiment - 1
Introduction
Requirements identification is the first step of any software development project. Until
the requirements of a client have been clearly identified, and verified, no other task
(design, coding, testing) could begin. Usually business analysts having domain
knowledge on the subject matter discuss with clients and decide what features are to be
implemented.
In this experiment we will learn how to identify functional and non-functional
requirements from a given problem statement. Functional and non-functional
requirements are the primary components of a Software Requirements Specification
Objectives;
Requirements
Sommerville defines "requirement" [1] as a specification of what should be implemented.
Requirements specify how the target system should behave. It specifies what to do, but
not how to do. Requirements engineering refers to the process of understanding what a
customer expects from the system to be developed, and to document them in a standard
and easily readable and understandable format. This documentation will serve as
reference for the subsequent design, implementation and verification of the system.
It is necessary and important that before we start planning, design and implementation of
the software system for our client, we are clear about it's requirements. If we don't have a
clear vision of what is to be developed and what all features are expected, there would be
serious problems, and customer dissatisfaction as well.
Characteristics of Requirements
Requirements gathered for any new system to be developed should exhibit the following
three properties:
• Unambiguity: There should not be any ambiguity what a system to be developed
should do. For example, consider you are developing a web application for your
client.
• Consistency: To illustrate this, consider the automation of a nuclear plant.
Suppose one of the clients say that it the radiation level inside the plant exceeds
R1, all reactors should be shut down.
• Completeness: A particular requirement for a system should specify what the
system should do and also what it should not. For example, consider a software to
be developed for ATM. If a customer enters an amount greater than the maximum
permissible withdrawal amount, the ATM should display an error message, and it
should not dispense any cash.
• Modifiability
• Feasibility
• Testability
Categorization of Requirements
Based on the target audience or subject matter, requirements can be classified into
different types, as stated below:
• User requirements: They are written in natural language so that both customers
can verify their requirements have been correctly identified
• System requirements: They are written involving technical terms and/or
specifications, and are meant for the development or testing teams
Requirements can be classified into two groups based on what they describe:
• Functional requirements (FRs): These describe the functionality of a system --
how a system should react to a particular set of inputs and what should be the
corresponding output.
• Non-functional requirements (NFRs): They are not directly related what
functionalities are expected from the system. However, NFRs could typically
define how the system should behave under certain situations. For example, a
NFR could say that the system should work with 128MB RAM. Under such
condition, a NFR could be more critical than a FR.
Non-functional requirements could be further classified into different types like:
▪ Product requirements: For example, a specification that the web application
should use only plain HTML, and no frames
▪ Performance requirements: For example, the system should remain available
24x7
▪ Organizational requirements: The development process should comply to SEI
CMM level 4
Identifying Functional Requirements
Given a problem statement, the functional requirements could be identified by focusing
on the following points:
• Identify the high level functional requirements simply from the conceptual
understanding of the problem. For example, a Library Management System, apart
from anything else, should be able to issue and return books.
• Identify the cases where an end user gets some meaningful work done by using
the system. For example, in a digital library a user might use the "Search Book"
functionality to obtain information about the books of his interest.
• If we consider the system as a black box, there would be some inputs to it, and
some output in return. This black box defines the functionalities of the system.
For example, to search for a book, user gives title of the book as input and get the
book details and location as the output.
• Any high level requirement identified could have different sub-requirements. For
example, "Issue Book" module could behave differently for different class of
users, or for a particular user who has issued the book thrice consecutively.
Difference Between Functional Requirements and Non Functional Requirements:
Objectives
After completing this experiment you will be able to:
• Categorize projects using COCOMO, and estimate effort and development time
required for a project
• Estimate the program complexity and effort required to recreate it using
Halstead's metrics
Project Estimation Techniques
A software project is not just about writing a few hundred lines of source code to achieve
a particular objective. The scope of a software project is comparatively quite large, and
such a project could take several years to complete. However, the phrase "quite large"
could only give some (possibly vague) qualitative information. As in any other science
and engineering discipline, one would be interested to measure how complex a project is.
One of the major activities of the project planning phase, therefore, is to estimate various
project parameters in order to take proper decisions. Some important project parameters
that are estimated include:
• Project size: What would be the size of the code written say, in number of lines,
files, modules?
• Cost: How much would it cost to develop a software? A software may be just
pieces of code, but one has to pay to the managers, developers, and other project
personnel.
• Duration: How long would it be before the software is delivered to the clients?
• Effort: How much effort from the team members would be required to create the
software?
In this experiment we will focus on two methods for estimating project metrics:
COCOMO and Halstead's method.
COCOMO
COCOMO (Constructive Cost Model) was proposed by Boehm. According to him, there
could be three categories of software projects: organic, semidetached, and embedded. The
classification is done considering the characteristics of the software, the development
team and environment. These product classes typically correspond to application, utility
and system programs, respectively. Data processing programs could be considered as
application programs. Compilers, linkers, are examples of utility programs. Operating
systems, real-time system programs are examples of system programs. One could easily
apprehend that it would take much more time and effort to develop an OS than an
attendance management system.
The concept of organic, semidetached, and embedded systems are described below.
• Organic: A development project is said to be of organic type, if
• The project deals with developing a well understood application
• The development team is small
• The team members have prior experience in working with similar types of
projects
• Semidetached: A development project can be categorized as semidetached type,
if
• The team consists of some experienced as well as inexperienced staff
• Team members may have some experience on the type of system to be
developed
• Embedded: Embedded type of development project are those, which
• Aims to develop a software strongly related to machine hardware
• Team size is usually large
Boehm suggested that estimation of project parameters should be done through three
stages: Basic COCOMO, Intermediate COCOMO, and Complete COCOMO.
Basic COCOMO Model
The basic COCOMO model helps to obtain a rough estimate of the project parameters. It
estimates effort and time required for development in the following way:
Effort = a * (KDSI)b PMTdev = 2.5 * (Effort)c Monthswhere
• KDSI is the estimated size of the software expressed in Kilo Delivered
Source Instructions
• a, b, c are constants determined by the category of software project
• Effort denotes the total effort required for the software development,
expressed in person months (PMs)
• Tdev denotes the estimated time required to develop the software
(expressed in months)
The value of the constants a, b, c are given below:
Software project a b c
Ratings
Product attributes
Required software
0.75 0.88 1.00 1.15 1.40
reliability
Size of application
0.94 1.00 1.08 1.16
database
Cost drivers for INtermediate COCOMO
(Source: http://en.wikipedia.org/wiki/COCOMO)
Ratings
Hardware attributes
Run-time performance
1.00 1.11 1.30 1.66
constraints
Personnel attributes
Software engineer
1.42 1.17 1.00 0.86 0.70
capability
Virtual machine
1.21 1.10 1.00 0.90
experience
Programming language
1.14 1.07 1.00 0.95
experience
Project attributes
Application of software
1.24 1.10 1.00 0.91 0.82
engineering methods
Required development
1.23 1.08 1.00 1.04 1.10
schedule
EAF is used to refine the estimates obtained by basic COCOMO as
follows:Effort|corrected = Effort * EAFTdev|corrected = 2.5 * (Effort| corrected) c
.
Figure - 01: A use case diagram for a book store
Association between Actors and Use Cases
A use case is triggered by an actor. Actors and use cases are connected through binary
associations indicating that the two communicates through message passing.
An actor must be associated with at least one use case. Similarly, a given use case must be
associated with at least one actor. Association among the actors are usually not shown. However,
one can depict the class hierarchy among actors.
Use Case Relationships
Three types of relationships exist among use cases:
• Include relationship
• Extend relationship
• Use case generalization
Include Relationship
Include relationships are used to depict common behaviour that are shared by multiple use cases.
This could be considered analogous to writing functions in a program in order to avoid repetition
of writing the same code. Such a function would be called from different points within the
program.
Example
For example, consider an email application. A user can send a new mail, reply to an email he has
received, or forward an email. However, in each of these three cases, the user must be logged in
to perform those actions. Thus, we could have a login use case, which is included by compose
mail, reply, and forward email use cases. The relationship is shown in figure - 02.
Figure - 02: Include relationship between use cases
Notation
Include relationship is depicted by a dashed arrow with a «include» stereotype from the including
use case to the included use case.
Extend Relationship
Use case extensions are used used to depict any variation to an existing use case. They are used to
the specify the changes required when any assumption made by the existing use case becomes
false [iv, v].
Example
Let's consider an online bookstore. The system allows an authenticated user to buy selected
book(s). While the order is being placed, the system also allows to specify any special shipping
instructions [vii], for example, call the customer before delivery. This Shipping Instructions step
is optional, and not a part of the main Place Order use case. Figure - 03 depicts such relationship.
EXERCISE 1
Draw a use case diagram for the following problem
Consider a library, where a member can perform two operations: issue book and return it. A book
is issued to a member only after verifying his credentials. Draw a use case diagram for the
problem.
Learning Objectives:
• Identify the actors and use cases
• Associate the use cases with the actors by drawing a simple use case diagram
Limitations: While extending a use case, extension points could not be defined through this
interface
.
EXERCISE 2
Draw a use case diagram for the following problem
Consider your neighbouring travel agent from whom you can purchase flight tickets. To book a
ticket you need to provide details about your journey i.e. on which date and at what time you
would like to travel. You also need to provide your address. The agency has recently been
modernized. So you can pay either by cash or by card. You can also cancel a booked ticket later if
you decide to change your plan. In that case you need to book a new ticket again. Your agent also
allows you to book a hotel along with flight ticket. While canceling a flight ticket you can also
cancel hotel booking. Appropriate refund as per policy is made in case of cancellation.
Learning Objectives:
• Identify the use cases from a given non-trivial problem statement
• Identify the primary and secondary actors for a system
• Use to generalization of use cases and «include» stereotypes to prevent redundancy in the
coding phase
Limitations: While extending a use case, extension points could not be defined through this
interface.
Results & Discussions
While booking a flight or hotel customer has to provide his permanent address. So, the two use
concerned cases includes the use case 'Get address'.
Payment could be made either by cash or card. So, each of those use cases extends the 'Make
payment' use case. Customer makes the payment while travel agent receives it. Therefore both
customer and travel agent are associated with the use case 'Make payment'.
Experiment 4
Attributes of Entity
Attributes are the characteristics describing any entity belonging to an entity set. Any entity in a
set can be described by zero or more attributes.
For example, any student has got a name, age, an address. At any given time a student can study
only at one school. In the school he would have a roll number, and of course a grade in which he
studies. These data are the attributes of the entity set Student.
Keys
One or more attribute(s) of an entity set can be used to define the following keys:
Super key: One or more attributes, which when taken together, helps to uniquely identify an
entity in an entity set.
For example, a school can have any number of students. However, if we know grade and roll
number, then we can uniquely identify a student in that school.
Candidate key: It is a minimal subset of a super key. In other words, a super key might contain
extraneous attributes, which do not help in identifying an object uniquely. When such attributes
are removed, the key formed so is called a candidate key.
Primary key: A database might have more than one candidate key. Any candidate key chosen for
a particular implementation of the database is called a primary key.
Mapping Cardinalities
One of the main tasks of ER modeling is to associate different entity sets. Let's consider two
entity sets E1 and E2 associated by a relationship set R. Based on the number of entities in E1 and
E2 are associated with, we can have the following four type of mappings:
One to one: An entity in E1 is related to at most a single entity in E2, and vice versa.
One to many: An entity in E1 could be related to zero or more entities in E2. Any entity in E2
could be related to at most a single entity in E1.
Many to one: Zero or more number of entities in E1 could be associated to a single entity in E2.
However, an entity in E2 could be related to at most one entity in E1.
Many to many: Any number of entities could be related to any number of entities in E2,
including zero, and vice versa.
ER Diagram
From a given problem statement we identify the possible entity sets, their attributes, and
relationships among different entity sets. Once we have these information, we represent them
pictorially, called an entity-relationship (ER) diagram.
Graphical Notations for ER Diagram
Importance of ER modelling
Given a problem statement, the first step is to identify the entities, attributes and relationships. We
represent them using an ER diagram. Using this ER diagram, table structures are created, along
with required constraints. Finally, these tables are normalized in order to remove redundancy and
maintain data integrity. Thus, to have data stored efficiently, the ER diagram is to be drawn as
much detailed and accurate as possible.
EXERCISE 1
From the following problem statement identify the possible entity sets, their attributes, and
relationships.
SE VLabs Inc. is a young company with a few departments spread across the country. As of now,
the company has a strength of 200+ employees.
Each employee works in a department. While joining, a person has to provide a lot of personal
and professional details including name, address, phone #, mail address, date of birth, and so on.
Once all these information are furnished, a unique ID is generated for each employee. He is then
assigned a department in which he will work.
There are around ten departments in the company. Unfortunately, two departments were given
same names. However, departments too have ID's, which are unique.
Note: Try to use the features of the interface provided to capture as much details as possible.
Entity Set: Employee , Attributes: Name, Address, Phone number, Email address, Date of
birth, Employee ID (generated)
Relationships: Works in Department, Entity Set: Department
Attributes: Name, Department ID (unique), Relationships:, Employees work in
Department
Relationship: Works in Department
Description: Associates an employee with the department they work in.
Cardinality: Many-to-One (Many employees can work in one department, but one
employee can only work in one department)
With this breakdown, we capture the essential entity sets, their attributes, and the
relationship between them as described in the problem statement. These details provide a
foundation for designing a database schema or entity-relationship diagram to represent
the data model for SE VLabs Inc.
EXERCISE 2
Draw an ER diagram for the following problem:
The latest cab services agency in the city has approached you to develop a Cab Management
System for them. They would be using this software to efficiently manage and track different cabs
that are operated by them.
Cabs are solely owned by the agency. They hire people in contracts to drive the cabs. A cab can
be uniquely identified by, like any other vehicle in the country, its license plate. A few different
categories of cars are available from different manufacturers. And a few of them are AC cars.
Cab drivers are given a identification card while joining. The ID card contains his name,
permanent address, phone number, date of joining, duration of contract. Also, an unique
alphanumeric code is assigned to each number.
The agency provides service from 8 AM to 8 PM. Whenever any passenger books a cab, an
available cab is allocated for him. The booking receipt given to the passenger contains the car #,
source and destination places. Once he reaches the destination, he signs on a duplicate copy of the
receipt and gives back to the driver. Driver must submit this duplicate copy signed by the
passenger at the agency for confirmation.
To evaluate their quality of service, the agency also wants a (optional) customer satisfaction
survey, where passengers can provide feedback about their journey through the agency's website.
Note: This exercise is adapted from [ii]
Results & Discussions
his ER diagram effectively captures the entities involved in the Cab Management System
and their relationships. It provides a clear visualization of how cabs, drivers, passengers,
bookings, and feedback are interconnected within the system.The relationships defined in
the diagram reflect the interactions and dependencies between the entities.Additionally,
the optional entity for customer satisfaction survey allows the agency to gather feedback
from passengers.
Overall, this ER diagram serves as a valuable blueprint for designing and implementing
the Cab Management System, facilitating efficient management and tracking of cabs
operated by the agency.
Experiment 5
UML diagrams can be broadly categorized into structural and behavioral diagrams.
Structural diagrams focus on the static aspects of a system, depicting its elements and
how they relate to each other. Behavioral diagrams, on the other hand, illustrate the
dynamic aspects, such as interactions and behaviors among the system's components.
Class Diagram:
Messages:
1. Messages represent communication or interactions between objects in the sequence
diagram.
2. Messages are depicted as arrows between lifeline bars, indicating the flow of
communication.
3. There are different types of messages, including:
1. Synchronous Message: Denoted by a solid arrow, indicating that the sender
waits for a response from the receiver before proceeding.
2. Asynchronous Message: Denoted by a dashed arrow, indicating that the sender
does not wait for a response and continues its execution immediately.
3. Return Message: Represents the response to a previous message, indicating the
flow of control back to the sender.
4. Create Message: Represents the creation of a new object.
5. Destroy Message: Represents the destruction of an object.
EXERCISE 1
A web browser is a software that helps us access a resource (web page) available on the
World Wide Web and identified by a URL. A web browser consists of different sub-
components, which can be primarily categorized into browser rendering engine,
and browser control.
The rendering engine is responsible for displaying a requested page in the web browser.
The rendering engine itself is quite a complex piece of software, which knows how to
display a web page based on the HTML elements present in the page, and CSS rules
defined (if any). Today browsers are not only limited to displaying text and images, but
can provide access to audio and video components also.
Learning Objectives:
Limitations: All possible features of a class diagram could not be implemented here.
Also, auto-generation of code from the class diagram is not possible here.
How would you represent the three-way handshaking mechanism of TCP with a sequence
diagram?
Learning Objectives:
Note that in real life there will be a time delay between a message sent at one end and
received at the other end. Such time delay couldn't be represented here.
EXERCISE 3
The Web traditionally worked in a client-server model, where a web browser would send
a HTTP request to the web server, and the server would send back a HTTP response to
the browser. The HTTP request actually encapsulates the contents of the requested
resource in some format. In cases where access to a resource is restricted or say, it
requires a user authentication, the HTTP request encapsulates the login credentials and
sends to the server. The server then checks with the database server if the credentials are
correct. The status of verification is then send back to the browser.
In the recent years there has been a shift from the traditional way of how HTTP works. A
new technique has been proposed, popularly know as AJAX, that lets asynchronous
communication between a browser and web server. In traditional model, the browser used
to send a HTTP request, and then wait for a HTTP response. The next HTTP request was
usually sent after getting response from the server.
AJAX, however, lets a web browser to send multiple HTTP requests one after another,
without waiting until a response is received. This approach is found to be very helpful in
cases when contents of only a portion of the web page has to be updated, rather than
refreshing the entire page. Web 2.0 uses AJAX in many different cases for better user
experience.
1. How would you represent the traditional Web with a sequence diagram (in both
cases when user verification is required or not)
2. What changes would appear in your sequence diagram if you are trying model a
scenario where AJAX is being used?
Learning Objectives:
The figure above shows how "traditional" Web typically works. "Reource1" and
"Resource2" represent two resources, which could be accessed only after an user has
authenticated himself. As seen in the picture, the "Web Browser" sends a synchronous
"HTTP Request" to the server for transferring any information from the web browser to
the web server. The "Web Server" in turn sends back any information by encapsulating it
in a "HTTP Response" object. The point to note here is that the message sent by web
browser is synchronous. The web browser has to wait for a response, and update it's
display when it arrives. Only after then the web browser could send out a request for any
other resource.
The scenario changes when AJAX is being used. The corresponding sequence diagram is
shown in the figure below. (The user login sequence has not been shown here.)
Here, the "Web Browser" sends out asynchronous "XmlHttpRequest" to the "Web
Server". As such, it doesn't have to wait for a response to arrive from the web server.
Instead say, as a result of the user clicking on two buttons, the web browser can simply
send out two "XmlHttpRequests". It updates the display as and when a response arrives
from the web server.
Experiment 6
EXERCISE 1
Draw a context-level DFD to depict the typical user authentication process used by any
system. An user gives two inputs -- user name and password.
Results & Discussions
The context-level DFD (Data Flow Diagram) for the user authentication process depicts
the high-level overview of how a system typically handles user authentication using a
username and password input. Here's the breakdown of the diagram:
External Entity: Represents the user who interacts with the system by providing their
username and password for authentication.
Process: Represents the system's authentication process, which verifies the user's
credentials against stored data.
Data Flow:
Username Input: Represents the flow of the username input provided by the user.
Password Input: Represents the flow of the password input provided by the user.
Authentication Result: Represents the outcome of the authentication process, indicating
whether the user's credentials are valid or invalid.
Overall, the context-level DFD effectively captures the essence of the user authentication
process, providing a foundational understanding of how systems authenticate users based
on their provided username and password inputs.
EXERCISE 2
The Absolute Beginners Inc. is planning to launch a revolutionary social networking site,
EyeCopy. You have been entrusted with designing a DFD for the proposed application.
In particular, you have been asked to show the following scenarios:
• User registration
• User login
• Profile update
Draw a Level 1 DFD to depict the above data flow and the corresponding processes.
Should there be any data store in the DFD?
Results & Discussions
The Level 1 DFD effectively illustrates the main processes and data flows involved in user
registration, user login, and profile update scenarios for the EyeCopy social networking
site. It provides a high-level overview of how users interact with the system to perform
these essential functions.
User-Centric Focus: The DFD emphasizes the user's actions (registration, login, profile
update) as primary processes, highlighting the user's interaction with the system.
Data Flow Clarity: Each process is clearly defined with corresponding data flows,
indicating the exchange of information between the user and the system.
Data Store Usage: The inclusion of the User Profile Data Store ensures that user profile
information is securely stored and accessible for both registration and profile update
processes.
Scalability: The DFD can be further expanded to include additional processes and data
flows as needed, providing scalability in depicting the functionality of the social
networking site.
Overall, the Level 1 DFD serves as a valuable tool for understanding the core
functionality of the EyeCopy social networking site, facilitating communication and
collaboration during the development process.
Experiment 7
Raptor has 6 types of symbols, each of which represents a unique kind of instruction.
They are – Assignment, Call, Input, Output, Selection and Loop symbols.
The following image shows these symbols-
Introduction
RAPTOR (Rapid Algorithmic Prototyping Tool for Ordered Reasoning) is a free graphical
authoring tool created by Martin C. Carlisle, Terry Wilson, Jeff Humphries and Jason Moore,
designed specifically to help students visualize their algorithms and avoid syntactic baggage.
Students can create flow-chart for a particular program and raptor tool will generate code for
it in various programming languages, such as C, C++, Java and so on.
Symbols in RAPTOR
Raptor has 6 types of symbols, each of which represents a unique kind of instruction. They are
– Assignment, Call, Input, Output, Selection and Loop symbols. The following image shows
these symbols-
Call Symbol:
In RAPTOR, there isn't a specific symbol called "Call". Instead, functions or procedures can
be represented using rectangular symbols with the name of the function or procedure inside.
When you have modularized your code into functions or procedures, you can use these symbols
to call those functions or procedures.
Loop Symbol:
In RAPTOR, loops are represented using rectangular symbols labeled with loop keywords
(e.g., "Repeat" or "While").
These symbols indicate a sequence of operations that are repeated until a certain condition is
met.
Experiment – 8
Estimation of Test coverage metrics and structural complexity
A program, however, doesn't always consist of only sequential statements. There could be
branching and looping involved in it as well. Figure 2 shows how a CFG would look like if
there are sequential, selection and iteration kind of statements in order.
A real life application seldom could be written in a few lines. In fact, it might consist of
thousand of lines. A CFG for such a program is likely to become very large, and it would
contain mostly straight-line connections. To simplify such a graph different sequential
statements could be grouped together to form a basic block. A basic block is a maximal
sequence of program instructions I1, I2, ..., In such that for any two adjacent instructions Ik and
Ik+1, the following holds true:
• Ik is executed immediately before Ik+1
• Ik+1 is executed immediately after Ik
The size of a CFG could be reduced by representing each basic block with a node. To illustrate
this, let's consider the following example.
sum = 0;
i = 1;
while (i ≤ n) {
sum += i;
++i;
}
printf("%d", sum);
if (sum > 0) {
printf("Positive");
}
The CFG with basic blocks is shown for the above code in figure 3.
The first statement of a basic block is termed as leader. Any node x in a CFG is said to
dominate another node y (written as x dom y) if all possible execution paths that goes through
node y must pass through node x. The node x is said to be a dominator. In the above example,
line #s 1, 3, 4, 6, 7, 9, 10 are leaders. The node containing lines 7, 8 dominate the node
containing line # 10. The block containing line #s 1, 2 is said to be the entry block; the block
containing line # 10 is said to be the exit block.
If any block (or sub-graph) in a CFG is not connected with the sub-graph containing the entry
block, that signifies the concerned block contains code, which is unreachable while the program
is executed. Such unreachable code can be safely removed from the program. To illustrate this,
let's consider a modified version of our previous code:
sum = 0;
i = 1;
while (i ≤ n) {
sum += i;
++i;
}
return sum;
if (sum < 0) {
return 0;
}
The sub-graph containing line #s 8, 9, 10 is disconnected from the graph containing the entry
block. The code in the disconnected sub-graph would never get executed, and, therefore, could
be discarded.
Path
A path in a CFG is a sequence of nodes and edges that starts from the initial node (or entry
block) and ends at the terminal node. The CFG of a program could have more than one terminal
nodes.
Linearly-Independent-Path
A linearly independent path is any path in the CFG of a program such that it includes at least
one new edge not present in any other linearly independent path. A set of linearly independent
paths give a clear picture of all possible paths that a program can take during it's execution.
Therefore, path-coverage testing of a program would suffice by considering only the linearly
independent-paths.
we can find four linearly independent paths:
1 - 3 - 6 - (7, 8) - 10
1 - 3 - 6 - (7, 8) - 9 - 10
1 - 3 - (4, 5) - 6 - (7, 8) - 10
1 - 3 - (4, 5) - 6 - (7, 8) - 9 - 10
Note that 1 - 3 - (4, 5) - 3 - (4, 5) - 6 - (7, 8) - 10, for instance, won't qualify as a linearly
independent path because there is no new edge not already present in any of the above four
linearly independent paths.
McCabe's Cyclomatic Complexity
McCabe had applied graph-theoretic analysis to determine the complexity of a program
module. Cyclomatic complexity metric, as proposed by McCabe, provides an upper bound for
the number of linearly independent paths that could exist through a given program module.
Complexity of a module increases as the number of such paths in the module increase. Thus,
if Cyclomatic complexity of any program module is 7, there could be up to seven linearly
independent paths in the module. For a complete testing, each of those possible paths should
be tested.
In case of object-oriented programming, the above equations apply to methods of a class [viii].
Also, the value of V(G) so obtained is incremented by 1 considering the entry point of the
method. A quick summary of how different types of statements affect V(G) could be found in .
Once the complexities of individual modules of a program are known, complexity of the
program (or class) could be determined by: V(G) = SUM( V(Gi) ) - COUNT( V(Gi) ) +
1where COUNT( V(Gi) ) gives the total number of procedures (methods) in the program (class).
Merits
McCabe's Cyclomatic complexity has certain advantages:
• Independent of programming language
• Helps in risk analysis during development or maintenance phase
• Gives an idea about the maximum number of test cases to be executed (hence, the
required effort) for a given module
Demerits
Cyclomatic complexity doesn't reflect on cohesion and coupling of modules.
McCabe's Cyclomatic complexity was originally proposed for procedural languages. One may
look in to get an idea of how the complexity calculation could be modified for object-oriented
languages. In fact, one may also wish to make use of Chidamber-Kemerer metrics (or any other
similar metric), which has been designed for object-oriented programming.
Exercise-1:
#include <stdio.h>
Any sequence of instructions in a program could be represented in terms of basic blocks, and
a CFG could be drawn using those basic blocks. For the given C program:
Identify the basic blocks and verify whether your representation matches with the output
produced after compiling your program. Draw a Control Flow Graph (CFG) using these basic
blocks. Again, verify how the CFG generated after compilation relates to the basic blocks
identified by the compiler. Calculate McCabe's complexity from the CFG so obtained. Note
that gcc translates the high-level program into an intermediate representation using GIMPLE.
So, the CFG generated from your code would not show the actual instructions.
Learning Objectives:
Identify the basic basic blocks for a given program
Draw a CFG using the basic blocks
Determination of McCabe's complexity from a CFG
Limitations: The current workspace can generate CFGs only for the main function. In other
words, this would not work with user-defined functions. However, in real life a program would
contain several modules. All such modules have to be taken into account while determining the
complexity.
Function main (main)
Merging blocks 5 and 6
main (int argc, char * * argv)
{
int n;
int sum;
int i;
int D.1710;
const char * restrict D.1709;
<bb 2>:
n = 10;
sum = 0;
i = 1;
goto <bb 4>;
<bb 3>:
sum = sum + i;
i = i + 1;
<bb 4>:
if (i ≤ n)
goto <bb 3>;
else
goto <bb 5>;
<bb 5>:
D.1709 = (const char * restrict) "Sum of first %d natural numbers is: %d\n";
printf (D.1709, n, sum);
D.1710 = 0;
return D.1710;
}
Exercise-2:
#include <stdio.h>
int main(int argc, char **argv)
{
int a[5][10];
int i;
int j;
int nr;
int nc;
nr = 5;
nc = 10;
for (i = 0; i <= nr; i++) {
for (j = 0; j <= nc; j++) {
a[i][j] = 0;
}
}
return 0;
}
Tasks:
Compile the above program to generate it's CFG. Verify whetther the CFG corresponds to the
basic blocks. Identify the linearly independent paths from the CFG. The paths would be
indicated by the basic block numbers (instead of line numbers of the actual program)
Learning Objectives:
Identify the linearly independent paths from a CFG
Limitations: The current workspace can generate CFGs only for the main function. In other
words, this would not work with user-defined functions. However, in real life a program
would contain several modules. All such modules have to be taken into account while
determining the complexity.
The linearly independent paths for the above shown CFG are:
• 2-7-8-9
• 2-7-3-5-6-7-8-9
• 2-7-3-5-4-5-6-7-8–9
Excercise-3:
The following C program implements the binary search technique performed over an array of
integers. This is an example of a non-trivial program that we often encounter in our lives.
#include <stdio.h>
int main(int argc, char **argv)
{
int a[] = {2, 4, 6, 8, 10, 12, 14, 16};
int key = atoi(argv[1]);
int n = 8;
int low = 0;
int high = n - 1;
int middle;
int flag = 0;
while (low <= high) {
middle = (low + high) / 2;
if (key == a[middle]) {
printf("Found key %d at position %d\n", key, middle);
flag = 1;
}
else if (key < a[middle]) {
high = middle - 1;
}
else {
low = middle + 1;
}
if (flag)
break;
}
if (! flag)
printf("Key %d was not found!\n", key);
return 0;
}
Determine the cyclomatic complexity of this program. How would you classify this program
in terms of its complexity (simple, complex, unstable)?
Limitations: The current workspace can generate CFGs only for the main function. In other
words, this would not work with user-defined functions. However, in real life a program would
contain several modules. All such modules have to be taken into account while determining the
complexity.
Experiment-9
Designing Test Suites
Software Testing
Testing software is an important part of the development life cycle of a software. It is an
expensive activity. Hence, appropriate testing methods are necessary for ensuring the reliability
of a program. According to the ANSI/IEEE 1059 standard, the definition of testing is the
process of analyzing a software item, to detect the differences between existing and required
conditions i.e. defects/errors/bugs and to evaluate the features of the software item.
The purpose of testing is to verify and validate a software and to find the defects present in a
software. The purpose of finding those problems is to get them fixed.
• Verification is the checking or we can say the testing of software for consistency and
conformance by evaluating the results against pre-specified requirements.
• Validation looks at the systems correctness, i.e. the process of checking that what has
been specified is what the user actually wanted.
• Defect is a variance between the expected and actual result. The defect’s ultimate source
may be traced to a fault introduced in the specification, design, or development (coding)
phases.
Testing Frameworks
Following are the different testing frameworks:
Unit Testing
Unit testing is done at the lowest level. It tests the basic unit of software, that is the smallest
testable piece of software. The individual component or unit of a program are tested in unit
testing. Unit testing are of two types.
• Black box testing: This is also known as functional testing , where the test cases are
designed based on input output values only. There are many types of Black Box Testing
but following are the prominent ones.
- Equivalence class partitioning: In this approach, the domain of input values to a program is
divided into a set of equivalence classes. e.g. Consider a software program that computes
whether an integer number is even or not that is in the range of 0 to 10. Determine the
equivalence class test suite. There are three equivalence classes for this program. - The set of
negative integer - The integers in the range 0 to 10 - The integer larger than 10
- Boundary value analysis : In this approach, while designing the test cases, the values at
boundaries of different equivalence classes are taken into consideration. e.g. In the above given
example as in equivalence class partitioning, a boundary values based test suite is { 0, -1, 10,
11 }
• White box testing: It is also known as structural testing. In this testing, test cases are
designed on the basis of examination of the code.This testing is performed based on the
knowledge of how the system is implemented. It includes analyzing data flow, control
flow, information flow, coding practices, exception and error handling within the
system, to test the intended and unintended software behavior. White box testing can
be performed to validate whether code implementation follows intended design, to
validate implemented security functionality, and to uncover exploitable
vulnerabilities.This testing requires access to the source code. Though white box testing
can be performed any time in the life cycle after the code is developed, but it is a good
practice to perform white box testing during the unit testing phase.
Integration Testing
Integration testing is performed when two or more tested units are combined into a larger
structure. The main objective of this testing is to check whether the different modules of a
program interface with each other properly or not. This testing is mainly of two types:
• Top-down approach
• Bottom-up approach
In bottom-up approach, each subsystem is tested separately and then the full system is tested.
But the top-down integration testing starts with the main routine and one or two subordinate
routines in the system. After the top-level ‘skeleton’ has been tested, the immediately
subroutines of the ‘skeleton’ are combined with it and tested.
System Testing
System testing tends to affirm the end-to-end quality of the entire system. System testing is
often based on the functional / requirement specification of the system. Non-functional quality
attributes, such as reliability, security, and maintainability are also checked. There are three
types of system testing
• Alpha testing is done by the developers who develop the software. This testing is also
done by the client or an outsider with the presence of developer or we can say tester.
• Beta testing is done by very few number of end users before the delivery, where the
change requests are fixed, if the user gives any feedback or reports any type of defect.
• User Acceptance testing is also another level of the system testing process where the
system is tested for acceptability. This test evaluates the system's compliance with the
client requirements and assess whether it is acceptable for software delivery
• An error correction may introduce new errors. Therefore, after every round of error-
fixing, another testing is carried out, i.e. called regression testing. Regression testing
does not belong to either unit testing, integration testing, or system testing, instead, it
is a separate dimension to these three forms of testing.
Regression Testing
The purpose of regression testing is to ensure that bug fixes and new functionality introduced
in a software do not adversely affect the unmodified parts of the program [2]. Regression testing
is an important activity at both testing and maintenance phases. When a piece of software is
modified, it is necessary to ensure that the quality of the software is preserved. To this end,
regression testing is to retest the software using the test cases selected from the original test
suite.
Example
Write a program to calculate the square of a number in the range 1-100
#include <stdio.h>
int main()
{
int n, res;
printf("Enter a number: ");
scanf("%d", &n);
if (n >= 1 && n <= 100)
{
res = n * n;
printf("\n Square of %d is %d\n", n, res);
}
else if (n<= 0 || n > 100)
printf("Beyond the range");
return 0;
}
Output
Inputs Outputs
I1 : -2 O1 : Beyond the range
I2 : 0 O2 : Beyond the range
I3 : 1 O3 : Square of 1 is 1
I4 : 100 O4 : Square of 100 is 10000
I5 : 101 O5 : Beyond the range
I6 : 4 O6 : Square of 4 is 16
I7 : 62 O7 : Square of 62 is 3844
Test Cases
T1 : {I1 ,O1}
T2 : {I2 ,O2}
T3 : {I3, O3}
T4 : {I4, O4}
T5 : {I5, O5}
T6 : {I6, O6}
T7 : {I7, O7}
Exercise:
The Absolute Beginners Inc. seems to have been fascinated by your work. Recently they have
entrusted you with a task of writing a web-based mathematical software (using JavaScript). As
part of this software, your team mate has written a small module, which computes area of
simple geometric shapes. A portion of the module is shown below.
Prepare a test suite that will- Verify each of the above mentioned individual function is working
correctly. Your task essentially is to verify whether each of the above function is returning
correct values for given inputs. For example, a rectangle with length 10 unit and breadth 5 unit
will have an area of 50 sq. unit. This can be verified from the output of the function call
rectangle(10, 5);
However, testing also attempts to point out possible bugs in the software. How would the above
code behave for a call
rectangle(10, -5);
Modify the code to address this defect.
Limitations: This workspace attempts to provide a very simple version of a testing framework.
Real life testing frameworks are much more extensive and provide a lot of options like creating
test cases from user requirements, automatic reporting of bug when a test case fails, and so on.
Nevertheless, this workspace is expected to make a student familiar to testing and some of it's
templates and reports.