A R Karthick | a2e53d6 | 2016-02-19 17:38:30 -0800 | [diff] [blame] | 1 | class CordTester(object): |
| 2 | |
| 3 | def __init__(self, fsmTable, stopState, stateTable = None, eventTable = None): |
| 4 | self.fsmTable = fsmTable |
| 5 | self.stopState = stopState |
| 6 | self.stateTable = stateTable |
| 7 | self.eventTable = eventTable |
| 8 | self.currentState = None |
| 9 | self.currentEvent = None |
| 10 | self.nextState = None |
| 11 | self.nextEvent = None |
| 12 | |
| 13 | def runTest(self): |
| 14 | while self.currentState != self.stopState and self.currentEvent != None: |
| 15 | if self.stateTable and self.eventTable: |
| 16 | print 'Current state: %s, Current event: %s' %(self.stateTable.toStr(self.currentState), |
| 17 | self.eventTable.toStr(self.currentEvent)) |
| 18 | key = (self.currentState, self.currentEvent) |
| 19 | (actions, nextState) = self.fsmTable[key] |
| 20 | if actions: |
| 21 | for a in actions: |
| 22 | a() |
| 23 | self.currentState = nextState |
| 24 | self.currentEvent = self.nextEvent |