0% found this document useful (0 votes)
8 views12 pages

UNIT 4 Logic Based Testing Notes

The document provides an overview of logic-based testing, emphasizing the use of decision tables, boolean algebra, and Karnaugh-Veitch charts for program and test design. It discusses the importance of knowledge-based systems and how decision tables can be utilized for both business data processing and test case design. Additionally, it covers the generation of path expressions and the simplification of boolean algebra to aid in software testing.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views12 pages

UNIT 4 Logic Based Testing Notes

The document provides an overview of logic-based testing, emphasizing the use of decision tables, boolean algebra, and Karnaugh-Veitch charts for program and test design. It discusses the importance of knowledge-based systems and how decision tables can be utilized for both business data processing and test case design. Additionally, it covers the generation of path expressions and the simplification of boolean algebra to aid in software testing.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

UNIT - IV

Logic Based Testing: Overview, Decision Tables, Path Expressions, KV Charts,


Specifications.

LOGIC BASED TESTING-OVERVIEW:

• 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 The trouble with specifications is that they're hard to express.
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.
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.
o KNOWLEDGE BASED SYSTEM:
▪ The knowledge-based system (also expert system or “artificial
intelligence” system has become the programming construct of choice
for many applications that were once considered very difficult.
▪ Knowledge-based systems incorporate knowledge from a knowledge
domain such as medicine, law, or civil engineering into a database.
The data can then be queried and interacted with to provide solutions
to problems in that domain.
▪ One implementation of knowledge-based systems is to incorporate
the expert's knowledge into a set of rules. The user can then provide
data and ask questions based on that data.
▪ 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.
▪ Understanding knowledge-based systems and their validation
problems requires an understanding of formal logic.
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:
• The below Figure 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.
• Each column of the table is a rule that specifies the conditions under which the
actions named in the action stub will take place.
• The condition stub is a list of names of conditions.

Figure: Examples of Decision Table.

A more general decision table can be as below:

Figure: Another Example of Decision Table.


• 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.
• The table in Figure 6.1 can be translated as follows:
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).
• "Condition" is another word for predicate.
• Decision-table uses "condition" and "satisfied" or "met". Let us use "predicate" and
TRUE / FALSE.
• Now the above translations become:
1. Action 1 will be taken if predicates 1 and 2 aretrue 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.

Figure: The default rules of Table in Figure 6.1


• Decision-table processors:
o Decision tables can be automatically translated into code and, as such, area
higher-order language
o If the rule is satisfied, the corresponding action takes place
o Otherwise, rule2 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
o Decision tables have become a useful tool in the programmer’s kit, in
business data processing.
• Decision-tables as basis for test case design:
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
• Decision-tables and structure:
o Decision tables can also be used to examine a program's structure.
o Figure 6.4 shows a program segment that consists of a decision tree.
o These decisions, in various combinations, can lead to actions 1, 2, or 3.

Figure: A Sample Program


o If the decision appears on a path, put in a YES or NO as appropriate. If the
decision does not appear on the path, put in an I, Rule 1does not contain
decision C, therefore its entries are: YES, YES, I, YES.
o The corresponding decision table is shown in Table 6.1

Table: Decision Table corresponding to Figure 6.4


o As an example, expanding the immaterial cases results as below:

o Similarly, If we expand the immaterial cases for the above Table, it results
in
Table as below:

Table: Expansion of Table

o Sixteen cases are represented in Table 6.1, and no case appears twice.
o Consequently, the flow graph appears to be complete and consistent.
o 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.
• Another example - a trouble some program:
o Consider the following specification whose putative flow graph:
a. If condition A is met, do process A1 no matter what other actions are taken or
what other conditions are met.
b. If condition B is met, do process A2 no matter what other actions are taken or
what other conditions are met.
c. If condition C is met, do process A3 no matter what other actions are taken or
what other conditions are met.
d. If none of the conditions is met, then do processes A1, A2, and A3.
e. 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).
o Figure shows a sample program with a bug.

Figure: A Troublesome Program


o The programmer tried to force all three processes to be executed for the cases but
for go that the B and C predicates would be done again, thereby bypassing processes A2
and A3.
o Table 6.3 shows the conversion of this flow graph into a decision table after expansion.

Table: Decision Table


PATH EXPRESSIONS:
• 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 In logic-based testing we focus on the truth values of control flow predicates.
o A predicate is implemented as a process whose outcome is a truth-functional value.
o For our purpose, logic-based testing is restricted to binary predicates.
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 anode, the fact is expressed by use of a plus sign (+)
which means "OR".

Figure: A Troublesome Program


o 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.

o There are only two numbers in boolean algebra: zero (0) and one (1). One
means "always true" and zero means "alwaysfalse".
o Rules of booleanalgebra:
▪ Booleanalgebrahasthreeoperators: X(AND),+(OR) and (NOT)
▪ X : meaning AND. Also called multiplication. A statement such as AB
(A X B) means "A and B are both true". This symbol is usually left out
as in ordinary algebra.
+ : meaning OR. "A + B" means "either A is true or B is true or both".
meaning NOT. Also negation or complementation. This is read as either "not
A" or "A bar". The entire expression under the bar is negated.
▪ The following are the laws of boolean algebra:

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 The following are the laws of boolean algebra:

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:
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 Karnaugh-Veitch chart reduces boolean algebraic manipulations to
graphical trivia.
o Beyond six variables these diagrams get cumbersome and may not be
effective.
• Single Variable:
o Figure shows all the boolean functions of a single variable and their
equivalent representation as a KV chart.

Figure: KV Charts for Functions of a Single Variable.


o The charts show all possible truth values that the variable A can have.
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.
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 shows eight of the sixteen possible functions of two variables.

Figure: KV Charts for Functions of Two Variables.


o Each box corresponds to the combination of values of the variables for the
row and column of that box.
o A pair may be adjacent either horizontally or vertically but not diagonally.
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 1going down the column,
and because the A variable's value for the column is 1, the chart is
equivalent to a simple A.
o Figure shows the remaining eight functions of two variables.

Figure: More Functions of Two Variables.

o The first chart has two 1's in it, but because they are not adjacent, each
must be taken separately.
o They are written using a plus sign.
o It is clear now why there are sixteen functions of two variables.
o Each box in the KV chart corresponds to a combination of the variables'
values.
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 2 n combinations of 0 and 1 for the variables, and
each such combination (box) can be filled or not filled, leading to 2 2n ways
of doing this.
o Consequently, for one variable there are 2 21 = 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 KV charts for three variables are shown below.
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.
o A three-variable chart can have groupings of 1, 2, 4, and 8 boxes.
o A few examples will illustrate the principles:
Figure: KV Charts for Functions of Three Variables.

SPECIFICATIONS:
The procedure for specification validation is straight forward.
1. Rewrite the specification using consistent terminology.
2. Identify the predicates on which the cases are based. Name them with suitable letters
such as A, B, C.
3. Rewrite the specification in English that uses only the logical connectives AND, OR and
NOT, however stilted it might seem.
4. Convert the rewritten specification into an equivalent set of Boolean expressions.
5. Identify the default action and cases, if they are specified.
6. Enter the Boolean expressions in a KV Chart and check for consistency. If the specification
are consistent, there will be no overlaps, except for cases that result in multiple actions.
7. Enter the default cases and check for consistency.
8. If all boxes are covered, the specification is complete.
9. If the specification is incomplete or inconsistent, translate the corresponding boxes of the
KV Chart back into English and get a clarification, explanation or revision.
10. If the default cases were not specified explicitly, translate the default cases back into
English and get a confirmation

You might also like