STMT Unit-4
STMT Unit-4
UNIT IV
Overview
Decision tables
Path expressions
KV charts
Specifications
Overview:
The fundamental requirements of many programs can be specified by decision
tables, which provide a useful basis for program and test design. 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.
“Logic” is one of the most often used words in programmer‟s vocabularies but
one of their least used techniques. This chapter concerns logic in its simplest
form, Boolean algebra, and its application to program and specification test
and design. 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.
Logic has been, for several decades, the primary tool of hardware logic
designers. Today, hardware logic design and more important in the context of
this book, hardware logic test design, are intensely automated. 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.
Note:
As programming and test techniques have improved, the bugs have shifted
closer 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.
The trouble with specifications is that they're hard to express. Logicians have
struggled with this problem since Aristotle's time. Boolean algebra (also known
as the sentential calculus) is the most basic of all logic systems. Higher-order
logic systems are needed and used for formal specifications. If you have a
relatively painless specification system, to understand why your specification
was rejected or how it was transformed, you'll have to understand Boolean
algebra.
Knowledge-Based Systems:
Decision tables:
Decision table is a table consists of four areas called condition stub, the
condition entry, the action stub, and the action entry. 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 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).
Action 2 will be taken if the predicates are all false, (rule 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 the above table are:
Decision-table processors:
Decision tables can be automatically translated into code and, as such, are a
higher order language. The decision table's translator checks the source
decision table for consistency and completeness and fills in any required
default rules. The usual processing order in the resulting object code is, first,
to examine rule 1. If the rule is satisfied, the corresponding action takes place.
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.
Decision tables as a source language have the virtue of clarity, direct
correspondence to specifications, and maintain ability.
program's logical behavior is only part of its behavior. The program interfaces
with other programs, there are restrictions, or the decision-table language may
not have needed features. Any of these reasons could be sufficient to reject a
decision-table implementation.
For example,
Rule 1: “If the persons are male and over 30, then they shall receive a
15% raise. ”
Rule 2: "But if the persons are female, then they shall receive a 10% raise."
The above rules state that age is material for a male's raise, but immaterial for
determining a female's raise.
Rule 2.1 Rule 2.2 Rule 4.1 Rule 4.2 Rule 4.3 Rule 4.4
CONDITION 1 YES YES YES YES YES YES
CONDITION 2 YES NO YES YES NO NO
CONDITION 3 YES YES YES NO NO YES
CONDITION 4 YES YES YES YES YES YES
Rule 2 has been expanded by converting the „I‟ entry for condition 2 into a
separate rule 2.1 for YES and 2.2 for NO. Similarly, condition 2 was expanded
in rule 4 to yield intermediate rules 4.1/4.2 and 4.3/4.4, which were then
expanded via condition 3 to yield the four subrules shown.
If no default rules are given, then all cases not covered by explicit rules are
perforce default rules (or are intended to be). If default rules are given then you
must test the specification for consistency. The specification is complete if and
only if n (binary) conditions expand into 2n unique subrules. It is consistent if
and only if all rules expand into subrules whose condition combinations do not
match those of any other rules. Table (d) is an example of an inconsistent
specification in which the expansion of two rules yields a contradiction.
Rules 1 and 2 are contradictory because the expansion of rule 1 via condition 2
leads to the same set of predicate truth values as the expansion of rule 2 via
condition 3. Therefore action 1 or action 2 is taken depending on which rule is
evaluated first.
If we expand the immaterial cases for the above Table, it results in Table as
below:
Sixteen cases are represented in the above Table, and no case appears twice.
Path Expressions:
Logic-based testing is structural testing when it's applied to structure (e.g.,
control flow graph of an implementation); its functional testing when it's
applied to a specification. In logic-based testing we focus on the truth values of
control flow predicates.
For our purpose, logic based testing is restricted to binary predicates. If you
have case statements, you have to analyze things one case at a time if you're to
use these methods. If you have many case statements, there will be a lot of
bookkeeping and you're probably pushing the applicability of logic based
testing.
The conversion of this flow graph into a decision table after expansion is shown
below:
Several things can go wrong with predicates, especially if the predicate has to
be interpreted in order to express it as a predicate over input values,
Logic-based testing is useful against the first two bug types, whereas data flow
testing is more useful against the latter two.
Boolean algebra:
Let's take a structural viewpoint for the moment and review the steps
taken to get the predicate expression of a path.
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
and the NO or FALSE branch with the same letter over scored.
2. The truth value of a path is the product of the individual labels.
Concatenation or products mean "AND”.
3. If two or more paths merge at a node, the fact is expressed by use of a
plus sign (+) which means "OR”.
Using this convention, the truth-functional values for several of the nodes can
be expressed in terms of segments from previous nodes. Use the node name to
identify the point.
N6 = A + A‟B‟C‟
N8 = (N6) B + A‟B = AB + A‟B‟C‟B + A‟B
N11 = (N8) C + (N6) B‟C
N12 = N11 + A‟B‟C
N2 = N12 + (N8) C‟ + (N6) B‟C‟
There are only two numbers in Boolean algebra: zero (0) and one (1). „1‟
means "always true” and „0‟ means "always false."
Idempotency Law
1. A + A = A [if both stmt. are true, then the resultant stmt. is true]
A‟ + A‟ = A‟ [if both stmt. are false, then the resultant stmt. is false]
Null Law
2. A + 1 =1 [Here „1‟ is universal true. According to „+‟ operation, if
one statement is true, then the resultant statement is
always true]
11. (A‟)‟ =A
Involution law
12. 0‟ = 1
13. 1‟ = 0
Demorgan’s Law
14. (A + B)‟ =A‟B‟
15. (AB)‟ =A‟ + B‟
Distributive law
16. A (B + C) =AB + BC
Associative law for multiplication
17. (AB) C =A (BC)
Associative law for addition
18. (A + B) + C = A + (B + C)
Absorptive law
19. A + A‟B =A + B
20. A + AB =A
The path expressions can now be simplified by applying these rules. The steps
are shown in detail to illustrate the use of the rules. Usually, it‟s done with far
less work. It pays to practice.
N6 = A + A‟B‟C‟
= A+B‟C‟ : use Rule 19, with B=B‟C‟
N8 = (N6) B + A‟B
= (A + B‟C‟) B + A‟B
= AB + B‟C‟B + A‟B
= AB + 0C + A‟B
= B (A + A‟) = B (1) =B
KV Charts:
Below figure shows all the boolean functions of a single variable and their
equivalent representation as a KV chart.
Two–variable maps:
Each box corresponds to the combination of values of the variables for the row
and column of that box.
Any variable that changes in either the horizontal or vertical direction does not
appear in the expression.
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.
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–variable maps:
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.
Four–variable maps:
Five–variable maps:
Below figure is a five-variable chart with some of the adjacencies shown.
Specifications:
There's no point in getting into design and coding until you‟re sure that the
specification is logically consistent and complete. This section shows you how
much of specification analysis can be done using the KV charts, pencil and
paper.
You'll need to use such methods until your automated specification system and
language comes on stream (which needs long time).
2) Identify the predicates on which the cases are based. Name them with
suitable letters such as A, B, C.
Prepared by: Dept. of CSE, RGMCET Page 22
SOFTWARE TESTING METHODOLOGIES AND TOOLS
3) Rewrite the specification in English that uses only the logical connectives
AND, OR, and NOT.
10) If the default cases were not specified explicitly, translate the
default cases back into English and get a confirmation.
The predicates are written using the AND, OR and NOT Boolean connectivities.
Therefore, the problem should be one of finding the keywords: IF, THEN, AND,
OR, and NOT.
Unfortunately we have to deal real world of specifications and
specification writers, where clarity ranges from elusive [difficult to describe],
through esoteric [Mysterious], into incomprehensible.
Samples of phrases that have been or can be used for the words we need are:
IF: based on, based upon, because, but, if, if and when, only if, only when,
provided that, when, when or if, whenever
THEN: applies to, assign, consequently, do, implies that, infers that, initiate,
means that, shall, should, then will, would.
AND: all, and, as well as, both, but, in conjunction with, coincidental with,
consisting of, comprising, either….or, furthermore, in addition to, including,
jointly, moreover, mutually, plus, together with, total, with.
OR: and, and if . . . then, and/or, alternatively, any of, anyone of as well as,
but, case, contrast, depending upon, each, either, either. . . or, except if,
conversely, failing that, furthermore, in addition to, nor, not only . . . but,
although, other than, otherwise, or, or else, on other hand, plus.
NOT: but, but not, by contrast, besides, contrary, conversely, contrast, except
if, excluding, excepting, fail, failing, less, neither, never, no, not, other than.
EXCLUSIVE OR: but, by contrast, conversely, nor, on the other hand, other
than, or.
Here is a specification:
A1 = BC‟D‟ + AB‟C‟D
A3 = BD + BCD‟
Here is the KV chart for this specification (here we‟re using the numerals 1, 2,
3, and 4 to represent the actions and the default case):
There are several boxes that call for more than one action. If the specification
did not explicitly call out both actions in a sentence, such as, "IF ABC’D’ then
both action1 and action 2 shall be taken,".
I would treat that each box that contained more than one action as a Potential
conflict. Similarly, if the specification did say, ". . . both A1 any A2 . . ." but did
not mention A3, as in the ABCD entry, I would also question that entry.
If no explicit default action is specified, then fill out the KV chart with explicit
entries for the explicitly specified actions, negate the entire chart and present
It's also useful to present the new version of the specification, as a table that shows all
cases explicitly and also as a compact version in which you've taken advantage of the
possibility of simplifying the expression by using a KV chart.
You present the table and say that, "This table can also be expressed as. . . .”.
There may be disagreement. The specifier might insist that the table does not
correspond to the specification and that the table does not correspond to your
compact statement, which you know was derived from the table by using
Boolean algebra. Don't be smug [self-satisfied] if that happens. Just as often as
the seeming contradiction will be due to not understanding the equivalence, it
will be due to a predicate that has not been explicitly stated.
Here is an example:
C + A’