Cause-Effect Graphing
Cause-Effect Graphing
Graphing
2
Why Test?
4
How Do You Test a Program?
5
How Do You Test a Program?
6
What’s So Hard About Testing ?
Consider int proc1(int x, int y)
Assuming a 64 bit computer
Input space = 2128
9
Overview of Testing Activities
Afailure is a manifestation of
an error (also defect or bug).
Mere presence of an error may not
lead to a failure.
11
Pesticide Effect
12
Pesticide Effect
13
Fault Model
14
Fault Model of an OO Program
OO Faults
Structural Algorithmic
Faults Faults
Procedural Traceability
OO Incorrect Inadequate
Result Performance
Faults Faults Faults
15
Hardware Fault-Model
Simple:
Stuck-at 0
Stuck-at 1
Open circuit
Short circuit
Simple ways to test the presence of each
Hardware testing is fault-based testing
16
Software Testing
17
Test Cases and Test Suites
21
Design of Test Cases
Exhaustive testing of any non-
trivial system is impractical:
Input data domain is extremely large.
Design an optimal test suite:
Of reasonable size and
Uncovers as many errors as
possible. 22
Design of Test Cases
26
Design of Test Cases
27
Black-Box Testing
33
Cause and Effect Graphs
34
Cause and Effect Graphs
A B
If A then B
A
C
B
If (A and B)then C
38
Drawing Cause-Effect Graphs
A
C
B
If (A or B)then C
A
C
B
If (not(A and B))then C
39
Drawing Cause-Effect Graphs
A
C
B
If (not (A or B))then C
A B
If (not A) then B
40
Cause effect graph- Example
Processing
The function calculates whether the
level is safe, too high, or too low.
Output
message on screen
level=safe
level=high
invalid syntax
42
Cause effect graph- Example
or safe.
44
Cause effect graph- Example
Command is
syntactically valid
Operands are
syntactically valid.
45
Cause effect graph- Example
Three effects
level = safe
level = high
invalid syntax
46
Cause effect graph- Example
1 10 E
3
2 11
3 E
1
4
E
5 2
47
Cause effect graph- Decision table
Test 1 Test 2 Test 3 Test 4 Test 5
Cause 1 I I I S I
Cause 2 I I I X S
Cause 3 I S S X X
Cause 4 S I S X X
Cause 5 S S I X X
Effect 1 P P A A A
Effect 2 A A P A A
Effect 3 A A A P P
48
Cause effect graph- Example
50
Cause effect graph- Example
51
Cause effect graph- Example
52
Cause effect graph
54
Basic elements of a cause-effect graph
implication
not (~)
and (^)
or (v)
not C implies Ef
C implies Ef
C Ef C Ef
C2 ^ Ef v Ef
C3 C2
C, C1, C2, C3 denote causes.
Ef denotes an effect.
55
Semantics of basic elements
56
Constraints amongst causes (E,I,O,R)
Constraints show the relationship between the
causes.
Exclusive (E)
Inclusive (I)
Requires (R)
One and only one (O)
Exclusive: either C1 or C2 or C3 Inclusive: at least C1 or
C2
C1 C1
E I
C2
C2
C3
One and only one, of C1 and C2
C1 requires C2
C1
C1 O
R 57
C2 C2
Constraints amongst causes (E,I,O,R)
Identification of
all causes and
effects
Design the
cause-effect
graph
Apply constraints, if
any
updated.
Example
Any free printer and RAM available with the CPU selection is
displayed in a different window marked “Free”.
The total price, including taxes, for the items purchased is
calculated and displayed in the “Price” window.
Selection of a monitor could also change the items displayed
in the “Free” window.
Sample configurations and contents of the “Free” window
are given below.
C1
Ef1
E C2
C3 v Ef2
C4
^ Ef3
C5
Ef4
C6
1
C7
70
C8
Example
From the above cause-effect graph, followings can be inferred.
C1, C2 and C3 are constrained using the E (exclusive) relationship.
This expresses the requirement that only one CPU can be purchased in one
order.
Similarly, C3 and C8 are related via the R (requires) constraint to express the
requirement that monitor M 30 can only be purchased with CPU3.
Relationships amongst causes and effects are expressed using the basic
elements.
There is an intermediate node labelled 1 in the graph.
Such intermediate nodes are often useful when an effect depends on
conditions combined using more than one operator, for example,
(C1^C2)vC3.
Also it can be noted that
Purchase of printers and monitors without any CPU leads to no free item
(Ef4).
71
Example
The relationships between effects and causes shown
in the graph can be expressed in terms of Boolean
expressions as follows:
Ef1=C1
Ef2=C2vC3
Ef3=C3^C8
Ef4=C4^C5^C6^C7
72
Another example
Consider the example of keeping the record of
marital status and number of children of a citizen.
The value of marital status must be `U' or `M'.
The value of the number of children must be digit or
null in case a citizen is unmarried.
Ifthe information entered by the user is correct then
an update is made.
Ifthe value of marital status of the citizen is
incorrect, then the error message 1 is issued.
Similarly,if the value of the number of children is
incorrect, then the error message 2 is issued.
73
Answer
Causes are
c1: marital status is U
c2: marital status is M
c3: number of children is a digit
Effects are
e1: updation made
e2: error message 1 is issued
e3: error message 2 is issued
74
Answer
c1 e1
E v ^
c2 e2
R
c3 e3
C1
C2 v a e
^ b
C3
80
Example
81
Example: Generating tests using heuristics
First we note that node a matches the OR-node shown in the top half of
Table 1.
As we want the state of node a to be 0, heuristic H1 applies in this
situation.
H1 asks to enumerate all combinations of inputs to node a such that C1
and node b are 0.
(0,0) is the only such combination and is listed in the last column of the
following table.
C1 C2 C3 Inputs to node a
1 0 0 0 C1=0, b=0
2 0 0 1
3 0 1 0
4 0 1 1 C1=0, b=1
5 1 0 0 C1=1, b=0
6 1 0 1 82
7 1 1 0
Example: Generating tests using heuristics
83
Example: Generating tests using heuristics
Though not required here, suppose that we were to
consider the combination C1=0,b=1.
Heuristic H4 applies in this situation.
As both C2 and C3 are causes with no preceding
nodes,
the only combination we obtain now is (1,1).
Combining this with C1=0 we obtain sequence 4
listed in the preceding table.
84
Example: Generating tests using heuristics
C1 C2 C3 Inputs to node a
1 0 0 0 C1=0, b=0
2 0 0 1
3 0 1 0 85
Example: Generating tests using heuristics
Let us examine the rationale underlying the various
heuristics for reducing the number of combinations.
Heuristics H1 does not save us on any combinations.
The only way an OR-node can cause its effect e to be 0 is
for all its inputs to be 0.
H1 suggests that we enumerate all such combinations.
Heuristics H2 suggests we use all combinations that cause
e to be 1 except those that cause n1=n2=0.
To understand the rationale underlying H2 consider a
program required to generate an error message when
condition c1 or c2 is true.
A correct implementation of this requirement is given
below. 86
if(c1 v c2)printf(“Error”);
Example: Generating tests using heuristics
*/
Procedure for generating a decision table from a
cause-effect graph
Step 1 Initialize DT to an empty decision table.
next_dt_col=1.
Step 2 Execute the following steps for i=1 to q.
2.1 Select the next effect to be processed.
Let e=Efi.
2.2 Find combinations of conditions that cause e to be present.
Assume that e is present. Starting at e, trace the cause-
effect graph backwards and determine the combinations of
conditions C1, C2, …, Cp that lead to e being present.
Let V1, V2, …, Vmi be the combinations of causes that lead to e
being present, i.e. in 1 state, and hence mi≥1. Set Vk(l),p<l≤p+q
to 0 or 1 depending on whether effect Efl-p is present92or not for the
combination of all conditions in Vk.
Procedure for generating a decision table from a
cause-effect graph
C1
^ 1 2 Ef1
R v
C2
^
E
C3 3 Ef2
C4
94
Example
Step 1: Set next_dt_col=1 to initialize the decision table to
empty.
Next, i=1 and in accordance with Step 2.2, e=Ef1.
In accordance with Step 2.2, trace backwards from e to
determine combinations that will cause e to be present.
e must be present when node 2 is in 1-state.
Moving backwards from node 2 in the cause-effect graph,
any of the following three combinations of states of nodes 1
and C3 will lead to e being present: (0,1), (1,1) and (0,0).
Node 1 is also an internal node and hence move further back
to obtain the values of C1 and C2 that effect node 1.
Combinations of C1 and C2 that brings node 1 to the 1-state is
(1,1) and combinations that bring it to 0-state are (1,0),(0,1)
95
and (0,0).
Example
Combining this information with that derived earlier for
nodes 1 and C3, we obtain the following seven combinations
of C1, C2 and C3 that cause e to be present.
1 0 1
0 1 1
0 0 1
1 1 1
1 0 0
0 1 0
0 0 0
Next, C3 requires C1 which implies that C1 must be in 1-state
for C3 to be in 1-state.
96
to Step 2.1.
Example
We now have e=Ef2.
Tracing backwards, we find that for e to be present, node 3 must be in
the 1-state.
This is possible with only one combination of node 2 and C4, which is
(1,1).
Earlier we derived the combinations of C1, C2 and C3 that lead node 2
into the 1-state.
Combining these with the value of C4, we arrive at the following
combination of causes that lead to the presence of Ef2.
1 0 1 1
1 1 1 1
1 0 0 1
0 1 0 1
0 0 0 1
99
Example
From the cause-effect graph, note that C2 and C4 cannot be
present simultaneously.
Hence, we discard the second and fourth combinations from
the list above and obtain the following three feasible
combinations.
1 0 1 1
1 0 0 1
0 0 0 1
Appending the corresponding values of Ef1 and Ef2 to each of
the above combinations, we obtain the following three
vectors.
V1 1 0 1 1 1 1
V2 1 0 0 1 1 1
100
Example
Transposing the vectors listed above and appending them as
three columns to the existing decision table, we obtain the
following
1 2 3 4 5 6 7 8
C1 1 1 1 0 0 1 1 0
C2 0 1 0 1 0 0 0 0
C3 1 1 0 0 0 1 0 0
C4 0 0 0 0 0 1 1 1
Ef1 1 1 1 1 1 1 1 1
Ef2 0 0 0 0 0 1 1 1
103
Answer
Causes are
c1: Age is over 21
c2: Driving record is clean
c3: Tourist is on business
Effects are
e1: Supply a rental car without premium charge
e2: Supply a rental car with premium charge
e3: Car cannot be supplied
c1 e1
^ ^
c2 ^ e2
c3 e3 104
Decision Table and Test Cases
1 2 3 4
c1: Over 21? F T T T
c2: Driving record clean? - F T T
c3: On business? - - F T
e1: Supply a rental car without premium charge X
e2: Supply a rental car with premium charge X
e3: Car cannot be supplied X X
106
Answer
Causes are:
c1: side “a” is less than the sum of sides “b” and “c”.
c2: side “b” is less than the sum of sides “a” and “c”.
c3: side “c” is less than the sum of sides “a” and “b”.
c4: square of side “a” is equal to the sum of squares of sides “b” and “c”.
c5: square of side “a” is greater than the sum of squares of sides “b” and
“c”.
c6: square of side “a” is less than the the sum of squares of sides “b” and
“c”.
Effects are:
e1: Invalid triangle
e2: Right angle triangle
e3: Obtuse angled triangle
e4: Acute angled triangle
e5: Impossible stage 107
Cause-Effect Graph
c1
c2 v e1
c3
^
c4 e2
^
E c5 e3
^
c6 e4
^
108
e5
Decision Table
1 2 3 4 5 6 7 8 9 10 11
c1: a<b+c F T T T T T T T T T T
c2: b<a+c - F T T T T T T T T T
c3: c<a+b - - F T T T T T T T T
c4: a2=b2+c2 - - - T T T T F F F F
c5: a2>b2+c2 - - - T T F F T T F F
c6: a2<b2+c2 - - - T F T F T F T F
e5: Impossible X X X X X
Thank You
110