0% found this document useful (1 vote)
304 views

Cause-Effect Graphing

The document discusses cause-effect graphing, which is a black-box testing technique. It involves modeling dependency relationships between program inputs (causes) and outputs (effects) visually in a cause-effect graph. The graph represents logical relationships between inputs and outputs as a Boolean expression. This allows test cases to be generated by selecting combinations of input values, avoiding combinatorial explosion. Causes are conditions that may affect outputs, while effects are program responses. Cause-effect graphs can be used to automatically generate test cases from requirements specifications.

Uploaded by

Harsh Rangwani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (1 vote)
304 views

Cause-Effect Graphing

The document discusses cause-effect graphing, which is a black-box testing technique. It involves modeling dependency relationships between program inputs (causes) and outputs (effects) visually in a cause-effect graph. The graph represents logical relationships between inputs and outputs as a Boolean expression. This allows test cases to be generated by selecting combinations of input values, avoiding combinatorial explosion. Causes are conditions that may affect outputs, while effects are program responses. Cause-effect graphs can be used to automatically generate test cases from requirements specifications.

Uploaded by

Harsh Rangwani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 110

Cause-Effect

Graphing

Dr. Durga Prasad Mohapatra


Professor
CSE Department
NIT Rourkela
[email protected]
Plan of the Talk
 Introduction to Testing
 Cause Effect Graphing
 Procedure used for the generation of tests
 Basic elements of a cause-effect graph
 Constraints amongst causes
 Constraint amongst effects
 Creating Cause-Effect Graph
 Test generation from a decision table
 Decision Table from cause-effect graph

2
Why Test?

• Ariane 5 rocket self-destructed 37 seconds after launch


• Reason: A control software bug that went undetected
– Conversion from 64-bit floating point to 16-bit signed integer
value had caused an exception
• The floating point number was larger than 32767
• Efficiency considerations had led to the disabling of the exception
handler.
• Total Cost: over $1 billion 3
How Do You Test a Program?

Input test data to the program.


Observe the output:
Check if the program behaved as
expected.

4
How Do You Test a Program?

5
How Do You Test a Program?

Ifthe program does not behave as


expected:
Note the conditions under which it
failed.
Later debug and correct.

6
What’s So Hard About Testing ?
Consider int proc1(int x, int y)
Assuming a 64 bit computer
Input space = 2128

Assuming it takes 10secs to key-in an integer pair


It would take about a billion years to enter all
possible values!

Automatic testing has its own problems! 7


Testing Facts
Consumes largest effort among all
phases
Largestmanpower among all other
development roles
Implies more job opportunities
About 50% development effort
But 10% of development time?
How? 8
Testing Facts

Testingis getting more complex


and sophisticated every year.
Larger and more complex
programs
Newer programming paradigms

9
Overview of Testing Activities

Test Suite Design


Run test cases and observe
results to detect failures.
Debug to locate errors
Correct errors.
10
Error, Faults, and Failures

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

Errorsthat escape a fault detection


technique:
Can not be detected by further
applications of that technique.

12
Pesticide Effect

Assume we use 4 fault detection


techniques and 1000 bugs:
Each detects only 70% bugs
How many bugs would remain
1000*(0.3)4=81 bugs

13
Fault Model

Types of faults possible in a


program.
Some types can be ruled out
Concurrency related-problems in
a sequential program

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

 Eachtest case typically tries to


establish correct working of some
functionality
 Executes (covers) some program
elements
 For
restricted types of faults, fault-
based testing exists.

17
Test Cases and Test Suites

Test a software using a


set of carefully designed
test cases:
The set of all test cases
is called the test suite
18
Test Cases and Test Suites

A test case is a triplet [I,S,O]


I is the data to be input to the
system,
S is the state of the system at which
the data will be input,
O is the expected output of the
system.
19
Verification versus Validation
Verification
is the process of
determining:
Whether output of one phase of
development conforms to its previous
phase.
Validation is the process of determining:

Whether a fully developed system conforms


to its SRS document. 20
Verification versus Validation

Verificationis concerned with


phase containment of errors,
Whereas the aim of validation is
that the final product be error
free.

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

If test cases are selected randomly:


