def testScanning_LowBattery(self):
     sm = StateMachine()
     sm.handle_event(Event.START_PATROL)
     sm.handle_event(Event.SCANNING_TIME)
     sm.handle_event(Event.LOW_BATTERY)
     self.assertEqual(sm.get_state(), State.PATROLLING,
                      "SCANNING + LOW_BATTERY PATROLLING is valid")
 def testCharging_FullyCharged(self):
     sm = StateMachine()
     sm.handle_event(Event.LOW_BATTERY)
     sm.handle_event(Event.ARRIVED_AT_BASE)
     sm.handle_event(Event.FULLY_CHARGED)
     self.assertEqual(sm.get_state(), State.IDLE,
                      "RETURNING_TO_BASE + FULLY_CHARGED -> IDLE is valid")
 def testScaring_LowBattery(self):
     sm = StateMachine()
     sm.handle_event(Event.START_PATROL)
     sm.handle_event(Event.ARRIVED_AT_MOLEHILL)
     sm.handle_event(Event.LOW_BATTERY)
     self.assertEqual(sm.get_state(), State.PATROLLING,
                      "SCARING + LOW_BATTERY -> PATROLLING is valid")
 def testScaring_DoneScaring(self):
     sm = StateMachine()
     sm.handle_event(Event.START_PATROL)
     sm.handle_event(Event.ARRIVED_AT_MOLEHILL)
     sm.handle_event(Event.DONE_SCARING)
     self.assertEqual(sm.get_state(), State.PATROLLING,
                      "SCARING + DONE_SCARING -> PATROLLING is valid")
 def testScaring_ArrivedAtMolehill(self):
     sm = StateMachine()
     sm.handle_event(Event.START_PATROL)
     sm.handle_event(Event.ARRIVED_AT_MOLEHILL)
     with self.assertRaises(InvalidEventException,
                            msg="SCARING + is invalid"):
         sm.handle_event(Event.ARRIVED_AT_MOLEHILL)
 def testCharging_StartPatrol(self):
     sm = StateMachine()
     sm.handle_event(Event.LOW_BATTERY)
     sm.handle_event(Event.ARRIVED_AT_BASE)
     with self.assertRaises(InvalidEventException,
                            msg="CHARGING + START_PATROL is invalid"):
         sm.handle_event(Event.START_PATROL)
 def testScaring_FullyCharged(self):
     sm = StateMachine()
     sm.handle_event(Event.START_PATROL)
     sm.handle_event(Event.ARRIVED_AT_MOLEHILL)
     with self.assertRaises(InvalidEventException,
                            msg="SCARING + FULLY_CHARGED is invalid"):
         sm.handle_event(Event.FULLY_CHARGED)
 def testScanning_DoneScaring(self):
     sm = StateMachine()
     sm.handle_event(Event.START_PATROL)
     sm.handle_event(Event.SCANNING_TIME)
     with self.assertRaises(InvalidEventException,
                            msg="SCANNING + DONE_SCARING is invalid"):
         sm.handle_event(Event.DONE_SCARING)
 def testScanning_FullyCharged(self):
     sm = StateMachine()
     sm.handle_event(Event.START_PATROL)
     sm.handle_event(Event.SCANNING_TIME)
     with self.assertRaises(InvalidEventException,
                            msg="SCANNING + FULLY_CHARGED is invalid"):
         sm.handle_event(Event.FULLY_CHARGED)
 def testScanning_ArrivedAtBase(self):
     sm = StateMachine()
     sm.handle_event(Event.START_PATROL)
     sm.handle_event(Event.SCANNING_TIME)
     with self.assertRaises(InvalidEventException,
                            msg="SCANNING + ARRIVED_AT_BASE is invalid"):
         sm.handle_event(Event.ARRIVED_AT_BASE)
 def testScanning_ScanningTime(self):
     sm = StateMachine()
     sm.handle_event(Event.START_PATROL)
     sm.handle_event(Event.SCANNING_TIME)
     with self.assertRaises(InvalidEventException,
                            msg="SCANNING + SCANNING_TIME is invalid"):
         sm.handle_event(Event.SCANNING_TIME)
 def testCharging_DonePatrolling(self):
     sm = StateMachine()
     sm.handle_event(Event.LOW_BATTERY)
     sm.handle_event(Event.ARRIVED_AT_BASE)
     with self.assertRaises(
             InvalidEventException,
             msg="RETURNING_TO_BASE + DONE_PATROLLING is invalid"):
         sm.handle_event(Event.DONE_PATROLLING)
 def testCharging_ScanningTime(self):
     sm = StateMachine()
     sm.handle_event(Event.LOW_BATTERY)
     sm.handle_event(Event.ARRIVED_AT_BASE)
     with self.assertRaises(
             InvalidEventException,
             msg="RETURNING_TO_BASE + SCANNING_TIME is invalid"):
         sm.handle_event(Event.SCANNING_TIME)
 def testCharging_ArrivedAtBase(self):
     sm = StateMachine()
     sm.handle_event(Event.LOW_BATTERY)
     sm.handle_event(Event.ARRIVED_AT_BASE)
     with self.assertRaises(
             InvalidEventException,
             msg="RETURNING_TO_BASE + ARRIVED_AT_BASE is invalid"):
         sm.handle_event(Event.ARRIVED_AT_BASE)
 def testReturningToBase_ArrivedAtBase(self):
     sm = StateMachine()
     sm.handle_event(Event.LOW_BATTERY)
     sm.handle_event(Event.ARRIVED_AT_BASE)
     self.assertEqual(
         sm.get_state(), State.CHARGING,
         "RETURNING_TO_BASE + ARRIVED_AT_BASE -> CHARGING is valid")
 def testPatrolling_ArrivedAtMolehill(self):
     sm = StateMachine()
     sm.handle_event(Event.START_PATROL)
     sm.handle_event(Event.ARRIVED_AT_MOLEHILL)
     self.assertEqual(
         sm.get_state(), State.SCARING,
         "PATROLLING + ARRIVED_AT_MOLEHILL -> SCARING is valid")
 def testPatrolling_LowBattery(self):
     sm = StateMachine()
     sm.handle_event(Event.START_PATROL)
     sm.handle_event(Event.LOW_BATTERY)
     self.assertEqual(
         sm.get_state(), State.RETURNING_TO_BASE,
         "PATROLLING + LOW_BATTERY -> RETURNING_TO_BASE is valid")
 def testScanning_DoneScanning(self):
     sm = StateMachine()
     sm.handle_event(Event.START_PATROL)
     sm.handle_event(Event.SCANNING_TIME)
     sm.handle_event(Event.DONE_SCANNING)
     self.assertEqual(sm.get_state(), State.PATROLLING,
                      "SCANNING + DONE_SCANNING is invalid")
 def testReturningToBase_ArrivedAtMolehill(self):
     sm = StateMachine()
     sm.handle_event(Event.LOW_BATTERY)
     with self.assertRaises(
             InvalidEventException,
             msg="RETURNING_TO_BASE + LOW_BATTERY is invalid"):
         sm.handle_event(Event.ARRIVED_AT_MOLEHILL)
 def testReturningToBase_StartPatrol(self):
     sm = StateMachine()
     sm.handle_event(Event.LOW_BATTERY)
     with self.assertRaises(
             InvalidEventException,
             msg="RETURNING_TO_BASE + START_PATROL is invalid"):
         sm.handle_event(Event.START_PATROL)
 def testReturningToBase_LowBattery(self):
     sm = StateMachine()
     sm.handle_event(Event.LOW_BATTERY)
     with self.assertRaises(
             InvalidEventException,
             msg="RETURNING_TO_BASE + LOW_BATTERY is invalid"):
         sm.handle_event(Event.LOW_BATTERY)
 def testReturningToBase_FullyCharged(self):
     sm = StateMachine()
     sm.handle_event(Event.LOW_BATTERY)
     with self.assertRaises(
             InvalidEventException,
             msg="RETURNING_TO_BASE + FULLY_CHARGED is invalid"):
         sm.handle_event(Event.FULLY_CHARGED)
 def testReturningToBase_ScanningTime(self):
     sm = StateMachine()
     sm.handle_event(Event.LOW_BATTERY)
     with self.assertRaises(
             InvalidEventException,
             msg="RETURNING_TO_BASE + SCANNING_TIME is invalid"):
         sm.handle_event(Event.SCANNING_TIME)
 def testReturningToBase_DonePatrolling(self):
     sm = StateMachine()
     sm.handle_event(Event.LOW_BATTERY)
     with self.assertRaises(
             InvalidEventException,
             msg="RETURNING_TO_BASE + DONE_PATROLLING is invalid"):
         sm.handle_event(Event.DONE_PATROLLING)
 def testPatrolling_ArrivedAtBase(self):
     sm = StateMachine()
     sm.handle_event(Event.START_PATROL)
     with self.assertRaises(
             InvalidEventException,
             msg="PATROLLING + ARRIVED_AT_BASE is not valid"):
         sm.handle_event(Event.ARRIVED_AT_BASE)
 def testCreate(self):
     sm = StateMachine()
     self.assertEqual(sm.get_state(), State.IDLE,
                      "When created should be in IDLE state.")
     self.assertNotEqual(
         sm.get_state(), State.PATROLLING,
         "Ensure that the IDLE state is not the same as the PATROLLING state"
     )
     self.assertNotEqual(
         sm.get_state(), State.RETURNING_TO_BASE,
         "Ensure that the IDLE state is not the same as the RETURNING_TO_BASE state"
     )
     self.assertNotEqual(
         sm.get_state(), State.CHARGING,
         "Ensure that the IDLE state is not the same as the CHARGING state")
     self.assertNotEqual(
         sm.get_state(), State.SCARING,
         "Ensure that the IDLE state is not the same as the SCARING state")
     self.assertNotEqual(
         sm.get_state(), State.SCANNING,
         "Ensure that the IDLE state is not the same as the SCANNING state")
 def testPatrolling_StartPatrol(self):
     sm = StateMachine()
     sm.handle_event(Event.START_PATROL)
     with self.assertRaises(InvalidEventException,
                            msg="PATROLLING + START_PATROL is not valid"):
         sm.handle_event(Event.START_PATROL)
 def testIdle_DonePatrolling(self):
     sm = StateMachine()
     with self.assertRaises(InvalidEventException,
                            msg="IDLE + DONE_PATROLLING is not valid"):
         sm.handle_event(Event.DONE_PATROLLING)
 def testIdle_DoneScanning(self):
     sm = StateMachine()
     with self.assertRaises(InvalidEventException,
                            msg="IDLE + DONE_SCANNING is not valid"):
         sm.handle_event(Event.DONE_SCANNING)
 def testIdle_ScanningTime(self):
     sm = StateMachine()
     with self.assertRaises(InvalidEventException,
                            msg="IDLE + SCANNING_TIME is not valid"):
         sm.handle_event(Event.SCANNING_TIME)