def test_startReturnsActions(self): wanderer = RandomWalk(make_mock_environment()) actions = wanderer.dispatch(Start(), None) self.assertIsNotNone( actions, "dispatch has failed to return an initial action") self.assertTrue( len(actions) > 0, "dispatch has returned an empty list of actions")
def test_start_plan(self): actionExecutor = MockActionExecutor() plan = [Turn(math.pi), WalkForwardsIndefinitely()] env = make_mock_environment() save_plan(env, plan) print "Stored plan = " + repr(load_plan(env)) executor = PlanExecutor(env, actionExecutor) executor.perform_next_action() executor.perform_next_action() executor.perform_next_action() self.assertEqual(1, actionExecutor.allDoneCount, "all_done() should have been called once") self.assertItemsEqual(plan, actionExecutor.actions, "Executed actions should match plan")
def test_start_plan(self): actionExecutor = MockActionExecutor() plan = [Turn(math.pi), WalkForwardsIndefinitely()] env = make_mock_environment() save_plan(env, plan) print "Stored plan = "+repr(load_plan(env)) executor = PlanExecutor(env, actionExecutor) executor.perform_next_action() executor.perform_next_action() executor.perform_next_action() print "Executed actions = "+repr(actionExecutor.actions) self.assertEqual(1, actionExecutor.allDoneCount, "all_done() should have been called once") self.assertEqual(plan, actionExecutor.actions, "Executed actions should match plan")
def test_Bump(self): wanderer = RandomWalk(make_mock_environment()) actions = wanderer.dispatch(ObstacleDetected('LeftBumper', {'LeftBumper':True}), None) self.assertTrue(actions[0].distance < 0, "backoff after a bump")
def test_startReturnsActions(self): wanderer = RandomWalk(make_mock_environment()) actions = wanderer.dispatch(Start(), None) self.assertIsNotNone(actions, "dispatch has failed to return an initial action") self.assertTrue(len(actions) > 0, "dispatch has returned an empty list of actions")
def test_dispatch(self): wanderer = RandomWalk(make_mock_environment()) event = ObstacleDetected('LeftBumper', {'LeftBumper':True}) wanderer.dispatch(event, None)
def test_make_updaters(self): env = make_mock_environment() updaters = make_updaters(env) print "updaters = {}".format(updaters) self.assertTrue(updaters, "updaters should not be none") self.assertEqual(1, len(updaters), "Should be one updater class")
def test_dispatch(self): wanderer = RandomWalk(make_mock_environment()) event = ObstacleDetected('LeftBumper', self.sensors, self.position) wanderer.dispatch(event, None)
def main(): env = make_mock_environment() httpd = http.make_server(env, 8080) http.start_server(httpd)
def test_no_plan(self): actionExecutor = MockActionExecutor() executor = PlanExecutor(make_mock_environment(), actionExecutor) executor.perform_next_action() self.assertEqual(1, actionExecutor.allDoneCount, "all_done() should have been called once") self.assertEqual([], actionExecutor.actions, "No actions should have been executed")
def test_Bump(self): wanderer = RandomWalk(make_mock_environment()) actions = wanderer.dispatch( ObstacleDetected('LeftBumper', self.sensors, self.position), None) self.assertTrue(actions[0].distance < 0, "backoff after a bump")