Many test cases would not contribute to the
significance of the test suite,
Would not detect errors not already being
detected by other test cases in the suite.
Number of test cases in a randomly
selected test suite:
Not an indication of effectiveness of testing.
23
Design of Test Cases
Testinga system using a large number of
randomly selected test cases:
Does not mean that many errors in
the system will be uncovered.
Consider following example:
Findthe maximum of two integers x
and y.
24
Design of Test Cases
The code has a simple programming
error:
 if (x>y) max = x;
else max = x;
Testsuite {(x=3,y=2);(x=2,y=3)} can
detect the error,
A larger test suite {(x=3,y=2);
(x=4,y=3); (x=5,y=1)} does not detect
the error. 25
Design of Test Cases

Systematic approaches are


required to design an optimal test
suite:
Each test case in the suite should
detect different errors.

26
Design of Test Cases

Thereare essentially three main


approaches to design test cases:
Black-box approach
White-box (or glass-box) approach
Grey-box testing

27
Black-Box Testing

Test cases are designed using only


functional specification of the
software:
Without any knowledge of the internal
structure of the software.
For this reason, black-box testing is
also known as functional testing.
28
Black Box Testing
 Approaches to design black box test cases
 Requirements Based Testing
 Positive and Negative Testing
 Boundary Value Analysis (BVA)
 Boundary Value Checking (BVC)
 Robustness Testing
 Worst-Case Testing
 Equivalence Partitioning
 State Table Based Testing
 Decision Table Based
 Cause-Effect Graphing
 Compatibility Testing
 User Documentation Testing
29
 Domain Testing
Cause-Effect Graphing
 Cause-effect graphing, also known as dependency modeling,
 focuses on modelling dependency relationships amongst
 program input conditions, known as causes, and
 output conditions, known as effects.
 The relationship is expressed visually in terms of a cause-
effect graph.
 The graph is a visual representation of a logical relationship
amongst inputs and outputs that can be expressed as a
Boolean expression.
 The graph allows selection of various combinations of input
values as tests.
 The combinatorial explosion in the number of tests is
avoided by using certain heuristics during test generation.
30
Cause-Effect Graphing (Contd..)
 A cause is any condition in the requirements that may
effect the program output.
 An effect is the response of the program to some
combination of input conditions.
 For example, it may be
 An error message displayed on the screen
 A new window displayed
 A database updated.
 An effect need not be an “output” visible to the user of the
program.
 Instead, it could also be an internal test point in the
program that can be probed during testing to check if some
intermediate result is as expected.
 For example, the intermediate test point could be31 at the entrance
into a method to indicate that indeed the method has been
invoked.
Example

 Considerthe requirement “Dispense food only


when the DF switch is ON”
 Cause is “DF switch is ON”.
 Effect is “Dispense food”.
 This requirement implies a relationship between
the “DF switch is ON” and the effect “Dispense
food”.
 Other requirements might require additional
causes for the occurrence of the “Dispense food”
effect.
32
Cause and Effect Graphs

 Testing would be a lot easier:


 if we could automatically generate test cases from
requirements.
 Work done at IBM:

 Can requirements specifications be systematically used to


design functional test cases?

33
Cause and Effect Graphs

Examine the requirements:


restatethem as logical relation
between inputs and outputs.
The result is a Boolean graph
representing the relationships
called a cause-effect graph.

34
Cause and Effect Graphs

Convert the graph to a


decision table:
each column of the
decision table corresponds
to a test case for
functional testing.
35
Steps to create cause-effect graph

Study the functional


requirements.
Mark and number all causes
and effects.
Numbered causes and effects:
become nodes of the graph.
36
Steps to create cause-effect graph

Draw causes on the LHS


Draw effects on the RHS
Draw logical relationship
between causes and effects
as edges in the graph.
Extra nodes can be added
to simplify the graph
37
Drawing Cause-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

A water level monitoring


system
used by an agency involved in
flood control.
Input: level(a,b)
a is the height of water in dam
in meters
b is the rainfall in the last 24
hours in cms
41
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

We can separate the


requirements into 5 clauses:
first five letters of the command
is “level”
command contains exactly two
parameters
separated by comma and enclosed
in parentheses
43
Cause effect graph- Example

 Parameters A and B are real numbers:


 such that the water level is calculated to be low

 or safe.

 The parameters A and B are real numbers:


 such that the water level is calculated to be high.

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

Put a row in the decision


table for each cause or
effect:
in the example, there are
five rows for causes and
three for effects.
49
Cause effect graph- Example

The columns of the decision


