Esempio n. 1
0
 def test_transition_from_int1_to_frac1(self):
     # Given a QCalc engine in int1
     self.dut.TRAN(QCalc.int1)
     empty = qp.Event(qp.qep._QEP_EMPTY_SIG)
     self.dut.dispatch(empty)
     # When pressing the point button
     button = qp.Event(POINT_SIG)
     button.key = '.'
     self.dut.dispatch(button)
     # Then
     self.assertTrue(self.dut.is_in(QCalc.frac1))
Esempio n. 2
0
 def test_transition_from_begin_to_int1(self):
     # Given a QCalc engine in begin
     self.dut.TRAN(QCalc.begin)
     empty = qp.Event(qp.qep._QEP_EMPTY_SIG)
     self.dut.dispatch(empty)
     # When pressing a numeric button
     button = qp.Event(DIGIT_1_9_SIG)
     button.key = '1'
     self.dut.dispatch(button)
     # Then
     self.assertTrue(self.dut.is_in(QCalc.int1))
Esempio n. 3
0
 def button_clicked(self, button, sig, key):
     # Main driver of state machine events
     # Create event from button signal handler
     e = qp.Event(sig)
     e.key = key
     self.engine.dispatch(e)
     text = self.engine.get_display()
     self.widgets.get_widget('display').set_label(text)
Esempio n. 4
0
 def serving(self, e):
     if e.sig == HUNGRY_SIG:
         n = e.phil_num
         assert n < self.count and not self.isHungry_[n]
         displyPhilStat(n, "hungry")
         m = self.LEFT(n)
         if (self.fork_[m] == Table.FREE and self.fork_[n] == Table.FREE):
             self.fork_[m] = Table.USED_LEFT
             self.fork_[n] = Table.USED_RIGHT
             pe = TableEvt(EAT_SIG)
             pe.phil_num = n
             qp.QF.publish(pe)
             displyPhilStat(n, "eating")
         else:
             self.isHungry_[n] = True
         return 0
     elif e.sig == DONE_SIG:
         n = e.phil_num
         assert n < self.count
         self.fork_[self.LEFT(n)] = Table.FREE
         self.fork_[n] = Table.FREE
         displyPhilStat(n, "thinking")
         neighbor = self.RIGHT(n)  # check the right neighbor
         if (self.isHungry_[neighbor]
                 and self.fork_[neighbor] == Table.FREE):
             self.fork_[n] = Table.USED_LEFT
             self.fork_[neighbor] = Table.USED_RIGHT
             self.isHungry_[neighbor] = 0
             pe = TableEvt(EAT_SIG)
             pe.phil_num = neighbor
             qp.QF.publish(pe)
             displyPhilStat(neighbor, "eating")
         neighbor = self.LEFT(n)  # check the left neighbor
         if (self.isHungry_[neighbor]
                 and self.fork_[self.LEFT(neighbor)] == Table.FREE):
             self.fork_[self.LEFT(neighbor)] = Table.USED_LEFT
             self.fork_[neighbor] = Table.USED_RIGHT
             self.isHungry_[neighbor] = 0
             pe = TableEvt(EAT_SIG)
             pe.phil_num = neighbor
             qp.QF.publish(pe)
             displyPhilStat(neighbor, "eating")
         return 0
     elif e.sig == STOP_SIG:
         n = e.phil_num
         displyPhilStat(n, "stopped")
         self.stoppedNums_ += 1
         if self.stoppedNums_ == self.count:
             pe = qp.Event(TERMINATE_SIG)
             qp.QF.publish(pe)
         return 0
     elif e.sig == TERMINATE_SIG:
         print("received TERMINATE-SIG")
         self.stop()
         return 0
     return qp.Hsm.top
Esempio n. 5
0
    def test_that_transitions_matches_expected_route(self):
        qhsm = HsmTst()
        qhsm.init()  # Initial transition
        qhsm.dispatch(qp.Event(A_SIG))
        qhsm.dispatch(qp.Event(B_SIG))
        qhsm.dispatch(qp.Event(D_SIG))
        qhsm.dispatch(qp.Event(E_SIG))
        qhsm.dispatch(qp.Event(I_SIG))
        qhsm.dispatch(qp.Event(F_SIG))
        qhsm.dispatch(qp.Event(I_SIG))
        qhsm.dispatch(qp.Event(I_SIG))
        qhsm.dispatch(qp.Event(F_SIG))
        qhsm.dispatch(qp.Event(A_SIG))
        qhsm.dispatch(qp.Event(B_SIG))
        qhsm.dispatch(qp.Event(D_SIG))
        qhsm.dispatch(qp.Event(D_SIG))
        qhsm.dispatch(qp.Event(E_SIG))
        qhsm.dispatch(qp.Event(G_SIG))
        qhsm.dispatch(qp.Event(H_SIG))
        qhsm.dispatch(qp.Event(H_SIG))
        qhsm.dispatch(qp.Event(C_SIG))
        qhsm.dispatch(qp.Event(G_SIG))
        qhsm.dispatch(qp.Event(C_SIG))
        qhsm.dispatch(qp.Event(C_SIG))

        # static transitions
        qhsm.dispatch(qp.Event(C_SIG))
        qhsm.dispatch(qp.Event(A_SIG))
        qhsm.dispatch(qp.Event(A_SIG))
        qhsm.dispatch(qp.Event(B_SIG))
        qhsm.dispatch(qp.Event(B_SIG))
        qhsm.dispatch(qp.Event(D_SIG))
        qhsm.dispatch(qp.Event(D_SIG))
        qhsm.dispatch(qp.Event(E_SIG))
        qhsm.dispatch(qp.Event(I_SIG))
        qhsm.dispatch(qp.Event(F_SIG))
        qhsm.dispatch(qp.Event(I_SIG))
        qhsm.dispatch(qp.Event(I_SIG))
        qhsm.dispatch(qp.Event(F_SIG))
        qhsm.dispatch(qp.Event(A_SIG))
        qhsm.dispatch(qp.Event(A_SIG))
        qhsm.dispatch(qp.Event(B_SIG))
        qhsm.dispatch(qp.Event(B_SIG))
        qhsm.dispatch(qp.Event(D_SIG))
        qhsm.dispatch(qp.Event(D_SIG))
        qhsm.dispatch(qp.Event(D_SIG))
        qhsm.dispatch(qp.Event(D_SIG))
        qhsm.dispatch(qp.Event(E_SIG))
        qhsm.dispatch(qp.Event(G_SIG))
        qhsm.dispatch(qp.Event(H_SIG))
        qhsm.dispatch(qp.Event(G_SIG))
        qhsm.dispatch(qp.Event(H_SIG))
        qhsm.dispatch(qp.Event(F_SIG))
        qhsm.dispatch(qp.Event(H_SIG))
        qhsm.dispatch(qp.Event(F_SIG))
        qhsm.dispatch(qp.Event(C_SIG))
        qhsm.dispatch(qp.Event(G_SIG))
        qhsm.dispatch(qp.Event(G_SIG))

        qhsm.dispatch(qp.Event(TERMINATE_SIG))
        # Check difference
        self.assertEqual(EXPECTED_STRING, qhsm.result)
Esempio n. 6
0
 def test_transition_from_d211_to_d11(self):
     qhsm = HsmTst()
     qhsm.init()  # Initial transition
     qhsm.dispatch(qp.Event(E_SIG))
     self.assertTrue(qhsm.is_in(HsmTst.d11))
Esempio n. 7
0
def terminate():
    e = qp.Event(TERMINATE_SIG)
    qp.QF.publish(e)