def test_C3(mpers): fullContext = [ mpers.contexts.c1, mpers.contexts.c2, mpers.contexts.c3, mpers.contexts.c4, mpers.contexts.c5, mpers.contexts.c6, mpers.contexts.c7, mpers.contexts.c8 ] tasks = KnapsackPlanning().isAchievablePlan(mpers.rootGoal, fullContext, None) assert tasks is not None for task in tasks.getTasks(): assert task.identifier != "acceptEmergency"
def test_C10(mpers): fullContext = [ mpers.contexts.c1, mpers.contexts.c2, mpers.contexts.c3, mpers.contexts.c5, mpers.contexts.c6, mpers.contexts.c8, mpers.contexts.c10, mpers.contexts.c12 ] tasks = KnapsackPlanning().isAchievablePlan(mpers.rootGoal, fullContext, None) plan = ["notifyByLightAlert", "acceptEmergency"] assert tasks is not None for task in tasks.getTasks(): assert task.identifier not in plan
def test_abidesByInterpretation_not_passing_baseline(mpers): isNotifiedAboutEmergencyGoal = mpers.goals.isNotifiedAboutEmergencyGoal notifyBySoundAlertTask = mpers.tasks.notifyBySoundAlertTask c6 = mpers.contexts.c6 c1 = mpers.contexts.c1 context = [c6] result = KnapsackPlanning().abidesByInterpretation( notifyBySoundAlertTask, isNotifiedAboutEmergencyGoal.interp, context) assert result == True context = [c1] result = KnapsackPlanning().abidesByInterpretation( notifyBySoundAlertTask, isNotifiedAboutEmergencyGoal.interp, context) assert result == False
def test_C6(mpers): fullContext = [ mpers.contexts.c1, mpers.contexts.c4, mpers.contexts.c5, mpers.contexts.c6, mpers.contexts.c7, mpers.contexts.c8, mpers.contexts.c10, mpers.contexts.c12 ] tasks = KnapsackPlanning().isAchievablePlan(mpers.rootGoal, fullContext, None) plan = ["notifyCentralBySMS", "confirmEmergencyByCall", "sendInfoBySMS"] assert tasks is not None for task in tasks.getTasks(): assert task.identifier not in plan
def test_abidesByInterpretation_passing_baseline(mpers): isNotifiedAboutEmergencyGoal = mpers.goals.isNotifiedAboutEmergencyGoal notifyByMobileVibrationTask = mpers.tasks.notifyByMobileVibrationTask c1 = mpers.contexts.c1 c9 = mpers.contexts.c9 context = [c1] result = KnapsackPlanning().abidesByInterpretation( notifyByMobileVibrationTask, isNotifiedAboutEmergencyGoal.interp, context) assert result == True context = [c9] result = KnapsackPlanning().abidesByInterpretation( notifyByMobileVibrationTask, isNotifiedAboutEmergencyGoal.interp, context) assert result == True
def test_abidesByInterpretation_context_not_passing(mpers): identifyLocationByVoiceCallTask = mpers.tasks.identifyLocationByVoiceCallTask locationIsIdentifiedGoal = mpers.goals.locationIsIdentifiedGoal c5 = mpers.contexts.c5 context = [] result = KnapsackPlanning().abidesByInterpretation( identifyLocationByVoiceCallTask, locationIsIdentifiedGoal.interp, context) assert result == True context.append(c5) result = KnapsackPlanning().abidesByInterpretation( identifyLocationByVoiceCallTask, locationIsIdentifiedGoal.interp, context) assert result == False
def test_abidesByInterpretation_only_baseline(mpers): considerLastKnownLocationTask = mpers.tasks.considerLastKnownLocationTask locationIsIdentifiedGoal = mpers.goals.locationIsIdentifiedGoal context = [] result = KnapsackPlanning().abidesByInterpretation( considerLastKnownLocationTask, locationIsIdentifiedGoal.interp, context) assert result == True
def test_abidesByInterpretation_only_baseline_not_passing(mpers): locationIsIdentifiedGoal = mpers.goals.locationIsIdentifiedGoal context = [] LongSecondsTask = KnapsackObject("LongSecondsTask") LongSecondsTask.setProvidedQuality(None, MpersMetrics.SECONDS, 1500) result = KnapsackPlanning().abidesByInterpretation( LongSecondsTask, locationIsIdentifiedGoal.interp, context) assert result == False
def test_C4(mpers): fullContext = [ mpers.contexts.c1, mpers.contexts.c4, mpers.contexts.c6, mpers.contexts.c7, mpers.contexts.c8, mpers.contexts.c10, mpers.contexts.c12 ] tasks = KnapsackPlanning().isAchievablePlan(mpers.rootGoal, fullContext, None) plan = [ "notifyCentralBySMS", "confirmEmergencyByCall", "notifyBySoundAlert", "sendInfoBySMS", "identifyLocationByVoiceCall", "accessLocationFromTriangulation" ] assert tasks is not None for task in tasks.getTasks(): assert task.identifier not in plan
def test_EmergencyIsDetectedGoal(mpers): fullcontext = [ mpers.contexts.c1, mpers.contexts.c2, mpers.contexts.c3, mpers.contexts.c4, mpers.contexts.c8 ] plan = KnapsackPlanning().isAchievablePlan( mpers.goals.emergencyIsDetectedGoal, fullcontext, None) assert assertPlan(plan, [ mpers.tasks.notifyCentralByInternetTask, mpers.tasks.confirmEmergencyByCallTask ])
def test_IsNotifiedAboutEmergencyGoal(mpers): fullcontext = [ mpers.contexts.c1, mpers.contexts.c2, mpers.contexts.c3, mpers.contexts.c4, mpers.contexts.c5, mpers.contexts.c6, mpers.contexts.c7, mpers.contexts.c8, mpers.contexts.c9, mpers.contexts.c10 ] plan = KnapsackPlanning().isAchievablePlan( mpers.goals.isNotifiedAboutEmergencyGoal, fullcontext, None) assert assertPlan(plan, [mpers.tasks.notifyByLightAlertTask])
def test_infoIsPreparedGoal(mpers): fullcontext = [ mpers.contexts.c1, mpers.contexts.c2, mpers.contexts.c3, mpers.contexts.c4, mpers.contexts.c8 ] plan = KnapsackPlanning().isAchievablePlan(mpers.goals.infoIsPreparedGoal, fullcontext, None) assert assertPlan(plan, [ mpers.tasks.accessLocationFromGPSTask, mpers.tasks.accessDataFromDatabaseTask ])
def test_centralReceivesInfoGoal(mpers): fullcontext = [ mpers.contexts.c1, mpers.contexts.c2, mpers.contexts.c3, mpers.contexts.c4, mpers.contexts.c8 ] plan = KnapsackPlanning().isAchievablePlan( mpers.goals.centralReceivesInfoGoal, fullcontext, None) assert assertPlan(plan, [ mpers.tasks.sendInfoByInternetTask, mpers.tasks.accessLocationFromGPSTask, mpers.tasks.accessDataFromDatabaseTask ])
def test_C1(mpers): fullContext = [ mpers.contexts.c1, mpers.contexts.c2, mpers.contexts.c4, mpers.contexts.c5, mpers.contexts.c7, mpers.contexts.c8, mpers.contexts.c10, mpers.contexts.c12 ] plan = KnapsackPlanning().isAchievablePlan(mpers.rootGoal, fullContext, None) assert plan is not None assert False is assertPlan( plan, [mpers.tasks.accessLocationFromGPSTask, mpers.tasks.centralCallTask])
def test_MPERS_model(mpers): fullcontext = [ mpers.contexts.c1, mpers.contexts.c2, mpers.contexts.c3, mpers.contexts.c4, mpers.contexts.c8 ] plan = KnapsackPlanning().isAchievablePlan(mpers.rootGoal, fullcontext, None) assert True is assertPlan(plan, [ mpers.tasks.notifyCentralByInternetTask, mpers.tasks.confirmEmergencyByCallTask, mpers.tasks.notifyByMobileVibrationTask, mpers.tasks.sendInfoByInternetTask, mpers.tasks.accessLocationFromGPSTask, mpers.tasks.accessDataFromDatabaseTask, mpers.tasks.ambulanceDispatchDelegationTask, ])
def isAchievable(self, current, interp): newInterp = Interpretation() newInterp.merge(self.interp) newInterp.merge(interp) return KnapsackPlanning().isAchievable(self, current, newInterp)