table correspond to test cases.
Define the columns by
examining each effect:
list each combination of causes
that can lead to that effect.

50
Cause effect graph- Example

We can determine the


number of columns of the
decision table
by examining the lines
flowing into the effect nodes
of the graph.

51
Cause effect graph- Example

Theoretically we could have


generated 25=32 test cases.
Using cause effect graphing
technique reduces that
number to 5.

52
Cause effect graph

Not practical for systems


which:
include timing aspects
feedback from processes
is used for some other
processes.
53
Procedure used for the generation of tests
 Identifycauses and effects by reading the
requirements. Each cause and effect is assigned a
unique identifier. Note that an effect can also be a
cause for some other effect.
 Express the relationship between causes and
effects using a cause-effect graph.
 Transform the cause-effect graph into a limited
entry decision table, hereafter referred to as
decision table.
 Generate tests from the decision table.

54
Basic elements of a cause-effect graph
 implication
 not (~)
 and (^)
 or (v)
not C implies Ef
C implies Ef
C Ef C Ef

Ef when C1 and C2 and C3 Ef when C1 or C2


C1 C1

C2 ^ Ef v Ef

C3 C2
 C, C1, C2, C3 denote causes.
 Ef denotes an effect.
55
Semantics of basic elements

 C implies Ef: if(C) then Ef;


 not C implies Ef: if(⌐C) then Ef;
 Ef when C1 and C2 and C3: if(C1&&C2&&C3) then Ef;
 Ef when C1 or C2: if(C1||C2) then Ef;

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)

 Exclusive(E) constraint between three causes C1, C2


and C3 implies that exactly one of C1, C2, C3 can be
true.
 Inclusive(I) constraint between two causes C1 and
C2 implies that at least one of the two must be
present.
 Requires (R) constraint between C1 and C2 implies
that C1 requires C2.
 One and only one (O) constraint models the
condition that one, and only one, of C1 and C2 must
58
Possible values of causes constrained by
E, I, R,O
A 0 or 1 under a cause implies that the
corresponding condition is, respectively, false and
true.
 The arity of all constraints, except R, is greater
than 1, i.e., all except the R constraint can be
applied to two or more causes; the R constraint is
applied to two causes.
A condition that is false (true) is said to be in the
“0-state” (1 state).
 Similarly,an effect can be “present” (1 state) or
“absent” (0 state). 59
Possible values of causes constrained by E,
I, R,O
Constraint Arity Possible values
C1 C2 C3
E(C1,C2,C3) n≥2 0 0 0
1 0 0
0 1 0
0 0 1
I(C1,C2) n≥2 1 0 -
0 1 -
1 1 -
R(C1,C2) n=2 1 1 -
0 0 -
0 1 -
O(C1,C2,C3) n≥2 1 0 0
60
0 1 0
0 0 1
Constraint amongst effects
 Masking (M)

Ef1 masks Ef2


Ef1
M
Ef2

 Masking (M) constraint between two effects Ef1 and


Ef2 implies that if Ef1 is present, then Ef2 is forced to
be absent.
61
Steps for generating test cases using Cause-Effect
Graph

Identification of
all causes and
effects

Design the
cause-effect
graph
Apply constraints, if
any

Design limited entry


decision table from
graph

Write test cases using


every column
62 of the
decision table
Creating Cause-Effect Graph
 The process of creating a cause-effect graph consists of two
major steps.
 The causes and effects are identified by a careful
examination of the requirements.
 This process also exposes the relationships amongst various causes
and effects as well as constraints amongst the causes and effects.
 Each cause and effect is assigned a unique identifier for ease of
reference in the cause-effect graph.
 The cause-effect graph is constructed to
 express the relationships extracted from the requirements.
 When the number of causes and effects is large, say over
100 causes and 45 effects,
 it is appropriate to use an incremental approach.
63
Example
 Consider the task of test generation for a GUI based computer purchase
system.
 A web-based company is selling computers (CPU), printers (PR), monitors
(M), and additional memory (RAM).
 An order configuration consists of one to four items as shown below.
CPU 1 PR 1 M 20 RAM 256
CPU 2 PR 2 M 23 RAM 512
CPU 3 M 30 RAM 1G
 The GUI consists of four windows for displaying selections from CPU,
Printer, Monitor and RAM and one window where any free giveaway
items are displayed.
 For each order, the buyer may select from three CPU models, two
