appkit  1.5.1
RoadNarrows Robotics Application Kit
ut-sm.cxx
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Package: RoadNarrows Robotics Application Tool Kit
4 //
5 // Unit Test: Test State Machine Class.
6 //
7 /*! \file
8  *
9  * $LastChangedDate: 2013-05-03 08:51:57 -0600 (Fri, 03 May 2013) $
10  * $Rev: 2905 $
11  *
12  * \ingroup appkit_ut
13  *
14  * \brief Unit test for librnr_appkit StateMach, State, StateEvent, and
15  * StateKb classes.
16  *
17  * \author Robin Knight (robin.knight@roadnarrows.com)
18  *
19  * \par Copyright
20  * \h_copy 2013-2017. RoadNarrows LLC.\n
21  * http://www.roadnarrows.com\n
22  * All Rights Reserved
23  */
24 /*
25  * @EulaBegin@
26 //
27 // Redistribution and use in source and binary forms, with or without
28 // modification, are permitted provided that the following conditions are met:
29 //
30 // 1. Redistributions of source code must retain the above copyright notice,
31 // this list of conditions and the following disclaimer.
32 //
33 // 2. Redistributions in binary form must reproduce the above copyright notice,
34 // this list of conditions and the following disclaimer in the documentation
35 // and/or other materials provided with the distribution.
36 //
37 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
38 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
39 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
40 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
41 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
42 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
43 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
44 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
46 // POSSIBILITY OF SUCH DAMAGE.
47 //
48 // The views and conclusions contained in the software and documentation are
49 // those of the authors and should not be interpreted as representing official
50 // policies, either expressed or implied, of the FreeBSD Project.
51  * @EulaEnd@
52  */
53 ////////////////////////////////////////////////////////////////////////////////
54 
55 #include <stdio.h>
56 
57 #include <string>
58 #include <vector>
59 
60 #include "rnr/rnrconfig.h"
61 #include "rnr/log.h"
62 
63 #include "rnr/appkit/Random.h"
64 #include "rnr/appkit/State.h"
65 #include "rnr/appkit/StateKb.h"
66 #include "rnr/appkit/StateMach.h"
67 
68 #include "gtest/gtest.h"
69 
70 using namespace ::std;
71 using namespace ::rnr;
72 
73 /*!
74  * \ingroup appkit_ut
75  * \defgroup appkit_ut_sm State Machine Tests
76  * \brief Fine-grained testing of the StateMach, State, StateKb, and
77  * StateEvent classes.
78  * \{
79  */
80 
81 static const int StateIdA = State::StateIdNumOf; ///< state A
82 static const int StateIdB = State::StateIdNumOf + 1; ///< state B
83 
84 static const int EventIdPauseResume = 'p'; ///< pause/resume event id
85 static const int EventIdTerminate = 'q'; ///< terminate event id
86 static const int EventIdRestart = 'r'; ///< restart event id
87 static const int EventIdStart = 's'; ///< start event id
88 static const int EventIdSymbol[] = {' ', '@', '#'};
89  ///< tape symbol event ids
90 
91 static const char *ColorHead = "\033[0;31m"; ///< color tape head
92 static const char *ColorSymbol[] = {"", "\033[0;33m", "\033[0;35m"};
93  ///< color of symbols
94 static const char *ColorEnd[] = {"", "\033[0m", "\033[0m"};
95  ///< end color
96 
97 static const uint_t TRead = 500000; ///< read tape time interval
98 
99 /*!
100  * \brief Test menu.
101  */
102 static const char *TestMenu =
103  "\nTest Menu\n"
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";
108 
109 
110 // .............................................................................
111 // Common State Events
112 // .............................................................................
113 
114 /*!
115  * \brief Start state event class.
116  */
117 class StateEventStart : public StateEvent
118 {
119 public:
120  /*! \brief Constuctor. */
121  StateEventStart() : StateEvent(EventIdStart, "start") { }
122 
123  /*! \brief Destructor. */
124  virtual ~StateEventStart() { }
125 
126  /*!
127  * \brief Execute event action.
128  *
129  * \param pState State owning this event.
130  * \param nPrevStateId Previous state id.
131  * \param nEventId Event id.
132  *
133  * \return Next state id.
134  */
135  virtual int execAction(State *pState, int nPrevStateId, int nEventId)
136  {
137  return StateIdA;
138  }
139 };
140 
141 /*!
142  * \brief Restart state event class.
143  */
144 class StateEventRestart : public StateEvent
145 {
146 public:
147  /*! \brief Constuctor. */
148  StateEventRestart() : StateEvent(EventIdRestart, "restart") { }
149 
150  /*! \brief Destructor. */
151  virtual ~StateEventRestart() { }
152 
153  /*!
154  * \brief Execute event action.
155  *
156  * \param pState State owning this event.
157  * \param nPrevStateId Previous state id.
158  * \param nEventId Event id.
159  *
160  * \return Next state id.
161  */
162  virtual int execAction(State *pState, int nPrevStateId, int nEventId)
163  {
164  printf("%s", TestMenu);
165  return State::StateIdStart;
166  }
167 };
168 
169 /*!
170  * \brief Pause/resume state event class.
171  */
172 class StateEventPauseResume : public StateEvent
173 {
174 public:
175  /*! \brief Constuctor. */
176  StateEventPauseResume() : StateEvent(EventIdPauseResume, "pause/resume") { }
177 
178  /*! \brief Destructor. */
180 
181  /*!
182  * \brief Execute event action.
183  *
184  * \param pState State owning this event.
185  * \param nPrevStateId Previous state id.
186  * \param nEventId Event id.
187  *
188  * \return Next state id.
189  */
190  virtual int execAction(State *pState, int nPrevStateId, int nEventId)
191  {
192  if( pState->getTimeOut() == 0 )
193  {
194  pState->setTimeOut(TRead);
195  }
196  else
197  {
198  pState->setTimeOut(0);
199  }
200  return State::StateIdThis;
201  }
202 };
203 
204 /*!
205  * \brief Terminate state event class.
206  */
207 class StateEventTerminate : public StateEvent
208 {
209 public:
210  /*! \brief Constuctor. */
211  StateEventTerminate() : StateEvent(EventIdTerminate, "terminate") { }
212 
213  /*! \brief Destructor. */
214  virtual ~StateEventTerminate() { }
215 
216  /*!
217  * \brief Execute event action.
218  *
219  * \param pState State owning this event.
220  * \param nPrevStateId Previous state id.
221  * \param nEventId Event id.
222  *
223  * \return Next state id.
224  */
225  virtual int execAction(State *pState, int nPrevStateId, int nEventId)
226  {
227  return State::StateIdTerminate;
228  }
229 };
230 
231 
232 // .............................................................................
233 // (2,3) Turing State
234 // .............................................................................
235 
236 /*!
237  * \brief The (2,3) Turing state base class.
238  */
239 class State2_3Turing : public StateKb
240 {
241 public:
242  static vector<int> Tape; ///< the tape of symbols
243  static int Head; ///< the tape read/write head
244 
245  /*!
246  * \brief Initializatoin constuctor.
247  *
248  * \param nStateId State id. Must be state machine unique.
249  * \param strStateName State name.
250  * \param strRefTag State reference id.
251  */
252  State2_3Turing(int nStateId,
253  const std::string &strStateName="",
254  const std::string &strRefTag="") :
255  StateKb(nStateId, strStateName, strRefTag)
256  {
257  }
258 
259  /*! \brief Destructor. */
260  virtual ~State2_3Turing() { }
261 
262  /*
263  * \brief Read symbol from tape at the current head position.
264  *
265  * \return Symbol.
266  */
267  int readSymbol()
268  {
269  return Tape[Head];
270  }
271 
272  /*
273  * \brief Write symbol to tape at the current head position.
274  *
275  * \param sym Symbol.
276  */
277  void writeSymbol(int sym)
278  {
279  Tape[Head] = sym;
280  }
281 
282  /*!
283  * \brief Move head left one position on the tape.
284  */
286  {
287  if( Head > 0 )
288  {
289  --Head;
290  }
291  }
292 
293  /*!
294  * \brief Move head right one position on the tape.
295  */
297  {
298  if( Head < Tape.size()-1 )
299  {
300  ++Head;
301  }
302  }
303 
304  /*!
305  * \brief Show colorized tape to stdout.
306  */
307  void showTape()
308  {
309  int sym;
310  size_t i, j;
311 
312  for(i=0; i<Tape.size(); ++i)
313  {
314  sym = Tape[i];
315 
316  if( i == Head )
317  {
318  printf("%s%c%s", ColorHead, sym, ColorEnd[1]);
319  }
320 
321  else
322  {
323  for(j=0; j<3; ++j)
324  {
325  if( sym == EventIdSymbol[j] )
326  {
327  printf("%s%c%s", ColorSymbol[j], sym, ColorEnd[j]);
328  break;
329  }
330  }
331  }
332  }
333 
334  printf("\n");
335  fflush(stdin);
336  }
337 
338 };
339 
340 vector<int> State2_3Turing::Tape; ///< tape of symbols
341 int State2_3Turing::Head; ///< the tape read/write head
342 
343 
344 // .............................................................................
345 // Start State
346 // .............................................................................
347 
348 /*!
349  * \brief Start state event class.
350  *
351  * The start state is not part of the "official" (2,3) Turing Machine. Rather
352  * it is used to (re)initize the tape and then transition to the A state.
353  */
355 {
356 public:
357  /*! \brief Constuctor. */
358  StateStart() : State2_3Turing(StateIdStart, "Start", "S")
359  {
360  addStateEvents(new StateEventStart(),
361  new StateEventRestart(),
362  new StateEventTerminate(),
363  NULL);
364  }
365 
366  /*! \brief Destructor. */
367  virtual ~StateStart() { }
368 
369  /*!
370  * \brief Execute 'enter state' action.
371  *
372  * \param nPrevStateId Previous state id.
373  * \param nEventId Received event id.
374  */
375  virtual void actionEnterState(int nPrefStateId, int nEventId)
376  {
377  Random rand;
378  int n;
379  int sym;
380  size_t i;
381 
382  Tape.clear();
383 
384  n = rand.randrange(0, 10);
385 
386  printf("\n");
387 
388  for(i=0; i<39-n/2; ++i)
389  {
390  Tape.push_back(EventIdSymbol[0]);
391  }
392 
393  for(i=0; i<n; ++i)
394  {
395  Tape.push_back(EventIdSymbol[rand.randrange(0, 2)]);
396  }
397 
398  for(i=Tape.size(); i<80; ++i)
399  {
400  Tape.push_back(EventIdSymbol[0]);
401  }
402 
403  Head = 41;
404 
405  showTape();
406  }
407 
408 };
409 
410 
411 // .............................................................................
412 // (2,3) Turing State A
413 // .............................................................................
414 
415 /*!
416  * \brief (2,3) Turing Machine's state A, symbol 0 event.
417  */
418 class StateEventASym0 : public StateEvent
419 {
420 public:
421  /*! \brief Constuctor. */
422  StateEventASym0() : StateEvent(EventIdSymbol[0], "sym0", "action_P1_R_B") { }
423 
424  /*! \brief Destructor. */
425  virtual ~StateEventASym0() { }
426 
427  /*!
428  * \brief Evaluate event guard condition.
429  *
430  * \param pState Associated state.
431  * \param nPrevStateId Previous state id.
432  * \param nEventId Received event id.
433  *
434  * \return Returns true if event is accepted, otherwise returns false.
435  */
436  virtual bool evalGuardExpr(State *pState, int nPrevStateId, int nEventId)
437  {
438  return ((State2_3Turing*)pState)->Head < 79? true: false;
439  }
440 
441  /*!
442  * \brief Execute event action.
443  *
444  * Print symbol 1, move right, enter state B.
445  *
446  * \param pState State owning this event.
447  * \param nPrevStateId Previous state id.
448  * \param nEventId Event id.
449  *
450  * \return Next state id.
451  */
452  virtual int execAction(State *pState, int nPrevStateId, int nEventId)
453  {
454  ((State2_3Turing*)pState)->writeSymbol(EventIdSymbol[1]);
455  ((State2_3Turing*)pState)->moveHeadRight();
456  ((State2_3Turing*)pState)->showTape();
457  return StateIdB;
458  }
459 };
460 
461 /*!
462  * \brief (2,3) Turing Machine's state A, symbol 1 event.
463  */
464 class StateEventASym1 : public StateEvent
465 {
466 public:
467  /*! \brief Constuctor. */
468  StateEventASym1() : StateEvent(EventIdSymbol[1], "sym1", "action_P2_L_A") { }
469 
470  /*! \brief Destructor. */
471  virtual ~StateEventASym1() { }
472 
473  /*!
474  * \brief Evaluate event guard condition.
475  *
476  * \param pState Associated state.
477  * \param nPrevStateId Previous state id.
478  * \param nEventId Received event id.
479  *
480  * \return Returns true if event is accepted, otherwise returns false.
481  */
482  virtual bool evalGuardExpr(State *pState, int nPrevStateId, int nEventId)
483  {
484  return ((State2_3Turing*)pState)->Head > 0? true: false;
485  }
486 
487  /*!
488  * \brief Execute event action.
489  *
490  * Print symbol 2, move left, stay in state A.
491  *
492  * \param pState State owning this event.
493  * \param nPrevStateId Previous state id.
494  * \param nEventId Event id.
495  *
496  * \return Next state id.
497  */
498  virtual int execAction(State *pState, int nPrevStateId, int nEventId)
499  {
500  ((State2_3Turing*)pState)->writeSymbol(EventIdSymbol[2]);
501  ((State2_3Turing*)pState)->moveHeadLeft();
502  ((State2_3Turing*)pState)->showTape();
503  return StateIdA;
504  }
505 };
506 
507 /*!
508  * \brief (2,3) Turing Machine's state A, symbol 2 event.
509  */
510 class StateEventASym2 : public StateEvent
511 {
512 public:
513  /*! \brief Constuctor. */
514  StateEventASym2() : StateEvent(EventIdSymbol[2], "sym2", "action_P1_L_A") { }
515 
516  /*! \brief Destructor. */
517  virtual ~StateEventASym2() { }
518 
519  /*!
520  * \brief Evaluate event guard condition.
521  *
522  * \param pState Associated state.
523  * \param nPrevStateId Previous state id.
524  * \param nEventId Received event id.
525  *
526  * \return Returns true if event is accepted, otherwise returns false.
527  */
528  virtual bool evalGuardExpr(State *pState, int nPrevStateId, int nEventId)
529  {
530  return ((State2_3Turing*)pState)->Head > 0? true: false;
531  }
532 
533  /*!
534  * \brief Execute event action.
535  *
536  * Print symbol 1, move left, stay in state A.
537  *
538  * \param pState State owning this event.
539  * \param nPrevStateId Previous state id.
540  * \param nEventId Event id.
541  *
542  * \return Next state id.
543  */
544  virtual int execAction(State *pState, int nPrevStateId, int nEventId)
545  {
546  ((State2_3Turing*)pState)->writeSymbol(EventIdSymbol[1]);
547  ((State2_3Turing*)pState)->moveHeadLeft();
548  ((State2_3Turing*)pState)->showTape();
549  return StateIdA;
550  }
551 };
552 
553 /*!
554  * \brief (2,3) Turing Machine's state A.
555  */
556 class StateA : public State2_3Turing
557 {
558 public:
559  /*! \brief Constuctor. */
561  {
562  addStateEvents(new StateEventPauseResume(),
563  new StateEventRestart(),
564  new StateEventTerminate(),
565  new StateEventASym0(),
566  new StateEventASym1(),
567  new StateEventASym2(),
568  NULL);
569 
570  setTimeOut(TRead);
571  }
572 
573  /*! \brief Destructor. */
574  virtual ~StateA() { }
575 
576  /*!
577  * \brief Receive the next event.
578  *
579  * \return Event id.
580  */
581  virtual int receiveEvent()
582  {
583  int nEventId;
584 
585  nEventId = StateKb::receiveEvent();
586 
587  switch( nEventId )
588  {
589  case EventIdPauseResume:
590  case EventIdRestart:
591  case EventIdTerminate:
592  return nEventId;
593  case KbEventTimeOut:
594  return readSymbol();
595  default:
596  return '?'; // force default action == this state
597  }
598  }
599 };
600 
601 
602 // .............................................................................
603 // (2,3) Turing State B
604 // .............................................................................
605 
606 /*!
607  * \brief (2,3) Turing Machine's state B, symbol 0 event.
608  */
609 class StateEventBSym0 : public StateEvent
610 {
611 public:
612  /*! \brief Constuctor. */
613  StateEventBSym0() : StateEvent(EventIdSymbol[0], "sym0", "action_P2_L_A") { }
614 
615  /*! \brief Destructor. */
616  virtual ~StateEventBSym0() { }
617 
618  /*!
619  * \brief Evaluate event guard condition.
620  *
621  * \param pState Associated state.
622  * \param nPrevStateId Previous state id.
623  * \param nEventId Received event id.
624  *
625  * \return Returns true if event is accepted, otherwise returns false.
626  */
627  virtual bool evalGuardExpr(State *pState, int nPrevStateId, int nEventId)
628  {
629  return ((State2_3Turing*)pState)->Head > 0? true: false;
630  }
631 
632  /*!
633  * \brief Execute event action.
634  *
635  * Print symbol 2, move left, enter state A.
636  *
637  * \param pState State owning this event.
638  * \param nPrevStateId Previous state id.
639  * \param nEventId Event id.
640  *
641  * \return Next state id.
642  */
643  virtual int execAction(State *pState, int nPrevStateId, int nEventId)
644  {
645  ((State2_3Turing*)pState)->writeSymbol(EventIdSymbol[2]);
646  ((State2_3Turing*)pState)->moveHeadLeft();
647  ((State2_3Turing*)pState)->showTape();
648  return StateIdA;
649  }
650 };
651 
652 /*!
653  * \brief (2,3) Turing Machine's state B, symbol 1 event.
654  */
655 class StateEventBSym1 : public StateEvent
656 {
657 public:
658  /*! \brief Constuctor. */
659  StateEventBSym1() : StateEvent(EventIdSymbol[1], "sym1", "action_P2_R_B") { }
660 
661  /*! \brief Destructor. */
662  virtual ~StateEventBSym1() { }
663 
664  /*!
665  * \brief Evaluate event guard condition.
666  *
667  * \param pState Associated state.
668  * \param nPrevStateId Previous state id.
669  * \param nEventId Received event id.
670  *
671  * \return Returns true if event is accepted, otherwise returns false.
672  */
673  virtual bool evalGuardExpr(State *pState, int nPrevStateId, int nEventId)
674  {
675  return ((State2_3Turing*)pState)->Head < 79? true: false;
676  }
677 
678  /*!
679  * \brief Execute event action.
680  *
681  * Print symbol 2, move right, stay in state B.
682  *
683  * \param pState State owning this event.
684  * \param nPrevStateId Previous state id.
685  * \param nEventId Event id.
686  *
687  * \return Next state id.
688  */
689  virtual int execAction(State *pState, int nPrevStateId, int nEventId)
690  {
691  ((State2_3Turing*)pState)->writeSymbol(EventIdSymbol[2]);
692  ((State2_3Turing*)pState)->moveHeadRight();
693  ((State2_3Turing*)pState)->showTape();
694  return StateIdB;
695  }
696 };
697 
698 /*!
699  * \brief (2,3) Turing Machine's state B, symbol 2 event.
700  */
701 class StateEventBSym2 : public StateEvent
702 {
703 public:
704  /*! \brief Constuctor. */
705  StateEventBSym2() : StateEvent(EventIdSymbol[2], "sym2", "action_P0_R_A") { }
706 
707  /*! \brief Destructor. */
708  virtual ~StateEventBSym2() { }
709 
710  /*!
711  * \brief Evaluate event guard condition.
712  *
713  * \param pState Associated state.
714  * \param nPrevStateId Previous state id.
715  * \param nEventId Received event id.
716  *
717  * \return Returns true if event is accepted, otherwise returns false.
718  */
719  virtual bool evalGuardExpr(State *pState, int nPrevStateId, int nEventId)
720  {
721  return ((State2_3Turing*)pState)->Head < 79? true: false;
722  }
723 
724  /*!
725  * \brief Execute event action.
726  *
727  * Print symbol 0, move right, enter state A.
728  *
729  * \param pState State owning this event.
730  * \param nPrevStateId Previous state id.
731  * \param nEventId Event id.
732  *
733  * \return Next state id.
734  */
735  virtual int execAction(State *pState, int nPrevStateId, int nEventId)
736  {
737  ((State2_3Turing*)pState)->writeSymbol(EventIdSymbol[0]);
738  ((State2_3Turing*)pState)->moveHeadRight();
739  ((State2_3Turing*)pState)->showTape();
740  return StateIdA;
741  }
742 };
743 
744 /*!
745  * \brief (2,3) Turing Machine's state B.
746  */
747 class StateB : public State2_3Turing
748 {
749 public:
750 
751  /*! \brief Constuctor. */
753  {
754  addStateEvents(new StateEventPauseResume(),
755  new StateEventRestart(),
756  new StateEventTerminate(),
757  new StateEventBSym0(),
758  new StateEventBSym1(),
759  new StateEventBSym2(),
760  NULL);
761 
762  setTimeOut(TRead);
763  }
764 
765  /*! \brief Destructor. */
766  virtual ~StateB() { }
767 
768  /*!
769  * \brief Receive the next event.
770  *
771  * \return Event id.
772  */
773  virtual int receiveEvent()
774  {
775  int nEventId;
776 
777  nEventId = StateKb::receiveEvent();
778 
779  switch( nEventId )
780  {
781  case EventIdPauseResume:
782  case EventIdRestart:
783  case EventIdTerminate:
784  return nEventId;
785  case KbEventTimeOut:
786  return readSymbol();
787  default:
788  return '?'; // force default action == this state
789  }
790  }
791 };
792 
793 
794 // .............................................................................
795 // (2,3) Turing State Machine Test
796 // .............................................................................
797 
798 /*!
799  * \brief Test State Machine.
800  *
801  * \par (2,3) Turing Machine:
802  * The 2-state 3-color(symbol) Turing machine (hereinafter (2,3) Turing
803  * machine) might be universal as well.\n\n
804  * See
805  * http://en.wikipedia.org/wiki/Wolfram%27s_2-state_3-symbol_Turing_machine
806  *
807  * \return Returns 0 if test succeeds, else returns \h_lt 0.
808  */
809 static int testSM()
810 {
811  // manually set rnr log level
812  //LOG_SET_THRESHOLD(LOG_LEVEL_DIAG3);
813 
814  State *listOfStates[] = {new StateStart(), new StateA(), new StateB(), NULL};
815 
816  StateMach sm(0, "(2,3)Turing", State::StateIdStart, listOfStates);
817 
818  sm.printStateMach();
819 
820  printf("%s", TestMenu);
821 
822  sm.run();
823 
824  LOG_SET_THRESHOLD(LOG_LEVEL_OFF);
825 
826  return 0;
827 }
828 
829 
830 #ifndef JENKINS
831 
832 /*!
833  * \brief Test State Machine class.
834  *
835  * \par The Test:
836  * Construct a (2,3) Turing State Machin and run.
837  */
838 TEST(SM, SM2_3Turing)
839 {
840  EXPECT_TRUE( testSM() == 0 );
841 }
842 
843 #endif // JENKINS
844 
845 
846 /*!
847  * \}
848  */
void moveHeadRight()
Move head right one position on the tape.
Definition: ut-sm.cxx:296
StateEventASym2()
Constuctor.
Definition: ut-sm.cxx:514
static int testSM()
Test State Machine.
Definition: ut-sm.cxx:809
StateEventASym0()
Constuctor.
Definition: ut-sm.cxx:422
static const char * ColorSymbol[]
color of symbols
Definition: ut-sm.cxx:92
virtual ~StateStart()
Destructor.
Definition: ut-sm.cxx:367
(2,3) Turing Machine&#39;s state B, symbol 0 event.
Definition: ut-sm.cxx:609
virtual int execAction(State *pState, int nPrevStateId, int nEventId)
Execute event action.
Definition: ut-sm.cxx:162
StateEventPauseResume()
Constuctor.
Definition: ut-sm.cxx:176
void moveHeadLeft()
Move head left one position on the tape.
Definition: ut-sm.cxx:285
StateEventBSym0()
Constuctor.
Definition: ut-sm.cxx:613
static const char * ColorHead
color tape head
Definition: ut-sm.cxx:91
(2,3) Turing Machine&#39;s state A, symbol 2 event.
Definition: ut-sm.cxx:510
virtual bool evalGuardExpr(State *pState, int nPrevStateId, int nEventId)
Evaluate event guard condition.
Definition: ut-sm.cxx:673
virtual ~StateEventTerminate()
Destructor.
Definition: ut-sm.cxx:214
StateEventBSym1()
Constuctor.
Definition: ut-sm.cxx:659
virtual int execAction(State *pState, int nPrevStateId, int nEventId)
Execute event action.
Definition: ut-sm.cxx:689
virtual bool evalGuardExpr(State *pState, int nPrevStateId, int nEventId)
Evaluate event guard condition.
Definition: ut-sm.cxx:482
virtual ~State2_3Turing()
Destructor.
Definition: ut-sm.cxx:260
static const int StateIdA
state A
Definition: ut-sm.cxx:81
static const uint_t TRead
read tape time interval
Definition: ut-sm.cxx:97
StateA()
Constuctor.
Definition: ut-sm.cxx:560
StateB()
Constuctor.
Definition: ut-sm.cxx:752
StateEventASym1()
Constuctor.
Definition: ut-sm.cxx:468
Finite State Machine interface.
State2_3Turing(int nStateId, const std::string &strStateName="", const std::string &strRefTag="")
Initializatoin constuctor.
Definition: ut-sm.cxx:252
virtual ~StateEventBSym2()
Destructor.
Definition: ut-sm.cxx:708
virtual int execAction(State *pState, int nPrevStateId, int nEventId)
Execute event action.
Definition: ut-sm.cxx:190
virtual int execAction(State *pState, int nPrevStateId, int nEventId)
Execute event action.
Definition: ut-sm.cxx:544
(2,3) Turing Machine&#39;s state B.
Definition: ut-sm.cxx:747
static const char * ColorEnd[]
end color
Definition: ut-sm.cxx:94
(2,3) Turing Machine&#39;s state B, symbol 1 event.
Definition: ut-sm.cxx:655
virtual int execAction(State *pState, int nPrevStateId, int nEventId)
Execute event action.
Definition: ut-sm.cxx:735
virtual bool evalGuardExpr(State *pState, int nPrevStateId, int nEventId)
Evaluate event guard condition.
Definition: ut-sm.cxx:528
StateEventBSym2()
Constuctor.
Definition: ut-sm.cxx:705
static const int StateIdB
state B
Definition: ut-sm.cxx:82
virtual int receiveEvent()
Receive the next event.
Definition: ut-sm.cxx:773
virtual ~StateEventASym1()
Destructor.
Definition: ut-sm.cxx:471
static const int EventIdTerminate
terminate event id
Definition: ut-sm.cxx:85
static vector< int > Tape
the tape of symbols
Definition: ut-sm.cxx:242
virtual ~StateA()
Destructor.
Definition: ut-sm.cxx:574
virtual bool evalGuardExpr(State *pState, int nPrevStateId, int nEventId)
Evaluate event guard condition.
Definition: ut-sm.cxx:436
Keyboard StateKb derived state class interface.
virtual ~StateEventBSym0()
Destructor.
Definition: ut-sm.cxx:616
Start state event class.
Definition: ut-sm.cxx:354
static const char * TestMenu
Test menu.
Definition: ut-sm.cxx:102
virtual ~StateEventASym2()
Destructor.
Definition: ut-sm.cxx:517
static const int EventIdPauseResume
pause/resume event id
Definition: ut-sm.cxx:84
(2,3) Turing Machine&#39;s state A.
Definition: ut-sm.cxx:556
Start state event class.
Definition: ut-sm.cxx:117
(2,3) Turing Machine&#39;s state B, symbol 2 event.
Definition: ut-sm.cxx:701
virtual int execAction(State *pState, int nPrevStateId, int nEventId)
Execute event action.
Definition: ut-sm.cxx:498
virtual int execAction(State *pState, int nPrevStateId, int nEventId)
Execute event action.
Definition: ut-sm.cxx:643
virtual int execAction(State *pState, int nPrevStateId, int nEventId)
Execute event action.
Definition: ut-sm.cxx:452
virtual int execAction(State *pState, int nPrevStateId, int nEventId)
Execute event action.
Definition: ut-sm.cxx:225
Random variable generator class interface.
virtual bool evalGuardExpr(State *pState, int nPrevStateId, int nEventId)
Evaluate event guard condition.
Definition: ut-sm.cxx:627
Terminate state event class.
Definition: ut-sm.cxx:207
StateEventStart()
Constuctor.
Definition: ut-sm.cxx:121
virtual void actionEnterState(int nPrefStateId, int nEventId)
Execute &#39;enter state&#39; action.
Definition: ut-sm.cxx:375
virtual int receiveEvent()
Receive the next event.
Definition: ut-sm.cxx:581
virtual ~StateEventASym0()
Destructor.
Definition: ut-sm.cxx:425
(2,3) Turing Machine&#39;s state A, symbol 0 event.
Definition: ut-sm.cxx:418
State base class interface.
The (2,3) Turing state base class.
Definition: ut-sm.cxx:239
static const int EventIdSymbol[]
tape symbol event ids
Definition: ut-sm.cxx:88
virtual ~StateEventStart()
Destructor.
Definition: ut-sm.cxx:124
virtual int execAction(State *pState, int nPrevStateId, int nEventId)
Execute event action.
Definition: ut-sm.cxx:135
virtual ~StateEventRestart()
Destructor.
Definition: ut-sm.cxx:151
static int Head
the tape read/write head
Definition: ut-sm.cxx:243
virtual ~StateEventPauseResume()
Destructor.
Definition: ut-sm.cxx:179
static const int EventIdStart
start event id
Definition: ut-sm.cxx:87
static const int EventIdRestart
restart event id
Definition: ut-sm.cxx:86
StateEventRestart()
Constuctor.
Definition: ut-sm.cxx:148
virtual ~StateB()
Destructor.
Definition: ut-sm.cxx:766
void showTape()
Show colorized tape to stdout.
Definition: ut-sm.cxx:307
TEST(SM, SM2_3Turing)
Test State Machine class.
Definition: ut-sm.cxx:838
virtual ~StateEventBSym1()
Destructor.
Definition: ut-sm.cxx:662
StateStart()
Constuctor.
Definition: ut-sm.cxx:358
RoadNarrows Robotics.
Definition: Camera.h:74
StateEventTerminate()
Constuctor.
Definition: ut-sm.cxx:211
virtual bool evalGuardExpr(State *pState, int nPrevStateId, int nEventId)
Evaluate event guard condition.
Definition: ut-sm.cxx:719
(2,3) Turing Machine&#39;s state A, symbol 1 event.
Definition: ut-sm.cxx:464
Pause/resume state event class.
Definition: ut-sm.cxx:172
Restart state event class.
Definition: ut-sm.cxx:144