10/26/2012
State Graphs
A state is defined as : A combination of
circumstances or attributes belonging for the time
being to a person or thing.
For example, a moving automobile whose engine is
running can have the following states with respect to
its transmission.
UNIT 7
STATES,STATE GRAPHS AND
TRANSITION TESTING
D.ABHISHEKH MS(SE)
Reverse gear
Neutral gear
First gear
Second gear
Third gear
Fourth gear
State graph - Example
For example, a program that detects the
character sequence ZCZC can be in the
following states.
Neither ZCZC nor any part of it has been
detected.
Z has been detected.
ZC has been detected.
ZCZ has been detected.
ZCZC has been detected.
A
A,C
A,C
Z,C,A
A
None
Z
Z
ZC
ZCZ
Z
ZCZC
C
Z
Z
10/26/2012
ERROR
STATE
OKAY
1/NONE
2/REWRITE
1/NONE
4/REWRITE
1/NONE
2/REWRITE
3/NONE
5/ERASE
1/NONE
6/ERASE
1/NONE
7/OUT
Example to convert specification into a state graph
---------------------------------------------------------------
TRANSITION BUGS
With an example, we will now follow a set of rules, i.e. specifications to
deduce the state graph and state tables
RULE 1:
The program will maintain an error counter which will be incremented
whenever there is an error.
10/26/2012
State table from the state graph(refer earlier slide for the
graph)
Initial state graph deduced from Rule1
INPUT
error
error
error
error
STATE
OKAY
ERROR
0/None
1/
...
Okay
RULE 1: The program will maintain an error counter,
which will be incremented whenever there is an
error.
Rule 2: If there is an error, rewrite the block
OKAY
ERROR
0/None
1/REWRITE
2/REWRITE
For all Error
2 entries, we include a Rewrite 3/REWRITE
4/REWRITE
5/REWRITE
6/REWRITE
7/REWRITE
8/REWRITE
2/
3/
4/
5/
6/
7/
8/
Rule 3: If there have been 3 successive errors, erase of tape and then rewrite the block
INPUT
STATE
STATE
OKAY
0/None
ERROR
INPUT
1/REWRITE
2/REWRITE
2
3
3/REWRITE,ERASE,REWRITE
The first 3rd successive error
occurs
4/REWRITE,ERASE,REWRITE
5/REWRITE,ERASE,REWRITE
6/REWRITE,ERASE,REWRITE
7/REWRITE,ERASE,REWRITE
8/REWRITE,ERASE,REWRITE
10/26/2012
Rule 4: If there have been 3 successive erasures,
and another error occurs, put the unit out of service
STATE
OKAY
ERROR
0/None
1/REWRITE
2/REWRITE
3/REWRITE,ERASE,REWRI
TE
4/REWRITE,ERASE,REWRI
TE
We have 3 successive erasures- so
Rule 5: If the erasure was successful, return to the
normal state and clear the error counter
STATE
OKAY
ERROR
0/None
1/REWRITE
1 3 after the 1st
We reach State
erasure. If successful, we return to
2
None & the error counter is made
0
3
service
4we now put the unit out of5/REWRITE,ERASE,REWRI
TE
6/OUT
0/None 4/REWRITE,ERASE,REWRI
TE
0/None
5/REWRITE,ERASE,REWRI
TE
0/None
6/OUT
Rule 6: If the rewrite was successful, decrement the
error counter and return to the previous state
2/REWRITE
3/REWRITE,ERASE,REWRI
TE
Conclusion
INPUT
STATE
OKAY
ERROR
0/None
1/REWRITE
0/None
2/REWRITE
1/None
3/REWRITE,ERASE,REWRI
TE
0/None
2/None
4/REWRITE,ERASE,REWRI
TE
0/None
5/REWRITE,ERASE,REWRI
3/None Example: Say we are
TEat state 1. The error
If we have a
0/None counter here is 2.6/OUT
successful(okay) rewrite, the entry for okay
4/None at state 2 will have error counter
decremented by 1 which is:
(2-1)/None where, None output for
success.
6
7
Observe the previous slideRULE6 states If the rewrite was successful, then
decrement the error counter and return to the
previous state.
The requirement probably was If there have been
no erasures and rewrite was successful, then
This has now resulted in contradictions which is a
concern as it might lead to bugs.
It is always unlikely that a contradictory specification
can result in a satisfactory implementation.