Software Testing Notes
Software Testing Notes
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
STUDY MATERIAL
SOFTWARE TESTING
(II CS)
SOFTWARETESTING
UNIT I
Introduction: Purpose–Productivity and Quality in Software– Testing Vs. Debugging–Model for
Testing–Bugs–Types of Bugs – Testing and Design Style.
UNIT II
Flow / Graphs and Path Testing – Achievable paths – Path instrumentation Application Transaction
Flow Testing Techniques.
UNIT III
Data Flow Testing Strategies - Domain Testing: Domains and Paths – Domains and Interface
Testing.
UNIT IV
Linguistic –Metrics – Structural Metric – Path Products and Path Expressions. Syntax Testing–
Formats–Test Cases
UNIT IV
Logic Based Testing–Decision Tables–Transition Testing–States, State Graph, State Testing.
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
SOFTWARE TESTING
LECTURE NOTES
Unit I
(Introduction) : Purpose of Testing - productivity and Quality in software - Testing vs Debugging -
Model for Testing - Bugs - Types of Bugs - Testing and Design Style.
Definition of Software:
Software is a set of instructions, programs, or data that directs a computer on how to perform
specific tasks. It acts as the intermediary between the user and the hardware, enabling the execution
of operations and the functionality of devices.
Types of Software:
System Software:
Manages and controls the computer hardware so other software can function.
Ex: Windows, macOS, Linux, antivirus
Application Software:
Performs specific tasks for end-users, designed to solve problems or fulfill particular
needs.
Ex : Microsoft Office, Google Docs, games, media players
Programming Software:
Provides tools for developers to write, test, and debug other software.
Ex: Python Interpreter
Definition of Testing:
Testing is the process of exercising or evaluating a system or system components by manual or
automated means to verify that it satisfies specified requirements.
The Purpose of Testing:
Testing consumes at least half of the time and work required to produce a functional program.
o MYTH: Good programmers write code without bugs. (It’s wrong!!!)
o History says that even well written programs still have 1-3 bugs per hundred
statements.
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
Productivity in software development refers to the efficiency and speed at which software is
developed while maintaining desired quality. It measures how effectively developers can convert
requirements into functional software within a given timeframe.
1. Development Tools: Modern IDEs, frameworks, and libraries can significantly speed up
development.
2. Team Skills and Experience: Skilled and experienced developers produce high-quality
work faster.
3. Processes and Methodologies: Agile, DevOps, or other methodologies can streamline
workflows.
4. Code Reusability: Reusing code modules or libraries reduces development time.
5. Collaboration and Communication: Efficient teamwork and clear communication improve
productivity.
6. Automation: Automating repetitive tasks like testing and deployment increases efficiency.
Quality in Software
Software quality refers to the degree to which a software product meets customer requirements and
expectations, as well as how well it performs under specified conditions.
Testing vs Debugging:
Testing: To identify errors or verify that a system meets its requirements. The goal is to ensure the
software behaves as expected under various conditions.
Debugging: To identify, analyze, and fix defects found during testing or operation. The goal is to
locate the root cause of a failure and resolve it.
Testing vs Debugging:
It is the implementation of the software The process of fixing and resolving the
1.
with the intent of identifying the defects defects is known as debugging.
Testing can be performed either manually
The debugging process cannot be
2. or with the help of some automation
automated.
tools.
A group of test engineers executes
Debugging is done by the developer or
3. testing, and sometimes it can be
the programmer.
performed by the developers.
The test engineers perform manual and
automated test cases on the application,
The developers will find, evaluates, and
4. and if they detect any bug or error, they
removes the software errors.
can report back to the development team
for fixing.
Without having an understanding of the
Programming knowledge is not required
5. programming language, we cannot
to perform the testing process.
proceed with the debugging process.
Once the coding phase is done, we After the implementation of the test case,
6.
proceed with the testing process. we can start the Debugging process.
Software Testing includes two or more Debugging tries to match indication with
7. activities such as validation and cause, hence leading to the error
verification of the software. correction.
It is built on different testing levels such It is built on different kinds of bugs
8. as Unit Testing, Integration Testing, because there is no such level of
System Testing, etc. debugging is possible.
Software testing is the presentation of
9. It is a logical procedure.
defects.
Software testing is the vital phase of
It is not a part of SDLC because it occurs
10. SDLC (Software Development Life
as a subset of testing.
Cycle).
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
1. Environment:
(i) A Program's environment is the hardware and software required to make it run.
For online systems, the environment may include communication lines, other
systems, terminals and operators.
(ii) The environment also includes all programs that interact with and are used to
create the program under test - such as OS, linkage editor, loader, compiler,
utility routines.
Because the hardware and firmware are stable, it is not smart to blame the
environment for bugs.
2. Program:
(i) Most programs are too complicated to understand in detail.
(ii) The concept of the program is to be simplified in order to test it.
(iii) If simple model of the program doesn’t explain the unexpected behavior, we
may have to modify that model to include more facts and details. And if that
fails, we may have to modify the program.
3. Bugs:
(i) Bugs are more insidious (deceiving but harmful) than ever we expect them to be.
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
(ii) An unexpected test result may lead us to change our notion of what a bug is and
our model of bugs.
(iii) Some optimistic notions that many programmers or testers have about bugs are
usually unable to test effectively and unable to justify the dirty tests most
programs need.
Definition of Bug:
A bug is an error in a computer program's code that causes the software to behave unexpectedly or
fail.
Types of Bugs:
Functional Bugs: These bugs are issues in software that cause a problem with how it's
supposed to work. They might cause wrong calculations, make it act strangely, crash, or stop
features from working.
Unit Level Bugs: are errors found in the smallest parts of a software system. Developers divide
their code into these units to manage and test it more effectively. This method helps catch and
fix issues early.
Performance Bugs: are an issue that negatively impacts software stability, how fast it runs, or
how quickly it responds to user inputs. They slow down the system or make it unresponsive.
Usability Bugs: are errors that occur during the design of the user interface, making it
ineffective. This means the interface prevents users from performing their tasks easily or
efficiently. As a result, they may find it difficult or time-consuming to accomplish what need to
do.
Security bugs: are ongoing and serious problems in the tech world. These bugs can be exploited
to gain unauthorized access or privileges on a computer system. Attackers can steal sensitive
data or cause other damaging effects.
Logical bugs: disrupt software's intended workflow and cause it to behave incorrectly. These
bugs can lead to unexpected software behavior and even sudden crashes. They primarily occur
due to poorly written code or misinterpretation of business logic.
Compatibility Bugs: occur when software is incompatible with the hardware or cannot be
processed by the operating system. Such bugs arise when the software fails to run correctly on
different devices, operating systems, or environments.
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
Syntax Errors: are very common and typically happen when there are missing or incorrect
characters in the code. These occur in the source code of a program.
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
In software testing, testing style and designing style refer to different approaches or
methodologies used to create and execute test cases. They guide how testers identify test scenarios,
write test cases, and assess the system under test.
1. Testing Style
The testing style refers to the strategies or approaches testers adopt to execute tests and evaluate the
quality of the software. These styles vary depending on the goals, tools, and processes involved.
Exploratory Testing:
Scripted Testing:
Automated Testing:
Context-Driven Testing:
1. Adapts the testing process based on the project context, such as team skills,
application type, or deadlines.
2. Focused on flexibility and relevance.
3. Example: Prioritizing security testing for a banking application.
Risk-Based Testing:
2. Designing Style
The designing style in software testing refers to how test cases or scenarios are planned and created.
This is a key step in ensuring thorough and effective testing.
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
1. Uses formal models of the system (e.g., state machines) to generate test cases.
2. Ensures systematic and comprehensive coverage.
3. Example: Designing test cases from a UML diagram.
Experience-Based Design:
UNIT - II
Unit II (Flow Graphs and Path Testing): Achievable paths - Path instrumentation - Application
of data flow testing - Transaction flow testing techniques.
(ii) The flow graph is similar to the earlier flowchart, with which it is not to be confused .
(iii) Flow Graph Elements:A flow graph contains four different types of elements. (1)
Process Block (2) Decisions (3) Junctions (4) Case Statements. They are following,
1. Process Block:
A process block is a sequence of program statements uninterrupted by either
decisions or junctions.
It is a sequence of statements such that if any one of statement of the block is
executed, then all statement thereof are executed.
Formally, a process block is a piece of straight line code of one statement or
hundreds of statements.
A process has one entry and one exit. It can consists of a single statement or
instruction, a sequence of statements or instructions, a single entry/exit
subroutine, a macro or function call, or a sequence of these.
2. Decisions:
A decision is a program point at which the control flow can diverge.
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
Flow Graph:
1. Node 1: Start
2. Node 2: x > 0
3. Node 3: print("Positive")
4. Node 4: print("Negative")
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
5. Node 5: End
Edges:
1.
1. Independent paths are the unique paths that traverse through the flow graph. These
include all possible branches, loops, and conditions.
1. Path 1: 1 → 2 → 3 → 5
2. Path 2: 1 → 2 → 4 → 5
1. Run the test cases and verify the output against expected results.
Example:
1. Ensure all paths are tested and all branches behave as expected. Modify code or tests
if issues are identified.
Example: If a path produces incorrect output, inspect the logic in the corresponding part of
the flow graph and adjust the code.
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
Path Testing:
Path Testing is a white-box testing technique used to ensure that all possible execution
paths in a program or module are exercised at least once. It focuses on verifying the flow of logic
through the code, aiming to uncover errors in the control flow. It involves identifying and testing all
potential paths through the code, ensuring comprehensive coverage of the program’s logic.
(i) Path:
Path is a sequence of executable statements or instructions in the code from the start to an
endpoint (or from one decision point to another).
A control flow graph (or simply, flow graph) is a directed graph which represents the
control structure of a program or module. control flow graph (V, E) has V number of
nodes/vertices and E number of edges in it. A control graph can also have :
Objective:
1. To design test cases that cover all the independent paths in the control flow graph.
2. Ensure maximum coverage of branches, loops, and decision points.
1. An independent path introduces at least one new edge or node that has not been
traversed before in any other path.
2. The number of independent paths is determined by the Cyclomatic Complexity of
the program.
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
Eg:
Cyclomatic complexity gives the minimum number of test cases needed to cover all
paths.
Analyze the graph to determine paths that cover new edges or nodes.
Step 4: Design Test Cases: Finally, after obtaining the independent paths, test cases can
be designed where each test case represents one or more independent paths.
Step 5: Execute Test Cases: Run the program with the designed inputs and verify the
outputs.
ACHIEVABLE PATHS
In software testing, an achievable path is a path that has a solution. A path that doesn't have a
solution is considered unachievable. The process of finding a set of solutions to a path predicate
expression is called path sensitization.
We want to select and test enough paths to achieve a satisfactory notion of test completeness
such as C1+C2.Extract the programs control flowgraph and select a set of tentative covering
paths.
For any path in that set, interpret the predicates along the path as needed to express them in
terms of the input vector. In general individual predicates are compound or may become
compound as a result of interpretation.
Trace the path through, multiplying the individual compound predicates to achieve a boolean
expression such as
ADFGHIJKL+AEFGHIJKL+BCDFGHIJKL+BCEFGHIJKL
Each product term denotes a set of inequalities that if solved will yield an input vector that will drive
the routine along the designated path.Solve any one of the inequality sets for the chosen path and
you have found a set of input values for the path.If you can find a solution, then the path is
achievable.If you cant find a solution to any of the sets of inequalities, the path is un achievable.
PATH INSTRUMENTATION
Path instrumentation in path testing refers to the process of inserting additional code or
mechanisms (called instrumentation) into a program to collect information about the paths taken
during its execution. This helps determine whether specific paths in the control flow graph are
executed and assists in verifying test coverage.
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
Co-incidental Correctness: The coincidental correctness stands for achieving the desired
outcome for wrong reason.
The above figure is an example of a routine that, for the (unfortunately) chosen input value (X = 16),
yields the same outcome (Y = 2) no matter which case we select. Therefore, the tests chosen this
way will not tell us whether we have achieved coverage. For example, the five cases could be totally
jumbled and still the outcome would be the same. Path Instrumentation is what we have to do to
confirm that the outcome was achieved by the intended path.
An interpretive trace program is one that executes every statement in order and records the
intermediate values of all calculations, the statement labels traversed etc.
If we run the tested routine under a trace, then we have all the information we need to confirm
the outcome and, furthermore, to confirm that it was achieved by the intended path.
The trouble with traces is that they give us far more information than we need. In fact, the
typical trace program provides so much information that confirming the path from its massive
output dump is more work than simulating the computer by hand to confirm the path.
A simple and effective form of instrumentation is called a traversal marker or link marker.
Name every link by a lower case letter.
Instrument the links so that the link's name is recorded when the link is executed.
The succession of letters produced in going from the routine's entry to its exit should, if there are
no bugs, exactly correspond to the path name.
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
Why Single Link Markers aren't enough: Unfortunately, a single link marker may not do
the trick because links can be chewed by open bugs.
We intended to traverse the ikm path, but because of a rampaging GOTO in the middle of the m link,
we go to process B. If coincidental correctness is against us, the outcomes will be the same and we
won't know about the bug.
The solution to the problem of single link marker method is to implement two markers per link:
one at the beginning of each link and on at the end.
The two link markers now specify the path name and confirm both the beginning and end of the
link.
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
(iv) Link Counter: A less disruptive (and less informative) instrumentation method is based
on counters. Instead of a unique link name to be pushed into a string when the link is traversed, we
simply increment a link counter. We now confirm that the path length is as expected. The same
problem that led us to double link markers also leads us to double link counters.
(iv) Rehosting:
Path testing with C1+C2 coverage is a powerful tool for rehosting old software.
We get a very powerful, effective, rehosting process when C 1+C2 coverage is used in
conjunction with automatic or semiautomatic structural test generators.
Software is rehosted because it is no longer cost effective to support the environment in
which it runs.
The objective of rehosting is to change the operating environment and not the rehosted
software.
Rehosting from one COBOL environment to another is easy by comparison.
Rehosted software can be modified to improve efficiency and/or to implement new
functionality, which had been difficult in the old environments.
The test suites(collection) and all outcomes of the old environment become the specification
for the rehosted software.
The systems design documentation should contain an overview section, that details the
main transaction flows.
Detailed transaction flows are a mandatory prerequisite to the rational design of a
systems functional test.
Ask the designers to relate every flow to the specification and to show how that
transaction, directly or indirectly, follows from the requirements.
Make transaction flow testing the corner stone of system functional testing, just as path
testing is the corner stone of unit testing.
Select additional flow paths for loops, extreme values, and domain boundaries.
Design more test cases to validate all births and deaths.
Publish and distribute the selected test paths through the transaction flows as early as
possible, so that they will exert the maximum beneficial effect on the project.
Unit III
Data Flow Testing Strategies - Domain Testing: Domains and Paths – Domains and Interface
Testing.
Data flow testing is the name given to 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 data objects.
For example, pick enough paths to assure that every data object has been initialized prior to
use or that all defined objects have been used for something.
The source code consists of data declaration statements-that is statements that define data
structures, individual objects, initial or default rules and attributes
We will use a control graph to show what happens to data objects of interest at that moment.
Our objective is to expose deviations between the data flows we have and the data flows we
want.
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
Defined (d):
Usage (u):
A variable is used for computation (c) when it appears on the right hand side of an
assignment statement.
A file record is read or written.
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
In addition to the two letter situations, there are six single letter situations.
We will use a leading dash to mean that nothing of interest (d,k,u) occurs prior to the action
noted along the entry-exit path of interest.
A trailing dash to mean that nothing happens after the point of interest to the exit.
They possible anomalies are:
1. -k :- possibly anomalous because from the entrance to this point on the path, the
variable had not been defined. We are killing a variable that does not exist.
2. -d :- okay. This is just the first definition along this path.
3. -u :- possibly anomalous. Not anomalous if the variable is global and has been
previously defined.
4. k- :- not anomalous. The last thing done on this path was to kill the variable.
5. d- :- possibly anomalous. The variable was defined and not used on this path. But this could
be a global definition.
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
6. u- :- not anomalous. The variable was used but not killed on this path. Although this
sequence is not anomalous, it signals a frequent kind of bug. If d and k mean dynamic
storage allocation and return respectively, this could be an instance in which a dynamically
allocated object was not returned to the pool after use.
Data flow anomaly model prescribes that an object can be in one of four distinct states:
o K :- undefined, previously killed, does not exist
o D :- defined but not yet used for anything
o U :- has been used for computation or in predicate
o A :- anomalous
These capital letters (K, D, U, A) denote the state of the variable and should not be confused
with the program action, denoted by lower case letters.
Unforgiving Data - Flow Anomaly Flow Graph: Unforgiving model, in which once a
variable becomes anomalous it can never return to a state of grace.
Assume that the variable starts in the K state - that is, it has not been defined or does not
exist. If an attempt is made to use it or to kill it (e.g., say that we're talking about opening, closing,
and using files and that 'killing' means closing), the object's state becomes anomalous (state A) and,
once it is anomalous, no action can return the variable to a working state.
If it is defined (d), it goes into the D, or defined but not yet used, state. If it has been defined
(D) and redefined (d) or killed without use (k), it becomes anomalous, while usage (u) brings it to
the U state. If in U, redefinition (d) brings it to D, u keeps it in U, and k kills it.
Forgiving model is an alternate model where redemption (recover) from the anomalous state
is possible.
This graph has three normal and three anomalous states and he considers the kk
sequence not to be anomalous. The difference between this state graph and Figure 3.5 is that
redemption is possible. A proper action from any of the three anomalous states returns the
variable to a useful working state.
The point of showing you this alternative anomaly state graph is to demonstrate that the specifics of
an anomaly depends on such things as language, application, context, or even your frame of mind.
In principle, you must create a new definition of data flow anomaly (e.g., a new state graph) in
each situation. You must at least verify that the anomaly definition behind the theory or
imbedded in a data flow anomaly test tool is appropriate to your situation.
3. Records and pointers : In many applications we create the files and their names
dynamically and there is no way to determine without execution
4. Dynamic subroutine or function names in a call : A subroutine or function name is a
dynamic variable in a call
5. False Anomalies
6. Concurrency, Interrupts and system issues
Data Flow Model:
The data flow model is based on the program's control flow graph
Here we annotate each link with symbols (for example, d, k, u, c, p) or sequences of symbols
(for example, dd, du, ddd) that denote the sequence of data operations on that link with respect
to the variable of interest. Such annotations are called link weights.
The control flow graph structure is same for every variable: it is the weights that change.
Figure 3.8 shows that the control flow graph for the program and the node labels and
marked the decision nodes with the variables.
Figure 3.9 shows that this control flowgraph annotated for variables X and Y and there
there is a dcc on the first link (1,3)
Figure 3.10 shows all the predicate uses for the Z variable and Figure 3.11shows the
control flow graph for V data flow .
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.
In other words, data flow strategies require data-flow link weights (d,k,u,c,p).
Data Flow Testing Strategies are based on selecting test path segments (also called
sub paths) that satisfy some characteristic of data flows for all data objects.
Terminology:
Loop-Free Path Segment is a path segment for which every node in it is visited atmost
once. For Example, path (4,5,6,7,8,10) in Figure 3.10 is loop free, but path
(10,11,4,5,6,7,8,10,11,12) is not because nodes 10 and 11 are each visited twice.
Simple path segment is a path segment in which at most one node is visited twice. For
example, in Figure 3.10, (7,4,5,6,7) is a simple path segment. A simple path segment is either loop-
free or if there is a loop, only one node is involved.
A du path from node i to k is a path segment such that if the last link has a computational
use of X, then the path is simple and definition-clear; if the penultimate (last but one) node is j - that
is, the path is (i,p,q,...,r,s,t,j,k) and link (j,k) has a predicate use - then the path from i to j is both
loop-free and definition-clear.
The Strategies
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
The structural test strategies discussed below are based on the program's control flowgraph. They
differ in the extent to which predicate uses and/or computational uses of variables are included in
the test set. Various types of data flow testing strategies in decreasing order of their effectiveness
are:
All - du Paths (ADUP): The all-du-paths (ADUP) strategy is the strongest data- flow testing
strategy discussed here. It requires that every du path from every definition of every variable to
every use of that definition be exercised under some test.
For variable X and Y:In Figure 3.9, because variables X and Y are used only on link (1,3), any test
that starts at the entry satisfies this criterion (for variables X and Y, but not for all
variables as required by the strategy).
For variable Z: The situation for variable Z (Figure 3.10) is more complicated
because the variable is redefined in many places. For the definition on link (1,3) we must exercise
paths that include subpaths (1,3,4) and (1,3,5). The definition on link (4,5) is covered by any path
that includes (5,6), such as subpath (1,3,4,5,6, ...). The (5,6) definition requires paths that
include subpaths (5,6,7,4) and (5,6,7,8).
For variable V: Variable V (Figure 3.11) is defined only once on link (1,3). Because V has a
predicate use at node 12 and the subsequent path to the end must be forced for both directions at
node 12, the all-du-paths strategy for this variable requires that we exercise all loop-free entry/exit
paths and at least one path that includes the loop caused by (11,4). Note that we must test paths that
include both subpaths (3,4,5) and (3,5) even though neither of these has V definitions. They must be
included because they provide alternate du paths to the V use on link (5,6). Although (7,4) is not
used in the test set for variable V, it will be included in the test set that covers the predicate uses of
array variable V() and U.
The all-du-paths strategy is a strong criterion, but it does not take as many tests as it might seem at
first because any one test simultaneously satisfies the criterion for several definitions and uses of
several different variables.
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
All Uses Startegy (AU):The all uses strategy is that at least one definition clear path from every
definition of every variable to every use of that definition be exercised under some test. Just as we
reduced our ambitions by stepping down from all paths (P) to branch coverage (C2), say, we can
reduce the number of test cases by asking that the test set should include at least one path segment
from every definition to every use that can be reached by that
definition.
For variable V: In Figure 3.11, ADUP requires that we include subpaths (3,4,5) and (3,5) in
some test because subsequent uses of V, such as on link (5,6), can be reached by either alternative.
In AU either (3,4,5) or (3,5) can be used to start paths, but we don't have to use both. Similarly, we
can skip the (8,10) link if we've included the (8,9,10) subpath. Note the hole. We must include
(8,9,10) in some test cases because that's the only way to reach the c use at link (9,10) - but suppose
our bug for variable V is on link (8,10) after all? Find a covering set of paths under AU for Figure
3.11.
All p-uses/some c-uses strategy (APU+C) : For every variable and every definition of that
variable, include at least one definition free path from the definition to every predicate use; if there
are definitions of the variables that are not covered by the above prescription, then add
computational use test cases as required to cover every definition.
For variable Z:In Figure 3.10, for APU+C we can select paths that all take the upper link (12,13)
and therefore we do not cover the c-use of Z: but that's okay according to the strategy's definition
because every definition is covered. Links (1,3), (4,5), (5,6), and (7,8) must be included because
they contain definitions for variable Z. Links (3,4), (3,5), (8,9), (8,10), (9,6), and (9,10) must be
included because they contain predicate
uses of Z. Find a covering set of test cases under APU+C for all variables in this example-it only
takes two tests.
All c-uses/some p-uses strategy (ACU+P) : The all c-uses/some p-uses strategy (ACU+P) is to
first ensure coverage by computational use cases and if any definition is not covered by the
previously selected paths, add such predicate use cases as are needed to assure that every
definition is included in some test.
For variable Z: In Figure 3.10, ACU+P coverage is achieved for Z by path (1,3,4,5,6,7,8,10,
11,12,13[lower], 2), but the predicate uses of several definitions are not covered. Specifically, the
(1,3) definition is not covered for the (3,5) p-use, the (7,8) definition is not covered for the (8,9),
(9,6) and (9, 10) p-uses.
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
The above examples imply that APU+C is stronger than branch coverage but ACU+P may be weaker
than, or incomparable to, branch coverage.
All Definitions Strategy (AD) : The all definitions strategy asks only every definition of
every variable be covered by atleast one use of that variable, be that use a computational use or
a predicate use.
For variable Z: Path (1,3,4,5,6,7,8, . . .) satisfies this criterion for variable Z, whereas any entry/exit
path satisfies it for variable V. From the definition of this strategy we would expect it to be weaker
than both ACU+P and APU+C.
All Predicate Uses (APU), All Computational Uses (ACU) Strategies : The all predicate uses
strategy is derived from APU+C strategy by dropping the requirement that we include a c-use for
the variable if there are no p-uses for the variable. The all computational uses strategy is derived
from ACU+P strategy by dropping the requirement that we include a p-use for the variable if there
are no c-uses for the variable. It is intuitively obvious that ACU should be weaker than ACU+P and
that APU should be weaker than APU+C.
A (static) program slice is a part of a program (e.g., a selected set of statements) defined
with respect to a given variable X (where X is a simple variable or a data vector) and a
statement i: it is the set of all statements that could (potentially, under static analysis) affect
the value of X at statement i - where the influence of a faulty statement could result from an
improper computational use or predicate use of some other variables at prior statements.
If X is incorrect at statement i, it follows that the bug must be in the program slice for X
with respect to i
A program dice is a part of a slice in which all statements which are known to be correct
have been removed.
In other words, a dice is obtained from a slice by incorporating information obtained
through testing or experiment (e.g., debugging).
The debugger first limits her scope to those prior statements that could have caused the
faulty value at statement i (the slice) and then eliminates from further consideration those
statements that testing has shown to be correct.
Debugging can be modeled as an iterative procedure in which slices are further refined by
dicing, where the dicing information is obtained from ad hoc tests aimed primarily at
eliminating possibilities. Debugging ends when the dice has been reduced to the one faulty
statement.
Dynamic slicing is a refinement of static slicing in which only statements on achievable
paths to the statement in question are included.
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
Comparison of number of test cases for ACU, APU, AU & ADUP by Weyuker using
ASSET testing system
Comparison of # test cases for ACU, APU, AU & ADUP by Shimeall & Levenson
Commercial tools :
The Model:
Before doing whatever it does, a routine must classify the input and set it moving
on the right path
An invalid input (e.g., value too big) is just a special processing case called
'reject'.
The input then passses to a hypothetical subroutine rather than on
calculations.
In domain testing, we focus on the classification aspect of the routine rather than
on the calculations.
Structural knowledge is not needed for this model - only a consistent, complete
specification of input values for each case.
We can infer that for each case there must be atleast one path to process
that case.
A Domain Is A Set:
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
For example, in the statement IF x>0 THEN ALPHA ELSE BETA we know
that numbers greater than zero belong to ALPHA processing domain(s) while
zero and smaller numbers belong to BETA domain(s).
A domain may have one or more boundaries - no matter how many variables define
it.
For example, if the predicate is x2 + y2 < 16, the domain is the inside of a circle of
radius 4 about the origin. Similarly, we could define a spherical domain with one
boundary but in three variables.
Domains are usually defined by many boundary segments and therefore by many
predicates. i.e. the set of interpreted predicates traversed on that path (i.e., the path's
predicate expression) defines the domain's boundaries.
1. A Domain Closure:
A domain boundary is closed with respect to a domain if the points on the boundary
belong to the domain.
If the boundary points belong to some other domain, the boundary is said to be open.
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
Figure 4.2 shows three situations for a one-dimensional domain - i.e., a domain
defined over one input variable; call it x
The importance of domain closure is that incorrect closure bugs are frequent
domain bugs. For example, x >= 0 when x > 0 was intended.
2. Domain Dimensionality:
3. Bug Assumption:
The bug assumption for the domain testing is that processing is okay but the domain
definition is wrong.
An incorrectly implemented domain means that boundaries are wrong, which
may in turn mean that control flow predicates are wrong.
Many different bugs can result in domain errors. Some of them are:
1. Double Zero Representation :In computers or Languages that have a
distinct positive and negative zero, boundary errors for negative zero are
common.
2. Floating point zero check:A floating point number can equal zero only if
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
5. Co-incidental Correctness:
Domain testing isn't good at finding bugs for which the outcome is correct for the
wrong reasons. If we're plagued by coincidental correctness we may misjudge an incorrect
boundary. Note that this implies weakness for domain testing when dealing with routines
that have binary outcomes (i.e., TRUE/FALSE)
6. Representative Outcome:
Domain testing is an example of partition testing. Partition-testing strategies divide
the program's input space into domains such that all inputs within a domain are equivalent
(not equal, but equivalent) in the sense that any input represents all inputs in that domain.
If the selected input is shown to be correct by a test, then processing is presumed
correct, and therefore all inputs within that domain are expected (perhaps unjustifiably) to
be correct. Most test techniques, functional or structural, fall under partition testing and
therefore make this representative outcome assumption. For example, x 2 and 2x are equal for
x = 2, but the functions are different. The functional differences between adjacent domains
are usually simple, such as x + 7 versus x + 9, rather than x2 versus 2x.
This predicate specifies one boundary equation (x = 0) but alternates closure, putting
it in one or the other domain depending on whether y < 7 or y >
14. Treat compound predicates with respect because they’re more complicated than they
seem.
Whatever the bug is, it will not change the functional form of the boundary
predicate. For example, if the predicate is ax >= b, the bug will be in the value of a or b but
it will not change the predicate to ax >= b, say.
Most papers on domain testing, assume linear boundaries - not a bad assumption
because in practice most boundary predicates are linear.
NICE DOMAINS:
Some important properties of nice domains are: Linear, Complete, Systematic, And
Orthogonal, Consistently closed, Convex and simply connected.
To the extent that domains have these properties domain testing is easy as testing gets.
The bug frequency is lesser for nice domain than for ugly domains.
The impact on testing stems from the fact that it takes only two points to determine a
straight line and three points to determine a plane and in general n+ 1 point to determine an
n-dimensional hyper plane.
In practice more than 99.99% of all boundary predicates are either linear or can be
linearized by simple variable transformations.
Complete Boundaries:
Nice domain boundaries are complete in that they span the number space from plus to minus
infinity in all dimensions.
Figure 4.4 shows some incomplete boundaries. Boundaries A and E have gaps.
Such boundaries can come about because the path that hypothetically corresponds to them is
unachievable, because inputs are constrained in such a way that such values can't exist,
because of compound predicates that define a single boundary, or because redundant
predicates convert such boundary values into a null set.
The advantage of complete boundaries is that one set of tests is needed to confirm the
boundary no matter how many domains it bounds.
If the boundary is chopped up and has holes in it, then every segment of that boundary must
be tested for every domain it bounds.
Systematic Boundaries:
Systematic boundary means that boundary inequalities related by a simple function such as
a constant.
In Figure 4.3 for example, the domain boundaries for u and v differ only by a constant.
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
where fi is an arbitrary linear function, X is the input vector, ki and c are constants, and g(i,c) is a
decent function over i and c that yields a constant, such as k + ic.
The first example is a set of parallel lines, and the second example is a set of systematically
(e.g., equally) spaced parallel lines (such as the spokes of a wheel, if equally spaced in
angles, systematic).
If the boundaries are systematic and if you have one tied down and generate tests for it, the
tests for the rest of the boundaries in that set can be automatically generated.
Orthogonal Boundaries:
Two boundary sets U and V (See Figure 4.3) are said to be orthogonal if every inequality in
V is perpendicular to every inequality in U.
If two boundary sets are orthogonal, then they can be tested independently
In Figure 4.3 we have six boundaries in U and four in V. We can confirm the boundary
properties in a number of tests proportional to 6 + 4 = 10 (O(n)). If we tilt the boundaries to
get Figure 4.5,
we must now test the intersections. We've gone from a linear number of cases to a quadratic:
from O(n) to O(n2).
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
Actually, there are two different but related orthogonality conditions. Sets of boundaries can be
orthogonal to one another but not orthogonal to the coordinate axes (condition 1), or boundaries can
be orthogonal to the coordinate axes (condition 2).
Closure Consistency:
Figure 4.6 shows another desirable domain property: boundary closures are consistent and
systematic.
The shaded areas on the boundary denote that the boundary belongs to the domain in
which the shading lies - e.g., the boundary lines belong to the domains on the right.
Consistent closure means that there is a simple pattern to the closures - for example,
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
using the same relational operator for all boundaries of a set of parallel boundaries.
CONVEX:
A geometric figure (in any number of dimensions) is convex if you can take two arbitrary
points on any two different boundaries, join them by a line and all points on that line lie
within the figure.
Simply Connected:
Nice domains are simply connected; that is, they are in one piece rather than pieces all over
the place interspersed with other domains.
Consider domain boundaries defined by a compound predicate of the (Boolean) form ABC.
Say that the input space is divided into two domains, one defined by ABC and, therefore,
the other defined by its negation.
For example, suppose we define valid numbers as those lying between 10 and 17 inclusive.
The invalid numbers are the disconnected domain consisting of numbers less than 10 and
greater than 17.
UGLY DOMAINS:
Some domains are born ugly and some are uglified by bad specifications.
If the ugliness results from bad specifications and the programmer's simplification is
harmless, then the programmer has made ugly good.
But if the domain's complexity is essential (e.g., the income tax code), such
"simplifications" constitute bugs.
Figure 4.7c shows overlapped domains and Figure 4.7d shows dual closure assignment.
The programmer's and tester's reaction to complex domains is the same - simplify
There are three generic cases: concavities, holes and disconnected pieces.
Programmers introduce bugs and testers misdesign test cases by: smoothing out concavities
(Figure 4.8a), filling in holes (Figure 4.8b), and joining disconnected pieces (Figure 4.8c).
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
1. Domains are defined by their boundaries; therefore, domain testing concentrates test points on or
near boundaries.
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
2. Classify what can go wrong with boundaries, then define a test strategy for each case. Pick
enough points to test for all recognized kinds of boundary errors.
3. Because every boundary serves at least two different domains, test points used to check one
domain can also be used to check adjacent domains. Remove redundant test points.
4. Run the tests and by posttest analysis (the tedious part) determine if any boundaries are faulty
and if so, how.
5. Run enough tests to verify every boundary of every domain.
An interior point (Figure 4.10) is a point in the domain such that all points within an arbitrarily
small distance (called an epsilon neighborhood) are also in the domain.
A boundary point is one such that within an epsilon neighborhood there are points both in the
domain and not in the domain.
An extreme point is a point that does not lie between any two other arbitrary but distinct
points of a (convex) domain.
Figure 4.12 shows generic domain bugs: closure bug, shifted boundaries, tilted
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
Figure 4.13 shows possible domain bugs for a one-dimensional open domain
boundary.
The closure can be wrong (i.e., assigned to the wrong domain) or the boundary (a
point in this case) can be shifted one way or the other, we can be missing a boundary, or
we can have an extra boundary.
In Figure 4.13a we assumed that the boundary was to be open for A. The bug we're looking
for is a closure error, which converts > to >= or < to <= (Figure 4.13b). One test (marked x)
on the boundary point detects this bug because processing for that point will go to domain A
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
rather than B.
In Figure 4.13c we've suffered a boundary shift to the left. The test point we used for closure
detects this bug because the bug forces the point from the B domain, where it should be, to
A processing. Note that we can't distinguish between a shift and a closure error, but we do
know that we have a bug.
Figure 4.13d shows a shift the other way. The on point doesn't tell us anything because the
boundary shift doesn't change the fact that the test point will be processed in B. To detect
this shift we need a point close to the boundary but within
A. The boundary is open, therefore by definition, the off point is in A (Open Off Inside).
The same open off point also suffices to detect a missing boundary because what should
have been processed in A is now processed in B.
To detect an extra boundary we have to look at two domain boundaries. In this context an
extra boundary means that A has been split in two. The two off points that we selected
before (one for each boundary) does the job. If point C had been a closed boundary, the on
test point at C would do it.
For closed domains look at Figure 4.14. As for the open boundary, a test point on the
boundary detects the closure bug. The rest of the cases are similar to the open boundary,
except now the strategy requires off points just outside the domain.
Figure 4.15 shows possible domain boundary bugs for a two-dimensional domain.
A and B are adjacent domains and the boundary is closed with respect to A, which means
that it is open with respect to B.
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
1. Closure Bug: Figure 4.15a shows a faulty closure, such as might be caused by using a
wrong operator (for example, x >= k when x > k was intended, or vice versa). The two on
points detect this bug because those values will get B rather than A processing.
2. Shifted Boundary: In Figure 4.15b the bug is a shift up, which converts part of domain B
into A processing, denoted by A'. This result is caused by an incorrect constant in a
predicate, such as x + y >= 17 when x + y >= 7 was intended. The off point (closed off
outside) catches this bug. Figure 4.15c shows a shift down that is caught by the two on
points.
3. Tilted Boundary: A tilted boundary occurs when coefficients in the boundary inequality
are wrong. For example, 3x + 7y > 17 when 7x + 3y > 17 was intended. Figure 4.15d has a
tilted boundary, which creates erroneous domain segments A' and B'. In this example the
bug is caught by the left on point.
4. Extra Boundary: An extra boundary is created by an extra predicate. An extra boundary
will slice through many different domains and will therefore cause many test failures for the
same bug. The extra boundary in Figure 4.15e is caught by two on points, and depending on
which way the extra boundary goes, possibly by the off point also.
5. Missing Boundary: A missing boundary is created by leaving a boundary predicate out. A
missing boundary will merge different domains and will cause many test failures although
there is only one bug. A missing boundary, shown in Figure 4.15f, is caught by the two on
points because the processing for A and B is the same - either A or B processing.
The above figure 6.16 summarizes domain testing for two dimensional domains it shows a
domain all but one of whose boundaries are closed.
There are two on points (closed circles) for each segment and one off point(open circle)
The on points for two adjacent boundary segments are shared if both segments are open or if
both are closed.
Procedure For Testing: The procedure is conceptually is straight forward. It can be done by hand
for two dimensions and for a few domains and practically impossible for more than two variables.
4. For p binary predicates, there are at most 2 p combinations of TRUE-FALSE values and therefore, at
most 2p domains. Find the set of all non null domains. The result is a boolean expression in the
predicates consisting a set of AND terms joined by OR's. For example ABC+DEF+GHI Where the
capital letters denote predicates. Each
product term is a set of linear inequality that defines a domain or a part of a multiply connected domains.
5. Solve these inequalities to find all the extreme points of each domain using any of the linear
programming methods.
The basic domain testing strategy is N*1 strategy because it uses N on points and one off point
Clarke strategy uses N on and N off points per boundary segment(N*N strategy) and
strategies based on the vertex
Richardson and Clarke used the generalization strategy i.e, partition and analysis which includes
verification, both structural and functional information
Introduction:
We defined integration testing as testing the correctness of the interface between two otherwise
correct components.
Components A and B have been demonstrated to satisfy their component tests, and as part of the
act of integrating them we want to investigate possible inconsistencies across their interface.
Interface between any two components is considered as a subroutine call.
We're looking for bugs in that "call" when we do interface testing.
Let's assume that the call sequence is correct and that there are no type incompatibilities.
For a single variable, the domain span is the set of numbers between (and including) the smallest
value and the largest value. For every input variable we want (at least): compatible domain spans
and compatible closures (Compatible but need not be Equal).
The set of output values produced by a function is called the range of the function, in contrast
with the domain, which is the set of input values over which the function is defined.
For most testing, our aim has been to specify input values and to predict and/or confirm output
values that result from those inputs.
Interface testing requires that we select the output values of the calling routine i.e. caller's range
must be compatible with the called routine's domain.
An interface test consists of exploring the correctness of the following mappings:
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
caller domain --> caller range(caller unit test) caller range --> called domain(integration
test) domain --> called range (called unit test)
Closure Compatibility:
Assume that the caller's range and the called domain spans the same numbers - for example,
0 to 17.
Figure 4.16 shows the four ways in which the caller's range closure and the called's domain
closure can agree.
The thick line means closed and the thin line means open. Figure 4.16 shows the four cases
consisting of domains that are closed both on top
(17) and bottom (0), open top and closed bottom, closed top and open bottom, and open top
and bottom.
Figure 4.17 shows the twelve different ways the caller and the called can disagree about closure.
Not all of them are necessarily bugs. The four
cases in which a caller boundary is open and the called is closed (marked with a "?") are
probably not buggy. It means that the caller will not supply such values but the called can accept
them.
Span Compatibility:
In all cases, the caller's range is a subset of the called's domain. That's not necessarily a bug.
The routine is used by many callers; some require values inside a range and some don't. This
kind of span incompatibility is a bug only if the caller expects the called routine to validate the
called number for the caller.
Figure 4.19a shows the opposite situation, in which the called routine's domain has a smaller
span than the caller expects. All of these examples are buggy.
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
In Figure 4.19b the ranges and domains don't line up; hence good values are rejected, bad values
are accepted, and if the called routine isn't robust enough, we have crashes.
Figure 4.19c combines these notions to show various ways we can have holes in the domain:
these are all probably buggy.
Linearizing Transformations
We often convert non linear boundaries to equivalent linear boundaries this is done by applying linear
transformations
The methods are
1. Polynomials: A boundary is specified by a polynomial or multinomial in several variables
for example each term x,x2,x3 is replaced by y1=x,y2=x2
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
Coordinate transformations
Nice boundaries are parallel sets .Parallel boundaries sets are sets of linearly related boundaries they
differ only by constant
It is an O(n2) procedure for n boundary equations
Generally we have n equalities and m variables and convert the inequalities into equalities
Select the equation and apply a procedure called Gram-schmidt orthogonalization which transforms
original set of variables x into a new
The input variable is going to be linearized and orthogonalizes so that inequalities can be removed
A good coordinate systems can break the back of many tough problems. Make the domain design as
explicit
Look the transformations to new, orthogonal, coordinate sets therefore it is easy to test
Testers will test the domains based on the specifications to a minimal set.
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
these, the fact that nesting is ignored (nested loops, nested IF-THEN-ELSE, and so on) is probably the most
serious critique. A Basic statement such as
Levitin, in his incisive critique of linguistic metrics (LEVI86), makes a strong argument for the use of program
token count rather than lines of code, statement count, or Halstead’s length. A token in a programming language
is the basic syntactic unit from which programs are constructed. Tokens include keywords, labels, constants,
strings, and variable names. Token counting is easy because the first stage of compilation is to translate the
source code into equivalent numerical tokens. The number of tokens is easily obtained as a by-product of
compilation. Token count gets around the subjectivity problems we have with statement counts and lines of code.
4. STRUCTURAL METRICS
4.1. General
Structural metrics take the opposite viewpoint of linguistic metrics. Linguistic complexity is ignored while
attention is focused on control-flow or data-flow complexity—metrics based on the properties of flowgraph
models of programs. Graph theory is more than a half-century old but the study of graph-theoretic problems and
metrics goes back three centuries: see MAYE72. If it’s a graph (i.e., it consists of links and nodes) then there are
hundreds of interesting metrics that can be applied to it: metrics whose mathematical properties have been
studied in minute detail. The thrust of structural metrics research has not been so much the invention of new
graph-theoretic metrics but the investigation of the utility of known graph-theoretic metrics. McCabe’s use of the
cyclomatic number (MCCA76) is an archetypal example.
4.2.1. Definition
M = L — N + 2P
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
where
P = the number of disconnected parts of the graph (e.g., a calling program and a subroutine)
The number M that appeared alongside the flowgraphs in Chapter 3 was McCabe’s metric for that flowgraph. In
all the examples, except for the one on page 73, there was only one connected part, and consequently the value of
P was 1. Figure 7.1 shows some more examples and their associated M values.
Evaluate the cyclomatic complexity of the program’s design (e.g., from the design control flowgraph). As part of
self-inspection, reevaluate the complexity by counting decisions in the code. Any significant difference should be
explained, because it’s more likely that the difference is due to a missing path, an extra path, or an unplanned
deviation from the design than to something else. Having verified the code’s cyclomatic complexity, compare the
number of planned test cases to the code’s complexity. In particular, count how many test cases are intended to
provide coverage. If the number of covering test cases is less than the cyclomatic complexity, there is reason for
caution, because one of the following may be true:
1. You haven’t calculated the complexity correctly. Did you miss a decision?
2. Coverage is not really complete; there’s a link that hasn’t been covered.
3. Coverage is complete, but it can be done with a few more but simpler paths.
McCabe’s metric can be used to help decide whether it pays to make a piece of code which is common to two or
more links into a subroutine. Consider the graph of Figure 7.3. The program has a common part that consists of
Nc nodes and Lc links. This is the part being considered for conversion to a subroutine. This common part recurs
k times in the body of the main program. The main program has Nm nodes and Lm links over and above the
common part.
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
Subnodes 0 Nc + 2
Sublinks 0 Lc
Subcomplexity 0 L c – Nc – 2 + 2 = L c – Nc = M
.2.4. A Refinement
Myers (MYER77) points out a weakness of McCabe’s metric and suggests the use of a refinement thereto. A
decision statement in languages such as FORTRAN can contain a compound predicate of the form: IF A & B &
C THEN . . . . A statement such as this could be implemented as a string of IFs, resulting in a different
complexity measure. Figure 7.4 shows three alternate, equivalent, representations of the same IF-THEN-ELSE
statement. If the compound predicate is used in a single statement as in the first case, the complexity of the
construct is only two, but if it is broken down into its constituent parts, the complexity increases to four.
However, intuitively, all three constructs should have the same complexity. The refinement consists of
accounting for each term of the predicate expression separately. For a predicate expression of the form A&B&C .
. . , each predicate should be counted as if it was a decision. In more complicated expressions, such as A&B&C
OR D&E . . . , again count each predicate. If a predicate appears more than once in an expression, you can take a
pessimistic point of view and count each appearance or a slightly optimistic point of view and count only the first
appearance.
Statistics on how well McCabe’s metric correlates with design, test, and debugging difficulty are encouraging
(BELF79, CHEN78A, CURT79A, ENDR75, FEUE79A, FEUE79B, LIPO77, SCHN79A, SCHN79B,
SCHN79D, SHEP79C, THAY76, WALS79, ZOLN77).* The reported results confirm the utility of McCabe’s
metric as a convenient rule of thumb that is significantly superior to statement count.
*
Not all of these references provide direct information for McCabe’s metric. Some (ENDR75, THAY76) provide
correlations to decision counts and similar metrics that can be converted to McCabe’s metric. Note also that if we
forget the structural basis of cyclomatic complexity and merely use equivalent binary decision count or simple
predicate count, then this metric can be obtained by purely linguistic means.
Many other structural metrics have been proposed and investigated. Chen (CHEN78A) combines structural
properties with information theoretic concepts. Gong (GONG85) combines decisions and nesting depth.
Rodriguez and Tsai (RODR86) apply structural concepts to data flowgraphs, as do Tai (TAIK84) and Tsai et al.
(TSAI86). Van Verth (VANV87) proposes using a combination of control flow and data flow, as does
Whitworth (WHIT80B). This list is incomplete as the number of papers on alternate complexity metrics is as
great as those on alternate testing strategies. The problem with these metrics is that confirming statistics on their
usefulness is lacking. It is intuitively clear that cyclomatic complexity over data flowgraphs should be as useful a
metric as cyclomatic complexity over control flowgraphs but corroboration is still lacking (OVIE80).
. HYBRID METRICS
The appearance of McCabe’s and Halstead’s metrics spurred the proposal, development, refinement, and
validation of a host of similar and related metrics, or totally different alternatives based on different assumptions.
Some of those cited below preceded McCabe’s and Halstead’s work and some followed. It’s too early to tell
which will be experimentally confirmed independently over a range of projects and applications, no matter how
rational and sensible their basis might be. Some of the more interesting and promising alternatives are presented
in BAKE79A, BAKE80, BELF79, CHAP79, CHEN78A, DEYO79, EVAN84, FEUE79B, GILB77, LIPO77,
MCCL78B, PAIG80, RAMA88, SCHN79B, VANV87, WHIT80B, and ZONL77. Most of these metrics and
their variations recognize one or more weaknesses in the popular metrics and seek to measure reliability and/or
predict bug counts through refinement or alternative formulation of the problem. It is inevitable that increased
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
predictability and fidelity can only be achieved at a cost of increased sophistication, complexity of evaluation,
and difficulty of use.
MOTIVATION:
o Any question about a program can be cast into an equivalent question about an appropriate
flowgraph.
o Most software development, testing and debugging tools use flow graphs analysis techniques.
PATH PRODUCTS:
o Using link names as weights, we then convert the graphical flow graph into an equivalent
algebraic like expressions which denotes the set of all possible paths from entry to exit for the
flow graph.
o In tracing a path or path segment through a flow graph, you traverse a succession of link names.
o The name of the path or path segment that corresponds to those links is expressed naturally by
concatenating those link names.
o For example, if you traverse links a,b,c and d along some path, the name for that path segment is
abcd. This path name is also called a path product. Figure 5.1 shows some examples:
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
PATH EXPRESSION:
o Consider a pair of nodes in a graph and the set of paths between those node.
o Denote that set of paths by Upper case letter such as X,Y. From Figure 5.1c, the members of the
path set can be listed as follows:
ac+abc+abbc+abbbc+abbbbc+...........
o The + sign is understood to mean "or" between the two nodes of interest, paths ac, or abc, or abbc,
and so on can be taken.
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
o Any expression that consists of path names and "OR"s and which denotes a set of paths between
two nodes is called a "Path Expression.".
PATH PRODUCTS:
o The name of a path that consists of two successive path segments is conveniently expressed by the
concatenation or Path Product of the segment names.
XY=abcdefghij
o Similarly,
o YX=fghijabcde
o aX=aabcde
o Xa=abcdea
XaX=abcdeaabcde
o If X and Y represent sets of paths or path expressions, their product represents the set of paths that
can be obtained by following every element of X by any element of Y in all possible ways. For
example,
o Y = uvw + z
Then,
o If a link or segment name is repeated, that fact is denoted by an exponent. The exponent's value
denotes the number of repetitions:
Similarly, if
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
X = abcde
then
X1 = abcde
X2 = abcdeabcde = (abcde)2
X3 = abcdeabcdeabcde = (abcde)2abcde
= abcde(abcde)2 = (abcde)3
RULE 1: A(BC)=(AB)C=ABC
where A,B,C are path names, set of path names or path expressions.
o The zeroth power of a link name, path product, or path expression is also needed for
completeness. It is denoted by the numeral "1" and denotes the "path" whose length is zero - that
is, the path that doesn't have any links.
o a0 = 1
o X0 = 1
PATH SUMS:
o The "+" sign was used to denote the fact that path names were part of the same set of paths.
o Links a and b in Figure 5.1a are parallel paths and are denoted by a + b. Similarly, links c and d
are parallel paths between the next two nodes and are denoted by c + d.
o The set of all paths between nodes 1 and 2 can be thought of as a set of parallel paths and denoted
by eacf+eadf+ebcf+ebdf.
o If X and Y are sets of paths that lie between the same pair of nodes, then X+Y denotes the
UNION of those set of paths. For example, in Figure 5.2:
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
The first set of parallel paths is denoted by X + Y + d and the second set by U + V + W + h + i + j. The set of all
paths in this flowgraph is f(X + Y + d)g(U + V + W + h + i + j)k
o RULE 2: X+Y=Y+X
o RULE 3: (X+Y)+Z=X+(Y+Z)=X+Y+Z
DISTRIBUTIVE LAWS:
o The product and sum operations are distributive, and the ordinary rules of multiplication apply;
that is
o e(a+b)(c+d)f=e(ac+ad+bc+bd)f = eacf+eadf+ebcf+ebdf
ABSORPTION RULE:
o If X and Y denote the same set of paths, then the union of these sets is unchanged; consequently,
o If a set consists of paths names and a member of that set is added to it, the "new" name, which is
already in that set of names, contributes nothing and can be ignored.
o For example,
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
o if X=a+aa+abc+abcd+def then
It follows that any arbitrary sum of identical path expressions reduces to the same path expression.
LOOPS:
o Loops can be understood as an infinite set of parallel paths. Say that the loop consists of a single
link b. then the set of all paths through that loop point is b0+b1+b2+b3+b4+b5+..............
o This potentially infinite sum is denoted by b* for an individual link and by X* when X is a path
expression.
o The path expression for the above figure is denoted by the notation:
ab*c=ac+abc+abbc+abbbc+................
o Evidently,
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
o It is more convenient to denote the fact that a loop cannot be taken more than a certain, say n,
number of times.
Xn = X0+X1+X2+X3+X4+X5+..................+Xn
RULES 6 - 16:
o RULE 6: Xn + Xm = Xn if n>m
RULE 6: Xn + Xm = Xm if m>n
RULE 11: 1 + 1 = 1
RULE 12: 1X = X1 = X
Following or preceding a set of paths by a path of zero length does not change the set.
RULE 13: 1n = 1n = 1* = 1+ = 1
No matter how often you traverse a path of zero length,It is a path of zero length.
The null set of paths is denoted by the numeral 0. it obeys the following rules:
If you block the paths of a graph for or aft by a graph that has no paths , there wont be any paths.
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
REDUCTION PROCEDURE:
o This section presents a reduction procedure for converting a flowgraph whose links are labeled
with names into a path expression that denotes the set of all entry/exit paths in that flowgraph. The
procedure is a node-by-node removal algorithm.
3. Remove all self-loops (from any node to itself) by replacing them with a link of the form
X*, where X is the path expression of the link in that loop.
4. Select any node for removal other than the initial or final node. Replace it with a set of
equivalent links whose path expressions correspond to all the ways you can form a product
of the set of inlinks with the set of outlinks of that node.
8. Does the graph consist of a single link between the entry node and the exit node? If yes,
then the path expression for that link is a path expression for the original flowgraph;
otherwise, return to step 4.
o A flowgraph can have many equivalent path expressions between a given pair of nodes; that is,
there are many different ways to generate the set of all paths between two nodes without affecting
the content of that set.
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
o The appearance of the path expression depends, in general, on the order in which nodes are
removed.
o The cross - term step is the fundamental step of the reduction algorithm.
o Successive applications of this step eventually get you down to one entry and one exit node. The
following diagram shows the situation at an arbitrary node that has been selected for removal:
o (a + b)(c + d + e) = ac + ad + + ae + bc + bd + be
o In the first way, we remove the self-loop and then multiply all outgoing links by Z*.
o In the second way, we split the node into two equivalent nodes, call them A and A' and put in a
link between them whose path expression is Z*. Then we remove node A' using steps 4 and 5 to
yield outgoing links whose path expressions are Z*X and Z*Y.
o Let us see by applying this algorithm to the following graph where we remove several nodes in
order; that is
o Removing the loop and then node 6 result in the following expression:
o a(bgjf)*b(c+gkh)d((ilhd)*imf(bjgf)*b(c+gkh)d)*(ilhd)*e
o You can practice by applying the algorithm on the following flowgraphs and generate their
respective path expressions:
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
APPLICATIONS:
APPLICATIONS:
o The purpose of the node removal algorithm is to present one very generalized concept- the path
expression and way of getting it.
2. Identify a property of interest and derive an appropriate set of "arithmetic" rules that
characterizes the property.
3. Replace the link names by the link weights for the property of interest. The path
expression has now been converted to an expression in some algebra, such as ordinary
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
algebra, regular expressions, or boolean algebra. This algebraic expression summarizes the
property of interest over the set of all paths.
4. Simplify or evaluate the resulting "algebraic" expression to answer the question you asked.
o The question is not simple. Here are some ways you could ask it:
o Determining the actual number of different paths is an inherently difficult problem because there
could be unachievable paths resulting from correlated and dependent predicates.
o If we know both of these numbers (maximum and minimum number of possible paths) we have a
good idea of how complete our testing is.
o Label each link with a link weight that corresponds to the number of paths that link represents.
o Also mark each loop with the maximum number of times that loop can be taken. If the answer is
infinite, you might as well stop the analysis because it is clear that the maximum number of paths
will be infinite.
o There are three cases of interest: parallel links, serial links, and loops.
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
o This arithmetic is an ordinary algebra. The weight is the number of paths in each set.
o EXAMPLE:
Each link represents a single link and consequently is given a weight of "1" to start. Lets say the outer loop will
be taken exactly four times and inner Loop Can be taken zero or three times Its path expression, with a little
work, is:
2. A: The flow graph should be annotated by replacing the link name with the maximum of
paths through that link (1) and also note the number of times for looping.
3. B: Combine the first pair of parallel loops outside the loop and also the pair in the outer
loop.
4. C: Multiply the things out and remove nodes to clear the clutter.
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
13 = 10 + 11 + 12 + 13 = 1 + 1 + 1 + 1 = 4
8. G: Simpifying the loop further results in the total maximum number of paths in the
flowgraph:
2 X 84 X 2 = 32,768.
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
o Alternatively, you could have substituted a "1" for each link in the path expression and then
simplified, as follows:
a(b+c)d{e(fi)*fgj(m+l)k}*e(fi)*fgh
= 1(1 + 1)1(1(1 x 1)31 x 1 x 1(1 + 1)1)41(1 x 1)31 x 1 x 1
= 2(131 x (2))413
= 2(4 x 2)4 x 4
= 2 x 84 x 4 = 32,768
o Actually, the outer loop should be taken exactly four times. That doesn't mean it will be taken
zero or four times. Consequently, there is a superfluous "4" on the outlink in the last step.
Therefore the maximum number of different paths is 8192 rather than 32,768.
STRUCTURED FLOWGRAPH:
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
o Structured code can be defined in several different ways that do not involve ad-hoc rules such as
not using GOTOs.
o A structured flowgraph is one that can be reduced to a single link by successive application of the
transformations of Figure 5.7.
o The node-by-node reduction procedure can also be used as a test for structured code.
o Flow graphs that DO NOT contain one or more of the graphs shown below (Figure 5.8) as
subgraphs are structured.
o A lower bound on the number of paths in a routine can be approximated for structured flow
graphs.
o The values of the weights are the number of members in a set of paths.
o EXAMPLE:
1. Applying the arithmetic to the earlier example gives us the identical steps unitl step 3 (C)
as below:
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
3. If you observe the original graph, it takes at least two paths to cover and that it can be done
in two paths.
4. If you have fewer paths in your test plan than this minimum you probably haven't covered.
It's another check.
o Path selection should be biased toward the low - rather than the high-probability paths.
This question can be answered under suitable assumptions, primarily that all probabilities
involved are independent, which is to say that all decisions are independent and uncorrelated.
1. Probabilities can come into the act only at decisions (including decisions associated with
loops).
2. Annotate each outlink with a weight equal to the probability of going in that direction.
4. For a simple loop, if the loop will be taken a mean of N times, the looping probability is
N/(N + 1) and the probability of not looping is 1/(N + 1).
7. In this table, in case of a loop, PA is the probability of the link leaving the loop and PL is
the probability of looping.
2. For the series case, if you must do both things, and their probabilities are
independent (as assumed), then the probability that you do both is the product of
their probabilities.
9. For example, a loop node has a looping probability of PL and a probability of not looping
of PA, which is obviously equal to I - PL.
10. Following the above rule, all we've done is replace the outgoing probability with 1 - so
why the complicated rule? After a few steps in which you've removed nodes, combined
parallel terms, removed loops and the like, you might find something like this:
which is what we've postulated for any decision. In other words, division by 1 - PL renormalizes the outlink
probabilities so that their sum equals unity after the loop is removed.
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
o EXAMPLE:
1. Here is a complicated bit of logic. We want to know the probability associated with cases
A, B, and C.
2. Let us do this in three parts, starting with case A. Note that the sum of the probabilities at
each decision node is equal to 1. Start by throwing away anything that isn't on the way to
case A, and then apply the reduction procedure. To avoid clutter, we usually leave out
probabilities equal to 1.
CASE A:
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
3. Case B is simpler:
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
5. This checks. It's a good idea when doing this sort of thing to calculate all the probabilities
and to verify that the sum of the routine's exit probabilities does equal 1.
6. If it doesn't, then you've made calculation error or, more likely, you've left out some
branching probability.
7. How about path probabilities? That's easy. Just trace the path of interest and multiply the
probabilities as you go.
8. Alternatively, write down the path name and do the indicated arithmetic operation.
9. Say that a path consisted of links a, b, c, d, e, and the associated probabilities were .2, .5,
1., .01, and I respectively. Path abcbcbcdeabddea would have a probability of 5 x 10-10.
o Given the execution time of all statements or instructions for every link in a flowgraph and the
probability for each direction for all decisions are to find the mean processing time for the routine
as a whole.
o The model has two weights associated with every link: the processing time for that link, denoted
by T, and the probability of that link P.
o EXAMPLE:
1. Start with the original flow graph annotated with probabilities and processing time.
2. Combine the parallel links of the outer loop. The result is just the mean of the processing
times for the links because there aren't any other links leaving the first node. Also combine
the pair of links at the beginning of the flowgraph..
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
4. Use the cross-term step to eliminate a node and to create the inner self - loop.
5. Finally, you can get the mean processing time, by using the arithmetic rules as follows:
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
PUSH/POP, GET/RETURN:
o This model can be used to answer several different questions that can turn up in debugging.
Given a pair of complementary operations such as PUSH (the stack) and POP (the stack),
considering the set of all possible paths through the routine, what is the net effect of the routine?
PUSH or POP? How many times? Under what conditions?
o Here are some other examples of complementary operations to which this model applies:
o OPEN/CLOSE a file.
2. The numeral 1 is used to indicate that nothing of interest (neither PUSH nor POP) occurs
on a given link.
3. "H" denotes PUSH and "P" denotes POP. The operations are commutative, associative,
and distributive.
8. Below Table 5.9 shows several combinations of values for the two looping terms - M1 is
the number of times the inner loop will be taken and M2 the number of times the outer
loop will be taken.
9. These expressions state that the stack will be popped only if the inner loop is not taken.
10. The stack will be left alone only if the inner loop is iterated once, but it may also be
pushed.
11. For all other values of the inner loop, the stack will only be pushed.
1. Exactly the same arithmetic tables used for previous example are used for GET /
RETURN a buffer block or resource, or, in fact, for any pair of complementary operations
in which the total number of operations in either direction is cumulative.
4. G(G + R)G(GR)*GGR*R
= G(G + R)G3R*R
= (G + R)G3R*
= (G4 + G2)R*
5. This expression specifies the conditions under which the resources will be balanced on
leaving the routine.
6. If the upper branch is taken at the first decision, the second loop must be taken four times.
7. If the lower branch is taken at the first decision, the second loop must be taken twice.
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
8. For any other values, the routine will not balance. Therefore, the first loop does not have
to be instrumented to verify this behavior because its impact should be nil.
o The node-by-node reduction procedure, and most graph-theory-based algorithms work well when
all paths are possible, but may provide misleading results when some paths are unachievable.
o The approach to handling unachievable paths (for any application) is to partition the graph into
subgraphs so that all paths in each of the subgraphs are achievable.
o The resulting subgraphs may overlap, because one path may be common to several different
subgraphs.
o Each predicate's truth-functional value potentially splits the graph into two subgraphs. For n
predicates, there could be as many as 2n subgraphs.
THE PROBLEM:
o The generic flow-anomaly detection problem (note: not just data-flow anomalies, but any flow
anomaly) is that of looking for a specific sequence of options considering all possible paths
through a routine.
o Let the operations be SET and RESET, denoted by s and r respectively, and we want to know if
there is a SET followed immediately a SET or a RESET followed immediately by a RESET
(an ss or an rr sequence).
1. A file can be opened (o), closed (c), read (r), or written (w). If the file is read or written to
after it's been closed, the sequence is nonsensical. Therefore, cr and cw are anomalous.
Similarly, if the file is read before it's been written, just after opening, we may have a bug.
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
Therefore, or is also anomalous. Furthermore, oo and cc, though not actual bugs, are a
waste of time and therefore should also be examined.
2. A tape transport can do a rewind (d), fast-forward (f), read (r), write (w), stop (p), and skip
(k). There are rules concerning the use of the transport; for example, you cannot go from
rewind to fast-forward without an intervening stop or from rewind or fast-forward to read
or write without an intervening stop. The following sequences are
anomalous: df, dr, dw, fd, and fr. Does the flowgraph lead to anomalous sequences on any
path? If so, what sequences and under what circumstances?
3. The data-flow anomalies discussed in Unit 4 requires us to detect the dd, dk, kk,
and ku sequences. Are there paths with anomalous data flows?
THE METHOD:
o Annotate each link in the graph with the appropriate operator or the null operator 1.
o Simplify things to the extent possible, using the fact that a + a = a and 12 = 1.
o You now have a regular expression that denotes all the possible sequences of operators in that
graph. You can now examine that regular expression for the sequences of interest.
o As an example, let
A = pp
B = srr
C = rp
T = ss
o However, let
A = p + pp + ps
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
Is it obvious that there is a p4 sequence in ABnC? The theorem states that we have only to look at
Multiplying out the expression and simplifying shows that there is no p4 sequence.
o Incidentally, the above observation is an informal proof of the wisdom of looping twice discussed
in Unit 2. Because data-flow anomalies are represented by two-character sequences, it follows the
above theorem that looping twice is what you need to do to find such anomalies.
LIMITATIONS:
o Huang's theorem can be easily generalized to cover sequences of greater length than two
characters. Beyond three characters, though, things get complex and this method has probably
reached its utilitarian limit for manual application.
o There are some nice theorems for finding sequences that occur at the beginnings and ends of
strings but no nice algorithms for finding strings buried in an expression.
o Static flow analysis methods can't determine whether a path is or is not achievable. Unless the
flow analysis includes symbolic execution or similar techniques, the impact of unachievable paths
will not be included in the analysis.
o The flow-anomaly application, for example, doesn't tell us that there will be a flow anomaly - it
tells us that if the path is achievable, then there will be a flow anomaly. Such analytical problems
go away, of course, if you take the trouble to design routines for which all paths are achievable.
SUMMARY:
A flowgraph annotated with link names for every link can be converted into a path expression that
represents the set of all paths in that flowgraph. A node-by-node reduction procedure is used.
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
By substituting link weights for all links, and using the appropriate arithmetic rules, the path expression is
converted into an algebraic expression that can be used to determine the minimum and maximum number
of possible paths in a flowgraph, the probability that a given node will be reached, the mean processing
time of a routine, and other models.
With different, suitable arithmetic rules, and by using complementary operators as weights for the links,
the path expression can be converted into an expression that denotes, over the set of all possible paths,
what the net effect of the routine is.
With links annotated with the appropriate weights, the path expression is converted into a regular
expression that denotes the set of all operator sequences over the set of all paths in a routine. Rules for
determining whether a given sequence of operations are possible are given. In other words, we have a
generalized flow-anomaly detection method that'll work for data-flow anomalies or any other flow
anomaly.
All flow analysis methods lose accuracy and utility if there are unachievable paths. Expand the accuracy and
utility of your analytical tools by designs for which all paths are achievable. Such designs are always possible.
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
Unit IV
Linguistic –Metrics – Structural Metric – Path Products and Path Expressions. Syntax Testing–
Formats–Test Cases
There’s no record of programming labor estimates on ENIAC, but I’m sure they fell far short of reality. The first
programmer, Lady Lovelace, who coded for Charles Babbage’s wonderful but unfinished computer in the
nineteenth century, I’m sure often said “Just one more week, Mr. Babbage, and it’ll be done.” Lucky for her the
hardware was never finished, so she didn’t have to go beyond desk checking. By the mid-1950s individual
programmers had coalesced into programming groups, which meant there was now a new profession—
programmer manager. The managers, who were responsible for productivity and quality, began to measure
software effort in terms of “number of lines of code.” That was used to predict programming costs, testing costs,
running time, number of bugs, salaries, the gross national product, the inflation rate of the peso, and who knows
what else. It is today still the primary quantitative measure in use: “Count the number of lines of code, and you
know all there is to know 2.3. Objectives
Science begins with quantification: you can’t do physics without a notion of length and time; you can’t do
thermodynamics until you measure temperature. The most fundamental question you can ask is “How big is it?”
Without defining what “big” means, it’s obvious that it makes no sense to say “This program will need more
testing than that program” unless we know how big they are relative to one another. Comparing two strategies
also needs a notion of size. The number of tests required by a strategy should be normalized to size. For example,
“Strategy A needs 1.4 tests per unit of size, while strategy B needs 4.3 tests per unit of size.”
What is meant by “size” is not obvious in the early phases of science development. Newton’s use of mass instead
of weight was a breakthrough for physics, and early researchers in thermodynamics had heat, temperature, and
entropy hopelessly confused. We seem to be doing about as well (or as badly) as the sixteenth- and seventeenth-
century physicists did at a comparable phase of development. “Size” isn’t obvious for software. .3.2. The
Questions
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
Our objective in this book is not to quantify all of computer science, but only to explore those metrics of
complexity that have proved their worth in practice. To see what kinds of metrics we need, let’s ask some
questions:
**
A formal examination of metrics requirements by Weyuker (WEYU88B) formally extends these concepts and
evaluates the extent to which several popular metrics, including statement count, cyclomatic number, Halstead’s
effort metric, and dataflow complexity do or do not meet them.
2. It need not be calculated for programs that change size dynamically or programs that in principle cannot be
debugged.
3. Adding something to a program (e.g., instructions, storage, processing time) can never decrease the measured
complexity.
There’s no agreement in the literature on how to classify metrics—and there are so many metrics to classify.
Here are some broad categories: linguistic metrics, structural metrics, and hybrid metrics. Each can be applied to
either programs or specifications; to date, however, application to programs has dominated. The taxonomy is not
rigid because a narrowly defined linguistic metric can define a structural property. For example, cyclomatic
complexity can be defined in terms of links and nodes in the control flowgraph or alternatively by the number of
equivalent branches in the program.
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
Linguistic Metrics—Metrics based on measuring properties of program or specification text without interpreting
what that text means or the ordering of components of the text. For example: lines of code, number of statements,
number of unique operators, number of unique operands, total number of operators, total number of operands,
total number of keyword appearances, total number of tokens.
Structural Metrics—Metrics based on structural relations between objects in the program—usually metrics on
properties of control flowgraphs or data flowgraphs; for example, number of links, number of nodes, nesting
depth.
Hybrid Metrics—Metrics based on some combination of structural and linguistic properties of a program or
based on a function of both structural and linguistic properties
3. LINGUISTIC METRICS
3.1. General
Linguistic metrics measure some property of text without interpreting what is measured. A metric is (mainly)
linguistic if its value doesn’t change when you rearrange the text. Linguistic metrics, to date, have been applied
mostly to program text. They can be just as easily applied to formal specifications, but because formal,
processable specifications are rare, there is almost no experience with such usage; but see RAMA85.
Count the number of lines of code in a program and use that number as a measure of complexity. If then, bugs
appear to occur at 1% per line, a 1000-line program should have 10 bugs and a 10,000 line program should have
100. Going further, if we find that it takes an average of twenty tests to find a bug, we might infer (empirically)
the expected number of tests needed per line of code.
Early users of lines of code did not include data declarations, comments, or any other lines that did not result in
object code. Later users decided to include declarations and other unexecutable statements but still excluded
comments and blank lines. The reason for this shift is the recognition that contemporary code can have 50% or
more data statements and that bugs occur as often in such statements as in “real” code. There is a rationale for
including comments. The quality of comments materially affects maintenance costs because the maintenance
programmer will depend on the comments more than anything else to do her job. Conversely, too many blank
lines and wordy but information-poor comments will increase maintenance effort. The problem with including
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
comments is that we must be able to distinguish between useful and useless comments, and there’s no rigorous
way to do that. The same can be said of blank lines and formatting text: a little helps us read the code but too
much forces us into excessive page turning.
Some of the difficulties with lines of code can be overcome by using statements instead—but this evokes new
problems that are as bad as those of lines of code. The problem, aptly stated by Levitin (LEVI86) is that there’s
no unique way to count statements in some languages (e.g., Pascal), and there’s no simple rule for defining
“statement” across different languages. Just as subjectivity is involved in applying lines of code, there’s
subjectivity in deciding what is and what is not to be called a statement (for some languages).
Thayer, Lipow and Nelson, in their monumental software reliability study (THAY76) showed error rates ranging
from 0.04% to 7% when measured against statement counts, with the most reliable routine being one of the
largest. The same lack of useful correlation is shown in Rubey (RUBE75). Curtis, Sheppard, and Milliman
(CURT79A) show that lines of code is as good as other metrics for small programs, but is optimistic for big
programs. Moderate performance is also reported for lines of code by Schneidewind (SCHN79A). The definitive
report on the relation between program size and bug rate is Lipow’s (LIPO82). In his study of 115,000 JOVIAL
statements, he found a nonlinear relation between bugs per line of code and statements; but also included other
factors related to language type and modularization. Small programs had an error rate of 1.3% to 1.8%, with big
programs increasing from 2.7% to 3.2%. Lipow’s study, however, and most of the others, only included
executable lines and not data declarations. The bottom line is that lines of code is reasonably linear for small
programs (under 100 lines) but increases nonlinearly with program size. It seems to correlate with maintenance
costs.
Halstead’s metrics are based on a combination of arguments derived from common sense, information theory,
and psychology. The clearest exposition is still to be found in Halstead’s Elements of Software Science
(HALS77). It’s an easy-to-read little book that should be read before applying these metrics. The following
exposition is intended only as an introductory overview. The set of metrics are based on two, easily measured,
parameters of programs:
From these he defines program length, which is not to be confused with the number of statements in a program,
by the following relation:
Confirmation of these metrics has been extensively published by Halstead and others. The most solid
confirmation of the bug prediction equation is by Lipow (LIPO82), who compared actual to predicted bug counts
to within 8% over a range of programs sizes from 300 to 12,000 executable statements. The analysis was of
postcompilation bugs, so that syntax errors caught by the compiler are properly excluded. However, of the
115,000 statements in the experiment, only the 75,000 executable statements were examined. It would be
interesting to see whether better accuracy would have been obtained had all declarations been included in the
analysis. Ottenstein, in an earlier report (OTTE79), showed similar good correlation. Curtis (CURT79A) shows
that Halstead’s metrics are at least twice as good as lines of code and are not improved by augmenting them with
lines of code or with McCabe’s metric.
Because Halstead’s metric is the best established (serious) linguistic metric we have, it’s fitting that it be
subjected to the harshest criticism. There are fewer hidden assumptions in Halstead’s work than in other
comparable efforts, but some assumptions and weaknesses still remain. Some of the following weaknesses apply
to all linguistic metrics.
1. Modularity—Modularity is not ignored because each call, together with the parameters of the call
sequence, will contribute to the values of n1, n2, N1, and N2, and therefore to the predicted bug count. Note
that Halstead treats each distinct subroutine call as a unique operator and not just as the one keyword
“CALL.” In this respect, the impact of hypermodularity on bug rate is not ignored.
2. 2. Database Impact and Declarations—Halstead isn’t to be faulted on this one. It’s just that most
evaluators and confirmers have continued the erroneous practice of ignoring unexecutable statements
such as declarations and data statements—which is to say that most initialization and data structure bugs
are ignored. They can’t be faulted for this entirely, because in many cases errors in data declarations and
initializing data statements are not even counted as bugs.
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
3. Opera/Operand Ambiguity—There is a hidden assumption that code is code and data are data, and never
the twain should meet. If Halstead’s metrics are rigidly applied to an assembly language program that
does extensive modification of its own code (ugh!) it will predict the same bug count as a routine that
performs the same operations on a fixed data area.
4. Data-Type Distinctions—In strongly typed languages that force the explicit declaration of all types and
prohibit mixed-type operations unless a type conversion statement has been inserted, the weakness does
not exist if we count all type conversation statements, whether or not they result in object code. If we
count all declarations, including user-defined type declarations, there is no weakness in Halstead’s
metrics.
5. Call Depth—No notice is made of call depth. A routine that calls ten different subroutines as a sequence
of successive calls would actually be considered more complex than a routine that had ten nested calls. If
the totality of the routines and all that it calls were considered, the bug prediction would be the same for
both because the total operator and operand counts would be the same.
6. Operator Types—An IF-THEN-ELSE statement is given the same weight as a FOR-UNTIL, even though it’s
known that loops are more troublesome. This is an example of a broader criticism—that operators and operands
are treated equally, with no correlation to the bug incidence associated with specific operators or with operand
types.
7. General Structure Issues—Of these, the fact that nesting is ignored (nested loops, nested IF-THEN-ELSE,
and so on) is probably the most serious critique. A Basic statement such as
Levitin, in his incisive critique of linguistic metrics (LEVI86), makes a strong argument for the use of program
token count rather than lines of code, statement count, or Halstead’s length. A token in a programming language
is the basic syntactic unit from which programs are constructed. Tokens include keywords, labels, constants,
strings, and variable names. Token counting is easy because the first stage of compilation is to translate the
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
source code into equivalent numerical tokens. The number of tokens is easily obtained as a by-product of
compilation. Token count gets around the subjectivity problems we have with statement counts and lines of code.
4. STRUCTURAL METRICS
4.1. General
Structural metrics take the opposite viewpoint of linguistic metrics. Linguistic complexity is ignored while
attention is focused on control-flow or data-flow complexity—metrics based on the properties of flowgraph
models of programs. Graph theory is more than a half-century old but the study of graph-theoretic problems and
metrics goes back three centuries: see MAYE72. If it’s a graph (i.e., it consists of links and nodes) then there are
hundreds of interesting metrics that can be applied to it: metrics whose mathematical properties have been
studied in minute detail. The thrust of structural metrics research has not been so much the invention of new
graph-theoretic metrics but the investigation of the utility of known graph-theoretic metrics. McCabe’s use of the
cyclomatic number (MCCA76) is an archetypal example.
4.2.1. Definition
M = L — N + 2P
where
P = the number of disconnected parts of the graph (e.g., a calling program and a subroutine)
The number M that appeared alongside the flowgraphs in Chapter 3 was McCabe’s metric for that flowgraph. In
all the examples, except for the one on page 73, there was only one connected part, and consequently the value of
P was 1. Figure 7.1 shows some more examples and their associated M values.
Evaluate the cyclomatic complexity of the program’s design (e.g., from the design control flowgraph). As part of
self-inspection, reevaluate the complexity by counting decisions in the code. Any significant difference should be
explained, because it’s more likely that the difference is due to a missing path, an extra path, or an unplanned
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
deviation from the design than to something else. Having verified the code’s cyclomatic complexity, compare the
number of planned test cases to the code’s complexity. In particular, count how many test cases are intended to
provide coverage. If the number of covering test cases is less than the cyclomatic complexity, there is reason for
caution, because one of the following may be true:
1. You haven’t calculated the complexity correctly. Did you miss a decision?
2. Coverage is not really complete; there’s a link that hasn’t been covered.
3. Coverage is complete, but it can be done with a few more but simpler paths.
McCabe’s metric can be used to help decide whether it pays to make a piece of code which is common to two or
more links into a subroutine. Consider the graph of Figure 7.3. The program has a common part that consists of
Nc nodes and Lc links. This is the part being considered for conversion to a subroutine. This common part recurs
k times in the body of the main program. The main program has Nm nodes and Lm links over and above the
common part.
Subnodes 0 Nc + 2
Sublinks 0 Lc
Subcomplexity 0 L c – Nc – 2 + 2 = L c – Nc = M
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
.2.4. A Refinement
Myers (MYER77) points out a weakness of McCabe’s metric and suggests the use of a refinement thereto. A
decision statement in languages such as FORTRAN can contain a compound predicate of the form: IF A & B &
C THEN . . . . A statement such as this could be implemented as a string of IFs, resulting in a different
complexity measure. Figure 7.4 shows three alternate, equivalent, representations of the same IF-THEN-ELSE
statement. If the compound predicate is used in a single statement as in the first case, the complexity of the
construct is only two, but if it is broken down into its constituent parts, the complexity increases to four.
However, intuitively, all three constructs should have the same complexity. The refinement consists of
accounting for each term of the predicate expression separately. For a predicate expression of the form A&B&C .
. . , each predicate should be counted as if it was a decision. In more complicated expressions, such as A&B&C
OR D&E . . . , again count each predicate. If a predicate appears more than once in an expression, you can take a
pessimistic point of view and count each appearance or a slightly optimistic point of view and count only the first
appearance.
Statistics on how well McCabe’s metric correlates with design, test, and debugging difficulty are encouraging
(BELF79, CHEN78A, CURT79A, ENDR75, FEUE79A, FEUE79B, LIPO77, SCHN79A, SCHN79B,
SCHN79D, SHEP79C, THAY76, WALS79, ZOLN77).* The reported results confirm the utility of McCabe’s
metric as a convenient rule of thumb that is significantly superior to statement count.
*
Not all of these references provide direct information for McCabe’s metric. Some (ENDR75, THAY76) provide
correlations to decision counts and similar metrics that can be converted to McCabe’s metric. Note also that if we
forget the structural basis of cyclomatic complexity and merely use equivalent binary decision count or simple
predicate count, then this metric can be obtained by purely linguistic means.
Many other structural metrics have been proposed and investigated. Chen (CHEN78A) combines structural
properties with information theoretic concepts. Gong (GONG85) combines decisions and nesting depth.
Rodriguez and Tsai (RODR86) apply structural concepts to data flowgraphs, as do Tai (TAIK84) and Tsai et al.
(TSAI86). Van Verth (VANV87) proposes using a combination of control flow and data flow, as does
Whitworth (WHIT80B). This list is incomplete as the number of papers on alternate complexity metrics is as
great as those on alternate testing strategies. The problem with these metrics is that confirming statistics on their
usefulness is lacking. It is intuitively clear that cyclomatic complexity over data flowgraphs should be as useful a
metric as cyclomatic complexity over control flowgraphs but corroboration is still lacking (OVIE80).
. HYBRID METRICS
The appearance of McCabe’s and Halstead’s metrics spurred the proposal, development, refinement, and
validation of a host of similar and related metrics, or totally different alternatives based on different assumptions.
Some of those cited below preceded McCabe’s and Halstead’s work and some followed. It’s too early to tell
which will be experimentally confirmed independently over a range of projects and applications, no matter how
rational and sensible their basis might be. Some of the more interesting and promising alternatives are presented
in BAKE79A, BAKE80, BELF79, CHAP79, CHEN78A, DEYO79, EVAN84, FEUE79B, GILB77, LIPO77,
MCCL78B, PAIG80, RAMA88, SCHN79B, VANV87, WHIT80B, and ZONL77. Most of these metrics and
their variations recognize one or more weaknesses in the popular metrics and seek to measure reliability and/or
predict bug counts through refinement or alternative formulation of the problem. It is inevitable that increased
predictability and fidelity can only be achieved at a cost of increased sophistication, complexity of evaluation,
and difficulty of use.
MOTIVATION:
o Any question about a program can be cast into an equivalent question about an appropriate
flowgraph.
o Most software development, testing and debugging tools use flow graphs analysis techniques.
PATH PRODUCTS:
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
o Using link names as weights, we then convert the graphical flow graph into an equivalent
algebraic like expressions which denotes the set of all possible paths from entry to exit for the
flow graph.
o In tracing a path or path segment through a flow graph, you traverse a succession of link names.
o The name of the path or path segment that corresponds to those links is expressed naturally by
concatenating those link names.
o For example, if you traverse links a,b,c and d along some path, the name for that path segment is
abcd. This path name is also called a path product. Figure 5.1 shows some examples:
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
PATH EXPRESSION:
o Consider a pair of nodes in a graph and the set of paths between those node.
o Denote that set of paths by Upper case letter such as X,Y. From Figure 5.1c, the members of the
path set can be listed as follows:
ac+abc+abbc+abbbc+abbbbc+...........
o The + sign is understood to mean "or" between the two nodes of interest, paths ac, or abc, or abbc,
and so on can be taken.
o Any expression that consists of path names and "OR"s and which denotes a set of paths between
two nodes is called a "Path Expression.".
PATH PRODUCTS:
o The name of a path that consists of two successive path segments is conveniently expressed by the
concatenation or Path Product of the segment names.
XY=abcdefghij
o Similarly,
o YX=fghijabcde
o aX=aabcde
o Xa=abcdea
XaX=abcdeaabcde
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
o If X and Y represent sets of paths or path expressions, their product represents the set of paths that
can be obtained by following every element of X by any element of Y in all possible ways. For
example,
o Y = uvw + z
Then,
o If a link or segment name is repeated, that fact is denoted by an exponent. The exponent's value
denotes the number of repetitions:
Similarly, if
X = abcde
then
X1 = abcde
X2 = abcdeabcde = (abcde)2
X3 = abcdeabcdeabcde = (abcde)2abcde
= abcde(abcde)2 = (abcde)3
RULE 1: A(BC)=(AB)C=ABC
where A,B,C are path names, set of path names or path expressions.
o The zeroth power of a link name, path product, or path expression is also needed for
completeness. It is denoted by the numeral "1" and denotes the "path" whose length is zero - that
is, the path that doesn't have any links.
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
o a0 = 1
o X0 = 1
PATH SUMS:
o The "+" sign was used to denote the fact that path names were part of the same set of paths.
o Links a and b in Figure 5.1a are parallel paths and are denoted by a + b. Similarly, links c and d
are parallel paths between the next two nodes and are denoted by c + d.
o The set of all paths between nodes 1 and 2 can be thought of as a set of parallel paths and denoted
by eacf+eadf+ebcf+ebdf.
o If X and Y are sets of paths that lie between the same pair of nodes, then X+Y denotes the
UNION of those set of paths. For example, in Figure 5.2:
The first set of parallel paths is denoted by X + Y + d and the second set by U + V + W + h + i + j. The set of all
paths in this flowgraph is f(X + Y + d)g(U + V + W + h + i + j)k
o RULE 2: X+Y=Y+X
o RULE 3: (X+Y)+Z=X+(Y+Z)=X+Y+Z
DISTRIBUTIVE LAWS:
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
o The product and sum operations are distributive, and the ordinary rules of multiplication apply;
that is
o e(a+b)(c+d)f=e(ac+ad+bc+bd)f = eacf+eadf+ebcf+ebdf
ABSORPTION RULE:
o If X and Y denote the same set of paths, then the union of these sets is unchanged; consequently,
o If a set consists of paths names and a member of that set is added to it, the "new" name, which is
already in that set of names, contributes nothing and can be ignored.
o For example,
o if X=a+aa+abc+abcd+def then
It follows that any arbitrary sum of identical path expressions reduces to the same path expression.
LOOPS:
o Loops can be understood as an infinite set of parallel paths. Say that the loop consists of a single
link b. then the set of all paths through that loop point is b0+b1+b2+b3+b4+b5+..............
o This potentially infinite sum is denoted by b* for an individual link and by X* when X is a path
expression.
o The path expression for the above figure is denoted by the notation:
ab*c=ac+abc+abbc+abbbc+................
o Evidently,
o It is more convenient to denote the fact that a loop cannot be taken more than a certain, say n,
number of times.
Xn = X0+X1+X2+X3+X4+X5+..................+Xn
RULES 6 - 16:
o RULE 6: Xn + Xm = Xn if n>m
RULE 6: Xn + Xm = Xm if m>n
RULE 11: 1 + 1 = 1
RULE 12: 1X = X1 = X
Following or preceding a set of paths by a path of zero length does not change the set.
RULE 13: 1n = 1n = 1* = 1+ = 1
No matter how often you traverse a path of zero length,It is a path of zero length.
The null set of paths is denoted by the numeral 0. it obeys the following rules:
If you block the paths of a graph for or aft by a graph that has no paths , there wont be any paths.
REDUCTION PROCEDURE:
o This section presents a reduction procedure for converting a flowgraph whose links are labeled
with names into a path expression that denotes the set of all entry/exit paths in that flowgraph. The
procedure is a node-by-node removal algorithm.
3. Remove all self-loops (from any node to itself) by replacing them with a link of the form
X*, where X is the path expression of the link in that loop.
4. Select any node for removal other than the initial or final node. Replace it with a set of
equivalent links whose path expressions correspond to all the ways you can form a product
of the set of inlinks with the set of outlinks of that node.
8. Does the graph consist of a single link between the entry node and the exit node? If yes,
then the path expression for that link is a path expression for the original flowgraph;
otherwise, return to step 4.
o A flowgraph can have many equivalent path expressions between a given pair of nodes; that is,
there are many different ways to generate the set of all paths between two nodes without affecting
the content of that set.
o The appearance of the path expression depends, in general, on the order in which nodes are
removed.
o The cross - term step is the fundamental step of the reduction algorithm.
o Successive applications of this step eventually get you down to one entry and one exit node. The
following diagram shows the situation at an arbitrary node that has been selected for removal:
o (a + b)(c + d + e) = ac + ad + + ae + bc + bd + be
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
o In the first way, we remove the self-loop and then multiply all outgoing links by Z*.
o In the second way, we split the node into two equivalent nodes, call them A and A' and put in a
link between them whose path expression is Z*. Then we remove node A' using steps 4 and 5 to
yield outgoing links whose path expressions are Z*X and Z*Y.
o Let us see by applying this algorithm to the following graph where we remove several nodes in
order; that is
o Removing the loop and then node 6 result in the following expression:
o a(bgjf)*b(c+gkh)d((ilhd)*imf(bjgf)*b(c+gkh)d)*(ilhd)*e
o You can practice by applying the algorithm on the following flowgraphs and generate their
respective path expressions:
APPLICATIONS:
APPLICATIONS:
o The purpose of the node removal algorithm is to present one very generalized concept- the path
expression and way of getting it.
2. Identify a property of interest and derive an appropriate set of "arithmetic" rules that
characterizes the property.
3. Replace the link names by the link weights for the property of interest. The path
expression has now been converted to an expression in some algebra, such as ordinary
algebra, regular expressions, or boolean algebra. This algebraic expression summarizes the
property of interest over the set of all paths.
4. Simplify or evaluate the resulting "algebraic" expression to answer the question you asked.
o The question is not simple. Here are some ways you could ask it:
o Determining the actual number of different paths is an inherently difficult problem because there
could be unachievable paths resulting from correlated and dependent predicates.
o If we know both of these numbers (maximum and minimum number of possible paths) we have a
good idea of how complete our testing is.
o Label each link with a link weight that corresponds to the number of paths that link represents.
o Also mark each loop with the maximum number of times that loop can be taken. If the answer is
infinite, you might as well stop the analysis because it is clear that the maximum number of paths
will be infinite.
o There are three cases of interest: parallel links, serial links, and loops.
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
o This arithmetic is an ordinary algebra. The weight is the number of paths in each set.
o EXAMPLE:
Each link represents a single link and consequently is given a weight of "1" to start. Lets say the outer loop will
be taken exactly four times and inner Loop Can be taken zero or three times Its path expression, with a little
work, is:
2. A: The flow graph should be annotated by replacing the link name with the maximum of
paths through that link (1) and also note the number of times for looping.
3. B: Combine the first pair of parallel loops outside the loop and also the pair in the outer
loop.
4. C: Multiply the things out and remove nodes to clear the clutter.
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
13 = 10 + 11 + 12 + 13 = 1 + 1 + 1 + 1 = 4
8. G: Simpifying the loop further results in the total maximum number of paths in the
flowgraph:
2 X 84 X 2 = 32,768.
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
o Alternatively, you could have substituted a "1" for each link in the path expression and then
simplified, as follows:
a(b+c)d{e(fi)*fgj(m+l)k}*e(fi)*fgh
= 1(1 + 1)1(1(1 x 1)31 x 1 x 1(1 + 1)1)41(1 x 1)31 x 1 x 1
= 2(131 x (2))413
= 2(4 x 2)4 x 4
= 2 x 84 x 4 = 32,768
o Actually, the outer loop should be taken exactly four times. That doesn't mean it will be taken
zero or four times. Consequently, there is a superfluous "4" on the outlink in the last step.
Therefore the maximum number of different paths is 8192 rather than 32,768.
STRUCTURED FLOWGRAPH:
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
o Structured code can be defined in several different ways that do not involve ad-hoc rules such as
not using GOTOs.
o A structured flowgraph is one that can be reduced to a single link by successive application of the
transformations of Figure 5.7.
o The node-by-node reduction procedure can also be used as a test for structured code.
o Flow graphs that DO NOT contain one or more of the graphs shown below (Figure 5.8) as
subgraphs are structured.
o A lower bound on the number of paths in a routine can be approximated for structured flow
graphs.
o The values of the weights are the number of members in a set of paths.
o EXAMPLE:
1. Applying the arithmetic to the earlier example gives us the identical steps unitl step 3 (C)
as below:
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
3. If you observe the original graph, it takes at least two paths to cover and that it can be done
in two paths.
4. If you have fewer paths in your test plan than this minimum you probably haven't covered.
It's another check.
o Path selection should be biased toward the low - rather than the high-probability paths.
This question can be answered under suitable assumptions, primarily that all probabilities
involved are independent, which is to say that all decisions are independent and uncorrelated.
1. Probabilities can come into the act only at decisions (including decisions associated with
loops).
2. Annotate each outlink with a weight equal to the probability of going in that direction.
4. For a simple loop, if the loop will be taken a mean of N times, the looping probability is
N/(N + 1) and the probability of not looping is 1/(N + 1).
7. In this table, in case of a loop, PA is the probability of the link leaving the loop and PL is
the probability of looping.
2. For the series case, if you must do both things, and their probabilities are
independent (as assumed), then the probability that you do both is the product of
their probabilities.
9. For example, a loop node has a looping probability of PL and a probability of not looping
of PA, which is obviously equal to I - PL.
10. Following the above rule, all we've done is replace the outgoing probability with 1 - so
why the complicated rule? After a few steps in which you've removed nodes, combined
parallel terms, removed loops and the like, you might find something like this:
which is what we've postulated for any decision. In other words, division by 1 - PL renormalizes the outlink
probabilities so that their sum equals unity after the loop is removed.
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
o EXAMPLE:
1. Here is a complicated bit of logic. We want to know the probability associated with cases
A, B, and C.
2. Let us do this in three parts, starting with case A. Note that the sum of the probabilities at
each decision node is equal to 1. Start by throwing away anything that isn't on the way to
case A, and then apply the reduction procedure. To avoid clutter, we usually leave out
probabilities equal to 1.
CASE A:
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
3. Case B is simpler:
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
5. This checks. It's a good idea when doing this sort of thing to calculate all the probabilities
and to verify that the sum of the routine's exit probabilities does equal 1.
6. If it doesn't, then you've made calculation error or, more likely, you've left out some
branching probability.
7. How about path probabilities? That's easy. Just trace the path of interest and multiply the
probabilities as you go.
8. Alternatively, write down the path name and do the indicated arithmetic operation.
9. Say that a path consisted of links a, b, c, d, e, and the associated probabilities were .2, .5,
1., .01, and I respectively. Path abcbcbcdeabddea would have a probability of 5 x 10-10.
o Given the execution time of all statements or instructions for every link in a flowgraph and the
probability for each direction for all decisions are to find the mean processing time for the routine
as a whole.
o The model has two weights associated with every link: the processing time for that link, denoted
by T, and the probability of that link P.
o EXAMPLE:
1. Start with the original flow graph annotated with probabilities and processing time.
2. Combine the parallel links of the outer loop. The result is just the mean of the processing
times for the links because there aren't any other links leaving the first node. Also combine
the pair of links at the beginning of the flowgraph..
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
4. Use the cross-term step to eliminate a node and to create the inner self - loop.
5. Finally, you can get the mean processing time, by using the arithmetic rules as follows:
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
PUSH/POP, GET/RETURN:
o This model can be used to answer several different questions that can turn up in debugging.
Given a pair of complementary operations such as PUSH (the stack) and POP (the stack),
considering the set of all possible paths through the routine, what is the net effect of the routine?
PUSH or POP? How many times? Under what conditions?
o Here are some other examples of complementary operations to which this model applies:
o OPEN/CLOSE a file.
2. The numeral 1 is used to indicate that nothing of interest (neither PUSH nor POP) occurs
on a given link.
3. "H" denotes PUSH and "P" denotes POP. The operations are commutative, associative,
and distributive.
8. Below Table 5.9 shows several combinations of values for the two looping terms - M1 is
the number of times the inner loop will be taken and M2 the number of times the outer
loop will be taken.
9. These expressions state that the stack will be popped only if the inner loop is not taken.
10. The stack will be left alone only if the inner loop is iterated once, but it may also be
pushed.
11. For all other values of the inner loop, the stack will only be pushed.
1. Exactly the same arithmetic tables used for previous example are used for GET /
RETURN a buffer block or resource, or, in fact, for any pair of complementary operations
in which the total number of operations in either direction is cumulative.
4. G(G + R)G(GR)*GGR*R
= G(G + R)G3R*R
= (G + R)G3R*
= (G4 + G2)R*
5. This expression specifies the conditions under which the resources will be balanced on
leaving the routine.
6. If the upper branch is taken at the first decision, the second loop must be taken four times.
7. If the lower branch is taken at the first decision, the second loop must be taken twice.
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
8. For any other values, the routine will not balance. Therefore, the first loop does not have
to be instrumented to verify this behavior because its impact should be nil.
o The node-by-node reduction procedure, and most graph-theory-based algorithms work well when
all paths are possible, but may provide misleading results when some paths are unachievable.
o The approach to handling unachievable paths (for any application) is to partition the graph into
subgraphs so that all paths in each of the subgraphs are achievable.
o The resulting subgraphs may overlap, because one path may be common to several different
subgraphs.
o Each predicate's truth-functional value potentially splits the graph into two subgraphs. For n
predicates, there could be as many as 2n subgraphs.
THE PROBLEM:
o The generic flow-anomaly detection problem (note: not just data-flow anomalies, but any flow
anomaly) is that of looking for a specific sequence of options considering all possible paths
through a routine.
o Let the operations be SET and RESET, denoted by s and r respectively, and we want to know if
there is a SET followed immediately a SET or a RESET followed immediately by a RESET
(an ss or an rr sequence).
1. A file can be opened (o), closed (c), read (r), or written (w). If the file is read or written to
after it's been closed, the sequence is nonsensical. Therefore, cr and cw are anomalous.
Similarly, if the file is read before it's been written, just after opening, we may have a bug.
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
Therefore, or is also anomalous. Furthermore, oo and cc, though not actual bugs, are a
waste of time and therefore should also be examined.
2. A tape transport can do a rewind (d), fast-forward (f), read (r), write (w), stop (p), and skip
(k). There are rules concerning the use of the transport; for example, you cannot go from
rewind to fast-forward without an intervening stop or from rewind or fast-forward to read
or write without an intervening stop. The following sequences are
anomalous: df, dr, dw, fd, and fr. Does the flowgraph lead to anomalous sequences on any
path? If so, what sequences and under what circumstances?
3. The data-flow anomalies discussed in Unit 4 requires us to detect the dd, dk, kk,
and ku sequences. Are there paths with anomalous data flows?
THE METHOD:
o Annotate each link in the graph with the appropriate operator or the null operator 1.
o Simplify things to the extent possible, using the fact that a + a = a and 12 = 1.
o You now have a regular expression that denotes all the possible sequences of operators in that
graph. You can now examine that regular expression for the sequences of interest.
o As an example, let
A = pp
B = srr
C = rp
T = ss
o However, let
A = p + pp + ps
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
Is it obvious that there is a p4 sequence in ABnC? The theorem states that we have only to look at
Multiplying out the expression and simplifying shows that there is no p4 sequence.
o Incidentally, the above observation is an informal proof of the wisdom of looping twice discussed
in Unit 2. Because data-flow anomalies are represented by two-character sequences, it follows the
above theorem that looping twice is what you need to do to find such anomalies.
LIMITATIONS:
o Huang's theorem can be easily generalized to cover sequences of greater length than two
characters. Beyond three characters, though, things get complex and this method has probably
reached its utilitarian limit for manual application.
o There are some nice theorems for finding sequences that occur at the beginnings and ends of
strings but no nice algorithms for finding strings buried in an expression.
o Static flow analysis methods can't determine whether a path is or is not achievable. Unless the
flow analysis includes symbolic execution or similar techniques, the impact of unachievable paths
will not be included in the analysis.
o The flow-anomaly application, for example, doesn't tell us that there will be a flow anomaly - it
tells us that if the path is achievable, then there will be a flow anomaly. Such analytical problems
go away, of course, if you take the trouble to design routines for which all paths are achievable.
SUMMARY:
A flowgraph annotated with link names for every link can be converted into a path expression that
represents the set of all paths in that flowgraph. A node-by-node reduction procedure is used.
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
By substituting link weights for all links, and using the appropriate arithmetic rules, the path expression is
converted into an algebraic expression that can be used to determine the minimum and maximum number
of possible paths in a flowgraph, the probability that a given node will be reached, the mean processing
time of a routine, and other models.
With different, suitable arithmetic rules, and by using complementary operators as weights for the links,
the path expression can be converted into an expression that denotes, over the set of all possible paths,
what the net effect of the routine is.
With links annotated with the appropriate weights, the path expression is converted into a regular
expression that denotes the set of all operator sequences over the set of all paths in a routine. Rules for
determining whether a given sequence of operations are possible are given. In other words, we have a
generalized flow-anomaly detection method that'll work for data-flow anomalies or any other flow
anomaly.
All flow analysis methods lose accuracy and utility if there are unachievable paths. Expand the accuracy
and utility of your analytical tools by designs for which all paths are achievable. Such designs are always
possible.
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
Unit V
Logic Based Testing–Decision Tables–Transition Testing–States, State Graph, State Testing.
INTRODUCTION:
o The functional requirements of many programs can be specified by decision tables, which
provide a useful basis for program and test design.
o Consistency and completeness can be analyzed by using boolean algebra, which can also be used
as a basis for test design. Boolean algebra is trivialized by using Karnaugh-Veitch charts.
o "Logic" is one of the most often used words in programmers' vocabularies but one of their least
used techniques.
o Boolean algebra is to logic as arithmetic is to mathematics. Without it, the tester or programmer is
cut off from many test and design techniques and tools that incorporate those techniques.
o Logic has been, for several decades, the primary tool of hardware logic designers.
o Many test methods developed for hardware logic can be adapted to software logic testing.
Because hardware testing automation is 10 to 15 years ahead of software testing automation,
hardware testing methods and its associated theory is a fertile ground for software testing
methods.
o As programming and test techniques have improved, the bugs have shifted closer to the process
front end, to requirements and their specifications. These bugs range from 8% to 30% of the total
and because they're first-in and last-out, they're the costliest of all.
o Boolean algebra (also known as the sentential calculus) is the most basic of all logic systems.
o Higher-order logic systems are needed and used for formal specifications.
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
o Much of logical analysis can be and is embedded in tools. But these tools incorporate methods to
simplify, transform, and check specifications, and the methods are to a large extent based on
boolean algebra.
The user's data is processed through the rule base to yield conclusions (tentative or
definite) and requests for more data. The processing is done by a program called
the inference engine.
o Decision tables are extensively used in business data processing; Decision-table preprocessors as
extensions to COBOL are in common use; boolean algebra is embedded in the implementation of
these processors.
o Although programmed tools are nice to have, most of the benefits of boolean algebra can be
reaped by wholly manual means if you have the right conceptual tool: the Karnaugh-Veitch
diagram is that conceptual tool.
DECISION TABLES:
Figure 6.1 is a limited - entry decision table. It consists of four areas called the condition stub, the
condition entry, the action stub, and the action entry.
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
Each column of the table is a rule that specifies the conditions under which the actions named in the
action stub will take place.
A rule specifies whether a condition should or should not be met for the rule to be satisfied. "YES" means
that the condition must be met, "NO" means that the condition must not be met, and "I" means that the
condition plays no part in the rule, or it is immaterial to that rule.
The action stub names the actions the routine will take or initiate if the rule is satisfied. If the action entry
is "YES", the action will take place; if "NO", the action will not take place.
Action 1 will take place if conditions 1 and 2 are met and if conditions 3 and 4 are not met (rule 1) or if
conditions 1, 3, and 4 are met (rule 2).
Decision-table uses "condition" and "satisfied" or "met". Let us use "predicate" and TRUE / FALSE.
1. Action 1 will be taken if predicates 1 and 2 are true and if predicates 3 and 4 are false (rule 1), or
if predicates 1, 3, and 4 are true (rule 2).
2. Action 2 will be taken if the predicates are all false, (rule 3).
3. Action 3 will take place if predicate 1 is false and predicate 4 is true (rule 4).
In addition to the stated rules, we also need a Default Rule that specifies the default action to be taken
when all other rules fail. The default rules for Table in Figure 6.1 is shown in Figure 6.3
DECISION-TABLE PROCESSORS:
1. Decision tables can be automatically translated into code and, as such, are a higher-order language
3. Otherwise, rule 2 is tried. This process continues until either a satisfied rule results in an action or
no rule is satisfied and the default action is taken
4. Decision tables have become a useful tool in the programmers kit, in business data processing.
1. The specification is given as a decision table or can be easily converted into one.
2. The order in which the predicates are evaluated does not affect interpretation of the rules or the
resulting action - i.e., an arbitrary permutation of the predicate order will not, or should not, affect
which action takes place.
3. The order in which the rules are evaluated does not affect the resulting action - i.e., an arbitrary
permutation of rules will not, or should not, affect which action takes place.
4. Once a rule is satisfied and an action selected, no other rule need be examined.
5. If several actions can result from satisfying a rule, the order in which the actions are executed
doesn't matter
9. Similalrly, If we expand the immaterial cases for the above Table 6.1, it results in Table 6.2 as
below:
12. Sixteen cases are represented in Table 6.1, and no case appears twice.
14. As a first check, before you look for all sixteen combinations, count the number of Y's and N's in
each row. They should be equal. We can find the bug that way.
1. Consider the following specification whose putative flowgraph is shown in Figure 6.5:
1. If condition A is met, do process A1 no matter what other actions are taken or what other
conditions are met.
2. If condition B is met, do process A2 no matter what other actions are taken or what other
conditions are met.
3. If condition C is met, do process A3 no matter what other actions are taken or what other
conditions are met.
4. If none of the conditions is met, then do processes A1, A2, and A3.
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
5. When more than one process is done, process A1 must be done first, then A2, and then
A3. The only permissible cases are: (A1), (A2), (A3), (A1,A3), (A2,A3) and (A1,A2,A3).
4. Table 6.3 shows the conversion of this flowgraph into a decision table after expansion.
PATH EXPRESSIONS:
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
GENERAL:
o Logic-based testing is structural testing when it's applied to structure (e.g., control flowgraph of
an implementation); it's functional testing when it's applied to a specification.
o We start by generating path expressions by path tracing as in Unit V, but this time, our purpose is
to convert the path expressions into boolean algebra, using the predicates' truth values (e.g., A
and ) as weights.
BOOLEAN ALGEBRA:
o STEPS:
1. Label each decision with an uppercase letter that represents the truth value of the
predicate. The YES or TRUE branch is labeled with a letter (say A) and the NO or FALSE
branch with the same letter overscored (say ).
2. The truth value of a path is the product of the individual labels. Concatenation or products
mean "AND". For example, the straight-through path of Figure 6.5, which goes via nodes
3, 6, 7, 8, 10, 11, 12, and 2, has a truth value of ABC. The path via nodes 3, 6, 7, 9 and 2
has a value of .
3. If two or more paths merge at a node, the fact is expressed by use of a plus sign (+) which
means "OR".
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
o There are only two numbers in boolean algebra: zero (0) and one (1). One means "always true"
and zero means "always false".
4. meaning NOT. Also negation or complementation. This is read as either "not A" or "A
bar". The entire expression under the bar is negated.
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
o In all of the above, a letter can represent a single sentence or an entire boolean algebra expression.
o Individual letters in a boolean algebra expression are called Literals (e.g. A,B)
o The product of several literals is called a product term (e.g., ABC, DE).
o An arbitrary boolean expression that has been multiplied out so that it consists of the sum of
products (e.g., ABC + DEF + GH) is said to be in sum-of-products form.
o The result of simplifications (using the rules above) is again in the sum of product form and each
product term in such a simplified version is called a prime implicant. For example, ABC + AB +
DEF reduces by rule 20 to AB + DEF; that is, AB and DEF are prime implicants.
o The path expressions of Figure 6.5 can now be simplified by applying the rules.
o Similarly,
o The deviation from the specification is now clear. The functions should have been:
Loops complicate things because we may have to solve a boolean equation to determine what predicate-
value combinations lead to where.
KV CHARTS:
INTRODUCTION:
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
o If you had to deal with expressions in four, five, or six variables, you could get bogged down in
the algebra and make as many errors in designing test cases as there are bugs in the routine you're
testing.
o Beyond six variables these diagrams get cumbersome and may not be effective.
SINGLE VARIABLE:
o Figure 6.6 shows all the boolean functions of a single variable and their equivalent representation
as a KV chart.
o A "1" means the variable’s value is "1" or TRUE. A "0" means that the variable's value is 0 or
FALSE.
o The entry in the box (0 or 1) specifies whether the function that the chart represents is true or false
for that value of the variable.
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
o We usually do not explicitly put in 0 entries but specify only the conditions under which the
function is true.
TWO VARIABLES:
o Figure 6.7 shows eight of the sixteen possible functions of two variables.
o Any variable that changes in either the horizontal or vertical direction does not appear in the
expression.
o In the fifth chart, the B variable changes from 0 to 1 going down the column, and because the A
variable's value for the column is 1, the chart is equivalent to a simple A.
o The first chart has two 1's in it, but because they are not adjacent, each must be taken separately.
o That combination might or might not be in the function (i.e., the box corresponding to that
combination might have a 1 or 0 entry).
o Since n variables lead to 2n combinations of 0 and 1 for the variables, and each such combination
(box) can be filled or not filled, leading to 22n ways of doing this.
o Consequently for one variable there are 221 = 4 functions, 16 functions of 2 variables, 256
functions of 3 variables, 16,384 functions of 4 variables, and so on.
o Given two charts over the same variables, arranged the same way, their product is the term by
term product, their sum is the term by term sum, and the negation of a chart is gotten by reversing
all the 0 and 1 entries in the chart.
OR
THREE VARIABLES:
o As before, each box represents an elementary term of three variables with a bar appearing or not
appearing according to whether the row-column heading for that box is 0 or 1.
(i) States
State is a condition or situation during which an object undergoes throughout its life time.
States are represented by nodes.
States are numbered or identified by characters or words or whatever else is convenient.
A state graph consists of a set of states in order to represent the behavior of the system.
To understand the concept of states let us consider the following examples.
Example 1: A program that detects the character sequence ZCZC can be in the following states.
1. Neither ZCZC nor any part of it has been detected.
2. Z has been detected.
3. ZC has been detected.
4. ZCZ has been detected.
5. ZCZC has been detected.
Example 2: A moving automobile whose engine is running can have the following states with respect to
transmission.
1. Reverse gear.
2. Neutral gear.
3. First gear.
4. Second gear.
5. Third gear.
6. Four gear.
Example 3: A person’s checkbook can have the following states with respect to bank balance.
1. Equal.
2. Less than.
3. Greater than.
Example 4: A word processing program menu can be in the following states with respect to file
transmission.
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
1. Create document.
2. Copy document.
3. Delete document.
4. Rename document.
5. Compress document.
6. Saving document
7. Copy disc.
8. Format disc
9. Backup disc
10. Recover from backup
Some thing is modeled and given is called input. Input may be values or variables.
A state graph takes input provided to states.
As a result of these inputs the state changes is known as transition.
That is changing from one state to other state is called transition.
Transitions are denoted by links that join the states.
The input that causes the transition is represented on the link. So the inputs are link weights.
A finite state machine is represented by a state graph having a finite number of states and a finite
number of transitions between states.
The ZCZC detection example can have the following types of inputs.
Z
C
Any character other than Z or C which will be denoted by A.
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
At state 1 if no write errors are detected (input = OK) no special action is taken (output=NONE). If
error is detected (input=ERROR) backspace the tape one block and rewrite the block (output
=REWRITE) i.e. enter into state 2.
At state 2 if the rewrite is successful (input= OK) no action is taken (output=NONE) and return to
state 1.
If the rewrite is not successful try another back space and rewrite (output=REWRITE) i.e. enter into
state 4.
If there are two successive rewrites and a third error occurs then backspace ten centimeters and erase
(output=ERASE) i.e. from state 4 to state 5.
If there are two successive rewrites and a third no error occurs then it enter into state 3 & then state 1.
At state 3 if any error is detected then it enter into state 2 and rewrite.
At state 5 if the erasure works (input=OK) no action is taken and return to initial state.
If it does not work, backspace another ten centimeters and erase. i.e. enter into state 6.
At state 6 if the erasure works (input=OK) no action is taken and return to initial state
If the second erasure does not work put the tape control out of service i.e enter into state 7
If state graph has a large number of states and transitions, then it is difficult to follow them.
Therefore a state table is used, as an easiest way to represent all the states, inputs, transitions and
outputs of the state graph.
A state table is defined as a tabular representation of a state graph.
It consists of
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
STATE OK ERROR
1 1/NONE 2/REWRITE
2 1/NONE 4/REWRITE
3 1/NONE 2/REWRITE
4 3/NONE 5/ERASE
5 1/NONE 6/ERASE
6 1/NONE 7/OUT
7
(i) General:
In testing we deal with a good state graph and also with a bad one.
The following figure shows examples of improper or bad state graphs.
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
(2)State Bugs
The bugs in states are called state bugs. The state bugs arise due to the following reasons.
1. Number of States:
A State graph consists of the number of states. It represents behavior of the system.
In practice the state is directly or indirectly recorded.
State table is used to record the number of states of the state graph.
In state table the state bugs are occurred because of missing states.
That is in state table if the number of states are not recorded or missed then the result might be the
bugs.
To find the missing states, first find the number of states
The number of states is founded by as follows.
1. Identify all the component factors of the state.
2. Identify all the allowable values for each factor.
3. Now the number of states is the product of the factors and allowable values.
Functional specifications are used to find the factors of the state. They may also helpful to find the
number of possible values for each factor.
2. Impossible States:
A state that is not possible is called impossible states.
For example a broken engine cannot run, so running a broken engine state is impossible state.
There are some combination of factors that are impossible, they are GEAR: R, N, 1, 2, 3, 4 = 6
factors
DIRECTION: forward, reverse, stopped = 3 factors ENGINE: running, stopped = 2 factors
TRANMISSION: ok, broken = 2 factors
ENGINE: ok, broken = 2 factors
3. Equivalent States:
Two states A, B are equivalent if every sequence of inputs starting from one state (s) produces
exactly the same sequence of outputs.
Let us take an example of two equivalent states.
In the below figure, let us assume the system is in state S.
An input of ‘a’ begins a transition to state A and an input of ‘b’ begins a transition to
state B from S.
If all the sequence of inputs from the state A generates exactly the same sequence of outputs as the
other state B, then we say that these two states are equivalent.
A
a
S C
b
B
Because these two states are treated equally, the state graph can be minimized by combining these
two equivalent states as shown in the following figure.
a,b
S A,B C
d/y
e/y
A C
a
e/y
1
e/x
b
e/x
B C
d/y
Here except a, b inputs, the system behavior in two states A, B are identical for every input sequence.
2. There are two set of rows which except for the state name, have identical state graphs with respect
to transitions and outputs. The two sets can be merged. Let consider the following equivalent
states.
a/y
a/u
b/x b/u
A1 A2 A3
a/u
1 a/w b/y
a/w
b/y
b/u
b/x
B1 B2 B3
b/u
a/y
a/u
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
STATE OK ERROR
1 A1/u B1/u
A1 A1/y A2/x
B1 B1/y B2/x
A2 B2/w A3/u
B2 A2/w B3/u
A3 A3/u B2/y
B3 B3/u A2/y
The merged equivalent states are represented by as follows
a/y a/w a/u
b/x b/u
a/u,b/u
1 A1 B1 A2 B2 A3 B3
b/y
a/y a/w
a/u
b/x b/u
A1 A2 A3
a/u
1
b/y
b/u
b/x
B1 B2 B3
b/u
a/y
a/w a/u
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
Transition Bugs
2. Example
The following example shows how to convert a specification into a state graph and how
contradictions can come out.
OK
Rule 1:
The program will maintain an error counter which will be incremented whenever there is an error.
Here there are only two input values OK, ERROR.
These values make it easier to detect ambiguities and contradictions in a state table.
123
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
INPUT
STATE OK ERROR
0 0/NONE 1/
1 2/
2 3/
3 4/
4 5/
5 6/
6 7/
7 8/
Rule 2:If there is an error rewrite the block.
INPUT
STATE OK ERROR
0 0/NONE 1/REWRITE
1 2/REWRITE
2 3/REWRITE
3 4/REWRITE
4 5/REWRITE
5 6/REWRITE
6 7/REWRITE
7 8/REWRITE
Rule 3: If there are three errors, erase 10 centimeters of tape and rewrite the block.
INPUT
STATE OK ERROR
0 0/NONE 1/REWRITE
1 2/REWRITE
2 3/REWRITE,ERASE,REWRITE
3 4/REWRITE,ERASE,REWRITE
4 5/REWRITE,ERASE,REWRITE
5 6/REWRITE,ERASE,REWRITE
6 7/REWRITE,ERASE,REWRITE
7 8/REWRITE,ERASE,REWRITE
Rule 4: If there are three erasures and another error occur, then put out of service.
INPUT124
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
STATE OK ERROR
0 0/NONE 1/REWRITE
1 2/REWRITE
2 3/ERASE,REWRITE
3 4/ERASE,REWRITE
4 5/ERASE,REWRITE
5 6/OUT
6
7
Rule 5:
If the erasure was successful return to the normal state and clear the error counter.
INPUT
STATE OK ERROR
0 0/NONE 1/REWRITE
1 2/REWRITE
2 3/ERASE,REWRITE
3 0/NONE 4/ERASE,REWRITE
4 0/NONE 5/ERASE,REWRITE
5 0/NONE 6/OUT
6
Rule 6:
If the rewrite was unsuccessful increment the error counter, and try another rewrite.
Rule 7:
If the rewrite was successful decrement the error counter and return to the previous state. INPUT
STATE OK ERROR
0 0/NONE 1/REWRITE
1 0/NONE 2/REWRITE
2 1/NONE 3/ERASE,REWRITE
3 0/NONE 4/ERASE,REWRITE
2/NONE
4 0/NONE 5/ERASE,REWRITE
3/NONE
125
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
5 0/NONE 6/OUT
4/NONE
6
Rule 7 A:
If there have been no erasures and the rewrite is successful return to the previous state.
3. Unreachable States:
An un reachable state is like unreachable code If a transition is not specified between two
states then that states are unreachable. That is if any incorrect transition occurs then the state
becomes unreachable.
There may be a transition from unreachable states to other states.
4. Dead States:
A dead state is a state that once entered cannot be left.
In programming, a set of states may be dead because a program has two stages.
In the first stage an initialization process takes place that consists of number of states to be
initialized.
In the second stage strongly connected set of functional states takes place in which operations
of the states cannot be completed. So the functional states become dead states. The only
solution to this problem is system restart.
Let us say that a routine is specified as a state graph that has been verified as correct in all details.
From the following the bugs may occur.
1. Wrong number of states
2. Wrong transition
3. Wrong output for a given transition
4. Pair of states are wrongly made equivalent
5. Set of states are split to create in equivalent duplicates.
6. Set of states become dead.
State testing is defined as a functional testing technique to test the functional bugs in the entire
system.
The principles for state testing are very similar to the principles of path testing.
For path testing it is not possible to test every possible path in a flowgraph.
Similarly for state testing it is not possible to test every possible path in a state graph.
In a state graph a path is a sequence of transitions
127 caused by a sequence of inputs.
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
In state testing the primary interest is given to the states and transitions rather than outputs.
In state testing define a set of covering input sequences and for each step in each input sequence
define the expected next state, the expected transition and the expected output code.
A set of tests consists of three sets of sequences
1. Input sequences.
2. Corresponding transitions
3. Output sequences.
The limitation is: State transition coverage in a state graph does not guarantee complete testing. The
extension:
Chow defines a hierarchy of paths and methods for combining paths.
The simplest is called a 0 switch which corresponds to test each transition independently.
The next level consists of testing transition sequences consisting of two transitions called 1 switch.
The maximum length switch is an n-1 switch where n is the number of states.
The different advantages are
State testing is useful when the error corrections are less expensive.
State testing is also useful when the testers want to detect a specified input.
A state testing is specifically designed for catching the deep bugs.
A state testing provides easiness during the design of tests. The different disadvantages are
State testing does not provide through testing because when a test is completed there might be some
bugs remains in the system. Testers require large number of input sequences to catch transition
errors, missing states etc..
Combination of hardware & software can be modeled sufficiently complicated state graph.
The state graph is behavioral model that is it is functional rather than structural.
Here labor intensive data gathering is needed and needs more meetings to resolves issues.
128
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
(vi) Tools:
The key to testability design is easy that is we can easily build explicit finite state machines.
For two finite state machines there are only eight good and bad ones.
For three finite state machines there are eighty possible good and bad one.
Similarly for Four state machines 2700 most of which are bad and for five state machines 275000
most of which are bad. For six state machines 100 millions most of which are bad.
(iii) Switches, Flags and unachievable paths :
The functionality of switches and flags are almost similar in the state testing.
Switches or flags are used as essential tool for state testing to test the finite state machine in every
possible state.
A flag or switch value is set at the initial process of finite state machine, and then this value is
evaluated and tested.
Depending on its value the specific path is selected to find an easiest way for testing the finite state
machine.
Mostly the switch or flag works on true or false condition.
In figure a flag is set to p in the program. This p variable is assigned to some value which can be
evaluated.
Depending on its value a path is separated into branches in order to proceed testing in either way
that is u or x
This also can be done by removing a flag and separating v path into two different paths w,y as
shown in the above figure.
Unachievable paths those paths which don’t interact with each other.
Here there are four paths u,w,x,y in that two are not achievable and two are achievable.
That is u is not achievable to path y and path x is not achievable to path w & u is achievable to path
w and path x is achievable to path y. 129
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
Finally both the paths uw and xy are needed to cover the branches.
In the above figure there are three flag variables p,q,r in the program.
These variables are assigned some values that can be evaluated and based on which the paths are
separated into branches.
The main benefit of using this implementation is to remove the unnecessary combination from the
decision tree as shown in the figure c.
To understand an essential and inessential finite state behavior, we need to know the concept of
finite state machines and combinational machines.
There is a difference between finite state machines and combinational machines in terms of quality.
In combinational machines a path is chosen depending on the truth values of predicates.
The predicate truth values are the values which once determined will never change and always
remains constant.
In these machines a path is equivalent to a Boolean algebraic expression over the predicates
Further more it does not matter in which order the decisions are made.
Fine state machine is represented by a state graph having a finite number of states and a finite
number of transitions between states
Finite state machine (FSM) is a functional testing tool and programming testing tool.
That is it is an essential tool for state testing in order to identify or model the behavior of software.
The different guide lines are given below.
1. Initially learn the procedure of finite state machine that are used in both hardware and software.
2. Design an abstract machine in such a way that it works properly and satisfies the user
requirements.
3. Design an explicit finite state machine.
4. Prototype test must be conducted thoroughly to determine the processing time and space of
explicit finite state machine design.
5. If time or space is more effecting the overall system, then use shortcuts to complete the design
process.
6. If there are more than a few numbers of states then use hierarchical design to represent them.
130
Mangayarkarasi College of Arts and Science for Women
Affiliated to Madurai Kamaraj University | Accredited with ‘A’ Grade by NAAC (3rd Cycle) Approved by UGC Under
Section 2(f) Status| ISO 9001:2015 Certified Institution
Paravai, Madurai-625402
7. If there is large number of states then software tools and programming languages must be
developed.
8. The capability to initialize to an arbitrary state must be inbuilt together with the transition
verification instrumentation.
http://www.mcr.org.in/sureshmudunuri/stm/unit4.php#domains_paths
131