60 #include "rnr/rnrconfig.h" 68 #include "gtest/gtest.h" 70 using namespace ::
std;
71 using namespace ::
rnr;
81 static const int StateIdA = State::StateIdNumOf;
82 static const int StateIdB = State::StateIdNumOf + 1;
92 static const char *
ColorSymbol[] = {
"",
"\033[0;33m",
"\033[0;35m"};
94 static const char *
ColorEnd[] = {
"",
"\033[0m",
"\033[0m"};
97 static const uint_t
TRead = 500000;
104 " 'p' pause/resume state machine\n" 105 " 'q' quite (terminate) state machine\n" 106 " 'r' restart state machine\n" 107 " 's' start state machine\n";
135 virtual int execAction(State *pState,
int nPrevStateId,
int nEventId)
162 virtual int execAction(State *pState,
int nPrevStateId,
int nEventId)
165 return State::StateIdStart;
190 virtual int execAction(State *pState,
int nPrevStateId,
int nEventId)
192 if( pState->getTimeOut() == 0 )
194 pState->setTimeOut(
TRead);
198 pState->setTimeOut(0);
200 return State::StateIdThis;
225 virtual int execAction(State *pState,
int nPrevStateId,
int nEventId)
227 return State::StateIdTerminate;
253 const std::string &strStateName=
"",
254 const std::string &strRefTag=
"") :
255 StateKb(nStateId, strStateName, strRefTag)
277 void writeSymbol(
int sym)
298 if( Head < Tape.size()-1 )
312 for(i=0; i<Tape.size(); ++i)
384 n = rand.randrange(0, 10);
388 for(i=0; i<39-n/2; ++i)
398 for(i=Tape.size(); i<80; ++i)
452 virtual int execAction(State *pState,
int nPrevStateId,
int nEventId)
498 virtual int execAction(State *pState,
int nPrevStateId,
int nEventId)
544 virtual int execAction(State *pState,
int nPrevStateId,
int nEventId)
585 nEventId = StateKb::receiveEvent();
643 virtual int execAction(State *pState,
int nPrevStateId,
int nEventId)
689 virtual int execAction(State *pState,
int nPrevStateId,
int nEventId)
735 virtual int execAction(State *pState,
int nPrevStateId,
int nEventId)
777 nEventId = StateKb::receiveEvent();
816 StateMach sm(0,
"(2,3)Turing", State::StateIdStart, listOfStates);
824 LOG_SET_THRESHOLD(LOG_LEVEL_OFF);
840 EXPECT_TRUE(
testSM() == 0 );
void moveHeadRight()
Move head right one position on the tape.
StateEventASym2()
Constuctor.
static int testSM()
Test State Machine.
StateEventASym0()
Constuctor.
static const char * ColorSymbol[]
color of symbols
virtual ~StateStart()
Destructor.
(2,3) Turing Machine's state B, symbol 0 event.
virtual int execAction(State *pState, int nPrevStateId, int nEventId)
Execute event action.
StateEventPauseResume()
Constuctor.
void moveHeadLeft()
Move head left one position on the tape.
StateEventBSym0()
Constuctor.
static const char * ColorHead
color tape head
(2,3) Turing Machine's state A, symbol 2 event.
virtual bool evalGuardExpr(State *pState, int nPrevStateId, int nEventId)
Evaluate event guard condition.
virtual ~StateEventTerminate()
Destructor.
StateEventBSym1()
Constuctor.
virtual int execAction(State *pState, int nPrevStateId, int nEventId)
Execute event action.
virtual bool evalGuardExpr(State *pState, int nPrevStateId, int nEventId)
Evaluate event guard condition.
virtual ~State2_3Turing()
Destructor.
static const int StateIdA
state A
static const uint_t TRead
read tape time interval
StateEventASym1()
Constuctor.
Finite State Machine interface.
State2_3Turing(int nStateId, const std::string &strStateName="", const std::string &strRefTag="")
Initializatoin constuctor.
virtual ~StateEventBSym2()
Destructor.
virtual int execAction(State *pState, int nPrevStateId, int nEventId)
Execute event action.
virtual int execAction(State *pState, int nPrevStateId, int nEventId)
Execute event action.
(2,3) Turing Machine's state B.
static const char * ColorEnd[]
end color
(2,3) Turing Machine's state B, symbol 1 event.
virtual int execAction(State *pState, int nPrevStateId, int nEventId)
Execute event action.
virtual bool evalGuardExpr(State *pState, int nPrevStateId, int nEventId)
Evaluate event guard condition.
StateEventBSym2()
Constuctor.
static const int StateIdB
state B
virtual int receiveEvent()
Receive the next event.
virtual ~StateEventASym1()
Destructor.
static const int EventIdTerminate
terminate event id
static vector< int > Tape
the tape of symbols
virtual ~StateA()
Destructor.
virtual bool evalGuardExpr(State *pState, int nPrevStateId, int nEventId)
Evaluate event guard condition.
Keyboard StateKb derived state class interface.
virtual ~StateEventBSym0()
Destructor.
static const char * TestMenu
Test menu.
virtual ~StateEventASym2()
Destructor.
static const int EventIdPauseResume
pause/resume event id
(2,3) Turing Machine's state A.
(2,3) Turing Machine's state B, symbol 2 event.
virtual int execAction(State *pState, int nPrevStateId, int nEventId)
Execute event action.
virtual int execAction(State *pState, int nPrevStateId, int nEventId)
Execute event action.
virtual int execAction(State *pState, int nPrevStateId, int nEventId)
Execute event action.
virtual int execAction(State *pState, int nPrevStateId, int nEventId)
Execute event action.
Random variable generator class interface.
virtual bool evalGuardExpr(State *pState, int nPrevStateId, int nEventId)
Evaluate event guard condition.
Terminate state event class.
StateEventStart()
Constuctor.
virtual void actionEnterState(int nPrefStateId, int nEventId)
Execute 'enter state' action.
virtual int receiveEvent()
Receive the next event.
virtual ~StateEventASym0()
Destructor.
(2,3) Turing Machine's state A, symbol 0 event.
State base class interface.
The (2,3) Turing state base class.
static const int EventIdSymbol[]
tape symbol event ids
virtual ~StateEventStart()
Destructor.
virtual int execAction(State *pState, int nPrevStateId, int nEventId)
Execute event action.
virtual ~StateEventRestart()
Destructor.
static int Head
the tape read/write head
virtual ~StateEventPauseResume()
Destructor.
static const int EventIdStart
start event id
static const int EventIdRestart
restart event id
StateEventRestart()
Constuctor.
virtual ~StateB()
Destructor.
void showTape()
Show colorized tape to stdout.
TEST(SM, SM2_3Turing)
Test State Machine class.
virtual ~StateEventBSym1()
Destructor.
StateEventTerminate()
Constuctor.
virtual bool evalGuardExpr(State *pState, int nPrevStateId, int nEventId)
Evaluate event guard condition.
(2,3) Turing Machine's state A, symbol 1 event.
Pause/resume state event class.
Restart state event class.