printer models, and three monitors.
 There are separate windows one each for CPU, printer, and monitor that
show the possible selections.
64
 For simplicity, assume that RAM is available only as an upgrade and that
only one unit of each item can be purchased in one order.
Example
 Monitors M 20 and M 23 can be purchased with any CPU or as
a stand-alone item.
 M 30 can only be purchased with CPU 3.
 PR 1 is available free with the purchase of CPU 2 or CPU 3.
 Monitors and printers, except for M 30, can also be purchased
separately without purchasing any CPU.
 Purchase of CPU 1 gets RAM 256 upgrade.
 Purchase of CPU 2 or CPU 3 gets a RAM 512 upgrade.
 The RAM 1G upgrade and a free PR 2 is available when CPU 3
is purchased with monitor M 30.
 When a buyer selects a CPU, the contents of the printer and
monitor windows are updated. Similarly, if a printer or a
monitor is selected, contents of various windows are
65

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.

Items purchased “Free” window Price


CPU 1 RAM 256 $499
CPU 1, PR 1 RAM 256 $628
CPU 2, PR 2, M 23 PR 1, RAM 512 $2257
CPU 3, M 30 PR 2, RAM 1G $3548
66
Example
 The first step in creating cause-effect graphing is to read the
requirements carefully and make a list of causes and effects.
 A unique identifier, C1 through C8, has been assigned to each cause.
 Each cause listed below is a condition that can be true or false.
 C1: Purchase CPU 1.
 C2: Purchase CPU 2.
 C3: Purchase CPU 3.
 C4: Purchase PR 1.
 C5: Purchase PR 2.
 C6: Purchase M 20.
 C7: Purchase M 23.
 C8: Purchase M 30.
 For example, C8 is true if monitor M 30 is purchased. 67
Example
 Note that while it is possible to order any of the items listed
above, the GUI will update the selection available depending
on which CPU, or any Other item, is selected.
 For example, if CPU 3 is selected for purchase then monitors
M 20 and M 23 will not be available in the monitor selection
window.
 Similarly, if monitor M 30 is selected for purchase, then CPU
1 and CPU 2 will not be available in the CPU window.
 Next, we identify the effects.
 In this example, the application software calculates and
displays the list of items available free with the purchase
and the total price.
 Hence, the effect is in terms of the contents of the “Free”
and “Price” windows. 68
Example
 Calculation of the total purchase price depends on the items
purchased and the unit price of each item.
 The unit price is obtained by the application from a price
database.
 The price calculation and display is a cause that creates the
effect of displaying the total price.
 For simplicity, we ignore the price related cause and effect.
 The set of effects in terms of the contents of the “Free”
display window are listed below.
Ef1: RAM 256
Ef2: RAM 512 and PR 1.
Ef3: RAM 1G and PR 2.
69
Ef4: No giveaway with this item.
Example

 Following shows the complete graph that expresses the


relationships between C1 through C8 and effects Ef1 through Ef4.

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

 There are two constraints


 Exclusive (between c1 and c2) and
 Requires (between c3 and c2)
 Causes c1 and c2 cannot occur simultaneously.
 For cause c3 to be true, cause c2 has to be true.
75
Heuristics to avoid combinatorial explosion
 While tracing back through a cause-effect graph,
 we generate combinations of causes that set an intermediate node,
or an effect, to a 0 or 1 state.
 Doing so in a brute force manner could lead to a large
number of combinations.
 In the worst case, if n causes are related to an effect e, then
the maximum number of combinations that bring e to a 1-
state is 2n.
 As tests are derived from the combinations of causes,
 large values of n could lead to an exorbitantly large number of tests.
 We avoid such a combinatorial explosion by using simple
heuristics related to the “AND” (^) and “OR” (v) nodes.
 Heuristics are based on the assumption that
76
 certain types of errors are less likely to occur than others.
Heuristics to avoid combinatorial explosion
 Thus, while applying the heuristics to generate
test
inputs will likely lead to a significant reduction
in the number of tests generated,
itmay also discard tests that would have
revealed a program error.
 Hence,one must apply the heuristics with
care and only when
the number of tests generated without their
application is too large to be useful in practice.
77
Heuristics used during the generation of input
combinations from a cause-effect graph
 The heuristics are labelled H1 through H4.
 Theleftmost column shows the node type in the
