11
A Review of Graphs for Testing

A Review of Graphs for Testing

Embed Size (px)

DESCRIPTION

A Review of Graphs for Testing. Directed graphs. A directed graph G(V,E) A finite V = {n 1 , n 2 , …, n m } of nodes A finite set E = {e 1 , e 2 , …, e p } of edges Each edge e k = { n i , n j } is an ordered pair (start and end nodes) V = {n1, n2, n3} - PowerPoint PPT Presentation

Citation preview

Page 1: A Review of Graphs for Testing

A Review of Graphs for

Testing

Page 2: A Review of Graphs for Testing

2

Directed graphs

• A directed graph G(V,E)• A finite V = {n1, n2, …, nm} of nodes• A finite set E = {e1, e2, …, ep} of edges• Each edge ek = {ni, nj} is an ordered pair (start and end

nodes)

• V = {n1, n2, n3}• E = {e1, e2, e3} = {(n1,2), (n2,n3), (n2,n4)}

n1 n2 n3

n4

e1 e2

e3

Page 3: A Review of Graphs for Testing

3

Graph terminology

• Indegree (ni): the number of distinct edges that have ni as a terminal node• Outdegree (ni): the number of distinct edges that

have ni as starting node• Source node: a node with indegree={}• Sink node: a node with outdegree = {}• Transfer node: a node with indegree !={} and

outdegree != {}

Page 4: A Review of Graphs for Testing

4

Graph terminology

• Directed path: a sequence of edges such that for any adjacent pairs of ei, ej, the terminal node of ei is the start node of ej• Connectedness: for two odes ni, nj• 0-connected: iff there is no path between ni, nj• 2-connected: iff there is a path between ni, nj• 3-connected: iff there is a path from ni to nj and a path

from nj to ni

• Strongly connected graph: all pairs of nodes are 3-connected

Page 5: A Review of Graphs for Testing

5

Program graphs

• Given a program in an imperative language, its graph is a directed graph in which noes are either entire statements or fragments of a statement and edges represent flow of control

Page 6: A Review of Graphs for Testing

6

Program graphs

• Given a program in an imperative language, its graph is a directed graph in which noes are either entire statements or fragments of a statement and edges represent flow of control

Page 7: A Review of Graphs for Testing

7

Program graphs

Page 8: A Review of Graphs for Testing

8

Program flowgraph: an example

Page 9: A Review of Graphs for Testing

9

Program flowgraph: another example

Page 10: A Review of Graphs for Testing

10

Cyclomatic complexity

• The cyclomatic number of a graph G is given by• V(G) = e – n + 2, where• e is the number of edges in G• n is the number of nodes in G

• Cyclomatic complexity pertains to both ordinary and directed graphs• V(G) is sometimes called McCabe Complexity after

Thomas McCabe

Page 11: A Review of Graphs for Testing

11

Cyclomatic complexity

• Used for testing (identifying the number of independent paths) and design (reduce complexity)• It gives the number of independent paths from in a

program (also called the basis path)• It provides the degree of complexity