cause-effect graph.
 Thecenter column is the desired state of the
dependent node.
 Therightmost column is the heuristics for generating
combinations of inputs to the nodes that effect the
dependent node e.
 Forsimplicity, only two nodes n1 and n2 and the
corresponding effect e are shown. 78
Heuristics used during the generation of input
combinations from a cause-effect graph
Table 1
Node type Desired Input combinations
state of e

n1 0 H1: Enumerate all combinations of inputs


---
to n1 and n2 such that n1=n2=0.
--- v e
--- 1 H2: Enumerate all combinations of inputs
--- n2 to n1 and n2 other than those for which
n1=n2=0.
0 H3: Enumerate all combinations of input
to n1 and n2 such that each of the possible
--- n1 combinations of n1 and n2 appears exactly
--- v e once and n1=n2=1 does not appear. Note
--- that for two nodes, there are three such
--- n2
combinations: (0,0), (0,1) and (1,0). In
general, for k nodes combined using the
logical and operator to form e, there are
2k-1 such combinations.
79
1 H4: Enumerate all combinations of inputs
to n1 and n2 such that n1=n2=1.
Example
 Consider the following cause-effect graph.
 We have at least two choices while tracing backwards
to derive the necessary combinations.
 Derive all combinations first and then apply the heuristics.
 Derive combinations while applying the heuristics.

C1

C2 v a e

^ b

C3
80
Example

 Suppose we require node e to be 1.


 Tracing backwards, this requirement implies that node a
must be a 0 (zero).
 If we trace backwards further, without applying any
heuristic, we obtain the following seven combinations of
causes that bring e to 1 state.
 The last column lists the inputs to node a.
 The combinations that correspond to the inputs to node a
listed in the rightmost column are separated by horizontal
lines.

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

 Let us begin with (0,0)


 No heuristic applies to C1 as it has no preceding nodes.
 Node b is an AND-node as shown in the bottom half of Table.
 We want node b to be 0 and therefore H3 applies.
 In accordance with H3 we generate three combinations of
inputs to node b: (0,0), (0,1) and (1,0).
 Notice that combination (1,1) is forbidden.
 Joining these combinations of C2 and C3 with C1=0,
 we obtain the first three combinations listed in the preceding table.

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

 We have completed derivation of combinations using


the heuristics listed in Table 1.
 Note that the combinations listed above for C1=1,b=0
are not required.
 Thus, we have obtained only three combinations
instead of the seven enumerated earlier.
 The reduced set of combinations is listed below.

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

 Now consider the following erroneous implementation of


the same requirement.
if(c1 v ¬c2)printf(“Error”);
 A test that sets both c1 and c2 true
 will not be able to detect an error in the implementation above
 if short circuit evaluation is used for Boolean expressions.
 However, a test that sets c1=0 and c2=1 will be able to
detect this error.
 Hence H2 saves us from generating all input combinations
that generate the pair (1,1) entering an effect in an OR-
node.
87
Example: Generating tests using
heuristics
 Heuristics
H3 saves us from repeating the
combinations of n1 and n2.
 Once again this could save us a lot of tests.
 The assumption here is that
 any error in the implementation of e will be
detected by
 tests that cover different combinations of n1 and
n2.
 Thus, there is no need to have two or more
tests that 88

 contain the same combination of n1 and n2.


Example: Generating tests using
heuristics
 Lastly, H4 for the AND-node is analogous to H1 for the OR-
node.
 The only way an AND-node can cause its effect e to be 1
 is for all its inputs to be 1.
 H4 suggests that we enumerate all such combinations.
 We stress, once again, that
 while the heuristics will likely reduce the set of tests generated
using cause-effect graphing,
 they might also lead to useful tests being discarded.
 Of course, in general and prior to the start of testing,
 it is almost impossible to know which of the test cases discarded
will be useless and which ones useful. 89
Decision Table from cause-effect graph
 Each column of the decision table represents a combination
of input values, and hence a test.
 There is one row for each condition and effect.
 Thus the table decision table can be viewed as an N X M
matrix with
 N being the sum of the number of conditions and effects and
 M the number of tests.
 Each entry in the decision table is a 0 or 1
 depending on whether or not the corresponding condition is false or
true, respectively.
 For a row corresponding to an effect, an entry is 0 or 1
 if the effect is not present or present, respectively.
90
Procedure for generating a decision table from a cause-
effect graph
 Input: A cause-effect graph containing causes C1, C2, …, Cp and
effects Ef1, Ef2, …, Efq.
 Output: A decision table DT containing N=p+q rows and M
columns, where M depends on the relationship between the
causes and effects as captured in the cause-effect graph.
 Procedure: CEGDT
 /*
 i is the index of the next effect to be considered.
 next_dt_col is the next empty column in the decision table.
 Vk: a vector of size p+q containing 1’s and 0’s. Vj, 1≤j≤p,
indicates the state of condition Cj and Vl, p<l ≤ p+q, indicates the
presence or absence of effect Efl-p.
91

 */
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

2.3 Update the decision table.


Add V1, V2, …, Vmi to the decision table as successive
columns starting at next_dt_col.
2.4 Update the next available column in the decision
table.
next_dt_col=next_dt_col+mi. At the end of this
procedure, next_dt_col-1 is the number of tests
generated.
 End of Procedure CEGDT
93
Example
 Consider the cause effect graph shown below.
 It shows four causes labelled C1, C2, C3 and C4 and two
effects labeled Ef1 and Ef2.
 There are three intermediate nodes labeled 1, 2 and 3.

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

 This constraint makes infeasible the second and third


Example
 In the end, we obtain the following five combinations of the four causes
that lead to e being present.
1 0 1
1 1 1
1 0 0
0 1 0
0 0 0
 Setting C4 to 0 and appending the values of Ef1 and Ef2, we obtain the
following five vectors.
V1 1 0 1 0 1 0
V2 1 1 1 0 1 0
V3 1 0 0 0 1 0
V4 0 1 0 0 1 0
V5 0 0 0 0 1 0 97
Example
 Note that m1=5 in Step 2.
 This completes the application of Step 2.2.
 The five vectors are transposed and added to the decision
table starting at column next_dt_col which is 1.
 The decision table at Step 2.3 follows
1 2 3 4 5
C1 1 1 1 0 0
C2 0 1 0 1 0
C3 1 1 0 0 0
C4 0 0 0 0 0
Ef1 1 1 1 1 1
Ef2 0 0 0 0 0

 We update next_dt_col to 6, increment i to 2 and get back


98

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

 Next, we update next_dt_col to 9.


 Of course, doing so is useless as the loop set up in Step 2 is
now terminated.
 The decision table listed above is the output. 101
Test generation from a decision table
 Test generation from a decision table is relatively forward.
 Each column in the decision table generates at least one test
input.
 Note that each combination might be able to generate more
than one test when a condition in the cause-effect graph can
be satisfied in more than one way.
 For example, consider the following cause:
 C: x<99
 The condition above can be satisfied by many values such as
x=1 and x=49.
 Also, C can be made false by many values of x such as x=100
and x=999.
 Thus, one might have a choice of values of input variables
102

while generating tests using columns from a decision table


Example
 A tourist of age greater than 21 years and having a
clean driving record is supplied a rental car.
A premium amount is also charged if the tourist is on
business,
 Otherwise, it is not charged.
 Ifthe tourist is less than 21 year old, or does not
have a clean driving record,
 The system will display the following message: “Car
cannot be supplied”.

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

Test Age Driving_record_clean On_business Expected Output


Case
1 20 Yes Yes Car cannot be supplied

2 26 No Yes Car cannot be supplied

3 62 Yes No Supply a rental car without


premium charge
4 62 Yes Yes Supply a rental car with
105
premium charge
Example 2: Triangle Classification Problem

 Consider a program for classification of a triangle.


 Its input is a triple of positive integers (say a, b and c) and
the input values are greater than zero and less than or equal
to 100.
 The triangle is classified according to the following rules:
 Right angled triangle: c2=a2+b2 or a2=b2+c2 or b2=c2+ a2
 Obtuse angled triangle: c2>a2+b2 or a2>b2+c2 or b2>c2+ a2
 Acute angled triangle: c2<a2+b2 or a2<b2+c2 or b2<c2+a2
 The program output may have one of the following words: [Acute
angled triangle, Obtuse angled triangle, Right angled triangle, Invalid
triangle, Input values are out of range]

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

e1: Invalid triangle X X X

e2: Right angle triangle X

e3: Obtuse angled X


triangle
e4: Acute angled X
triangle
109

e5: Impossible X X X X X
Thank You

110

You might also like