Example #1
0
def test_aGoalOrDecomposedWithTwoTasksMayBeAchievableAtOnlyOneBranch():
    goal = Goal(Decomposition.OR, "Root")
    assert goal.decomposition

    task1 = Task("T1")
    task2 = Task("T2")

    current = Context("C1")
    fullContext = []
    fullContext.append(current)

    qc = QualityConstraint(current, CommonMetrics.SECONDS, 15,
                           Comparison.LESS_OR_EQUAL_TO)

    task1.addApplicableContext(current)
    task1.setProvidedQuality(current, CommonMetrics.SECONDS, 16)

    task2.addApplicableContext(current)
    task2.setProvidedQuality(current, CommonMetrics.SECONDS, 11)

    goal.addDependency(task1)
    goal.addDependency(task2)

    goal.addApplicableContext(current)

    interp = Interpretation()
    interp.addQualityConstraint(qc)

    plan = PragmaticPlanning().isAchievable(goal, fullContext, interp)
    assert task2 in plan.getTasks()
    assert task1 not in plan.getTasks()
Example #2
0
def test_shouldIncludeNonApplicableContexts():
    goal = Pragmatic(False, "Root")

    task = Task("T1")
    context = Context("C1")
    wrongContext = Context("C2")
    current = []

    qc = QualityConstraint(context, CommonMetrics.SECONDS, 15,
                           Comparison.LESS_OR_EQUAL_TO)

    task.addApplicableContext(context)
    task.setProvidedQuality(context, CommonMetrics.SECONDS, 13)

    goal.addDependency(task)
    goal.addNonapplicableContext(wrongContext)
    goal.interp.addQualityConstraint(qc)

    interp = Interpretation()
    interp.addQualityConstraint(qc)

    current.append(wrongContext)
    assert PragmaticPlanning().isAchievable(goal, current, interp) is None

    current.append(context)
    assert PragmaticPlanning().isAchievable(goal, current, interp) is None

    current.remove(wrongContext)
    assert PragmaticPlanning().isAchievable(goal, current, interp)
    assert PragmaticPlanning().isAchievable(goal, current, interp).getTasks()
    assert 1 == len(goal.isAchievable(current, interp).getTasks())
Example #3
0
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 = PragmaticPlanning().isAchievablePlan(mpers.rootGoal, fullcontext,
                                                 None)
    plan = ["notifyByLightAlert", "acceptEmergency"]
    assert tasks is not None
    for task in tasks.getTasks():
        assert task.identifier not in plan
Example #4
0
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 = PragmaticPlanning().isAchievablePlan(mpers.rootGoal, fullcontext,
                                                 None)

    assert tasks is not None

    for task in tasks.getTasks():
        assert task.identifier != "acceptEmergency"
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 = PragmaticPlanning().abidesByInterpretation(
        notifyBySoundAlertTask, isNotifiedAboutEmergencyGoal.interp, context)
    assert result == True

    context = [c1]
    result = PragmaticPlanning().abidesByInterpretation(
        notifyBySoundAlertTask, isNotifiedAboutEmergencyGoal.interp, context)
    assert result == False
Example #6
0
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 = PragmaticPlanning().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
Example #7
0
def test_LocationIsIdentifiedGoal(mpers):
    fullcontext = []
    plan = PragmaticPlanning().isAchievable(
        mpers.goals.locationIsIdentifiedGoal, fullcontext, None)

    assert True is assertPlan(plan,
                              [mpers.tasks.considerLastKnownLocationTask])
def test_myQualityBaseline(mpers):
    accessLocationFromTriangulationTask = mpers.tasks.accessLocationFromTriangulationTask
    c2 = mpers.contexts.c2
    c11 = mpers.contexts.c11

    context = [c2]
    result = PragmaticPlanning().myProvidedQuality(
        accessLocationFromTriangulationTask, MpersMetrics.DISTANCE_ERROR,
        context)
    assert result == 40

    context.append(c11)
    result = PragmaticPlanning().myProvidedQuality(
        accessLocationFromTriangulationTask, MpersMetrics.DISTANCE_ERROR,
        context)
    assert result == 400
def test_ContextSet3_isNotifiedAboutEmergencyGoal(mpers):
    fullContext = [mpers.contexts.c4, mpers.contexts.c8, mpers.contexts.c11]

    plan = PragmaticPlanning().isAchievablePlan(
        mpers.goals.isNotifiedAboutEmergencyGoal, fullContext, None)

    assert assertPlan(plan, [mpers.tasks.centralCallTask])
Example #10
0
def test_ApplicableDeps():
    goal = Pragmatic(Decomposition.AND, "Root")

    task = Task("T1")
    context = Context("C1")
    wrongContext = Context("C2")

    qc = QualityConstraint(context, CommonMetrics.SECONDS, 15,
                           Comparison.LESS_OR_EQUAL_TO)

    task.addApplicableContext(context)
    task.setProvidedQuality(context, CommonMetrics.SECONDS, 13)

    goal.addDependency(task)
    goal.addApplicableContext(context)
    goal.interp.addQualityConstraint(qc)

    interp = Interpretation()
    interp.addQualityConstraint(qc)
    current = []
    current.append(wrongContext)
    assert PragmaticPlanning().isAchievable(goal, current, interp) is None

    current.append(context)
    assert len(goal.isAchievable(current, interp).getTasks()) == 1
def test_shouldBeUnachievable():
    root = Goal(Decomposition.AND, "root")

    context1 = Context("c1")
    context2 = Context("c2")

    current = []
    current.append(context1)

    task1 = Task("T1")
    task2 = Task("T2")

    task1.addApplicableContext(context2)
    task2.addApplicableContext(context2)

    root.addDependency(task1)
    root.addDependency(task2)

    deps = []
    deps.append(task1)
    deps.append(task2)

    plan = PragmaticPlanning().isAchievable(root, current, None)

    assert plan is None
Example #12
0
def test_shouldBeApplicable():
    goal = Goal(Decomposition.AND, "G1")
    task = Task("T1")
    delegation = Delegation("D1")

    contextCurrent = Context("C1")
    fullContext = []

    fullContext.append(contextCurrent)

    goal.addApplicableContext(contextCurrent)
    task.addApplicableContext(contextCurrent)
    delegation.addApplicableContext(contextCurrent)

    assert True is PragmaticPlanning().isApplicable(goal, fullContext)
    assert True is PragmaticPlanning().isApplicable(task, fullContext)
    assert True is PragmaticPlanning().isApplicable(delegation, fullContext)
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 = PragmaticPlanning().abidesByInterpretation(
        notifyByMobileVibrationTask, isNotifiedAboutEmergencyGoal.interp,
        context)
    assert result == True

    context = [c9]
    result = PragmaticPlanning().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 = PragmaticPlanning().abidesByInterpretation(
        identifyLocationByVoiceCallTask, locationIsIdentifiedGoal.interp,
        context)
    assert result == True

    context.append(c5)

    result = PragmaticPlanning().abidesByInterpretation(
        identifyLocationByVoiceCallTask, locationIsIdentifiedGoal.interp,
        context)
    assert result == False
Example #15
0
def test_IsNotifiedAboutEmergency(mpers):
    fullcontext = [
        mpers.contexts.c1, mpers.contexts.c2, mpers.contexts.c3,
        mpers.contexts.c4, mpers.contexts.c8
    ]
    plan = PragmaticPlanning().isAchievablePlan(
        mpers.goals.isNotifiedAboutEmergencyGoal, fullcontext, None)

    assert True is assertPlan(plan, [mpers.tasks.notifyByMobileVibrationTask])
def test_abidesByInterpretation_only_baseline(mpers):
    considerLastKnownLocationTask = mpers.tasks.considerLastKnownLocationTask
    locationIsIdentifiedGoal = mpers.goals.locationIsIdentifiedGoal
    context = []

    result = PragmaticPlanning().abidesByInterpretation(
        considerLastKnownLocationTask, locationIsIdentifiedGoal.interp,
        context)
    assert result == True
Example #17
0
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 = PragmaticPlanning().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_abidesByInterpretation_only_baseline_not_passing(mpers):
    locationIsIdentifiedGoal = mpers.goals.locationIsIdentifiedGoal
    context = []

    LongSecondsTask = Task("LongSecondsTask")
    LongSecondsTask.setProvidedQuality(None, MpersMetrics.SECONDS, 1500)

    result = PragmaticPlanning().abidesByInterpretation(
        LongSecondsTask, locationIsIdentifiedGoal.interp, context)
    assert result == False
def test_ContextSet3_emergencyIsDetectedGoal(mpers):
    fullContext = [mpers.contexts.c4, mpers.contexts.c8, mpers.contexts.c11]

    plan = PragmaticPlanning().isAchievablePlan(
        mpers.goals.emergencyIsDetectedGoal, fullContext, None)

    assert assertPlan(plan, [
        mpers.tasks.notifyCentralByInternetTask,
        mpers.tasks.acceptEmergencyTask
    ])
def test_ContextSet4_medicalCareReachesGoal(mpers):
    fullContext = [
        mpers.contexts.c1, mpers.contexts.c2, mpers.contexts.c3,
        mpers.contexts.c6, mpers.contexts.c7
    ]

    plan = PragmaticPlanning().isAchievablePlan(
        mpers.goals.medicalCareReachesGoal, fullContext, None)

    assert assertPlan(plan, [mpers.tasks.ambulanceDispatchDelegationTask])
def test_ContextSet4_isNotifiedAboutEmergencyGoal(mpers):
    fullContext = [
        mpers.contexts.c1, mpers.contexts.c2, mpers.contexts.c3,
        mpers.contexts.c6, mpers.contexts.c7
    ]

    plan = PragmaticPlanning().isAchievablePlan(
        mpers.goals.isNotifiedAboutEmergencyGoal, fullContext, None)

    assert assertPlan(plan, [mpers.tasks.notifyByLightAlertTask])
def test_shouldBeAchievable():
    root = Goal(Decomposition.AND, "root")

    context = Context("c1")
    current = []
    current.append(context)

    task1 = Task("t1")
    task2 = Task("t2")

    task1.addApplicableContext(context)

    root.addDependency(task1)
    root.addDependency(task2)

    plan = PragmaticPlanning().isAchievable(root, current, None)
    assert plan

    assert task2 in plan.getTasks()
def test_OnlyBaselineDefined():
    task = Task("T1")
    baseline = Context(None)
    fullContext = []

    fullContext.append(baseline)

    task.setProvidedQuality(baseline, MpersMetrics.METERS, 50.0)

    assert 50.0 == PragmaticPlanning().myProvidedQuality(
        task, MpersMetrics.METERS, fullContext)
def test_ContextSet3_centralReceivesInfoGoal(mpers):
    fullContext = [mpers.contexts.c4, mpers.contexts.c8, mpers.contexts.c11]

    plan = PragmaticPlanning().isAchievablePlan(
        mpers.goals.centralReceivesInfoGoal, fullContext, None)

    assert assertPlan(plan, [
        mpers.tasks.considerLastKnownLocationTask,
        mpers.tasks.accessDataFromDatabaseTask,
        mpers.tasks.sendInfoByInternetTask
    ])
def text_shouldProvideMetricForBaseline():
    task = Task("t1")

    current = Context("C1")
    fullContext = []
    fullContext.append(current)

    task.setProvidedQuality(None, MpersMetrics.METERS, 30.0)

    assert 30.0 == PragmaticPlanning().myProvidedQuality(
        task, MpersMetrics.METERS, fullContext)
Example #26
0
def test_getApplicableQC():
    goal = Pragmatic(Decomposition.AND, "Root")

    task = Task("T1")
    context = Context("C1")
    anotherContext = Context("C2")

    fullContext = []

    qc = QualityConstraint(context, CommonMetrics.SECONDS, 15,
                           Comparison.LESS_OR_EQUAL_TO)
    stricter = QualityConstraint(anotherContext, CommonMetrics.SECONDS, 10,
                                 Comparison.LESS_OR_EQUAL_TO)

    task.setProvidedQuality(context, CommonMetrics.SECONDS, 13)

    goal.addDependency(task)
    goal.addApplicableContext(context)
    goal.interp.addQualityConstraint(qc)
    goal.interp.addQualityConstraint(stricter)

    fullContext.append(context)

    assert stricter not in goal.interp.getQualityConstraints(fullContext)

    plan = PragmaticPlanning().isAchievable(goal, fullContext, goal.interp)
    assert len(plan.getTasks()) == 1

    fullContext.append(anotherContext)
    assert qc in goal.interp.getQualityConstraints(fullContext)

    assert stricter in goal.interp.getQualityConstraints(fullContext)

    assert PragmaticPlanning().isAchievable(goal, fullContext,
                                            goal.interp) is None

    fullContext.remove(context)

    assert qc not in goal.interp.getQualityConstraints(fullContext)

    assert stricter in goal.interp.getQualityConstraints(fullContext)
def test_shouldProvideCorrectValueForMetric():
    task = Task("T1")
    currentContext = Context("C1")
    fullContext = []

    fullContext.append(currentContext)

    task.setProvidedQuality(currentContext, MpersMetrics.METERS, 30)

    assert 30 == PragmaticPlanning().myProvidedQuality(task,
                                                       MpersMetrics.METERS,
                                                       fullContext)
def metricNotFound():
    task = Task("T1")
    currentContext = Context("C1")
    fullContext = []

    fullContext.append(currentContext)

    task.setProvidedQuality(currentContext, MpersMetrics.METERS, 30.0)

    result = PragmaticPlanning().myProvidedQuality(task, MpersMetrics.SECONDS,
                                                   fullContext)
    assert result is None
Example #29
0
def test_EmergencyIsDetected(mpers):
    fullcontext = [
        mpers.contexts.c1, mpers.contexts.c2, mpers.contexts.c3,
        mpers.contexts.c4, mpers.contexts.c8
    ]
    plan = PragmaticPlanning().isAchievablePlan(
        mpers.goals.emergencyIsDetectedGoal, fullcontext, None)

    assert True is assertPlan(plan, [
        mpers.tasks.notifyCentralBySMSTask,
        mpers.tasks.confirmEmergencyByCallTask
    ])
Example #30
0
def test_aGoalWithATaskMayBeAchievable():
    goal = Goal(Decomposition.AND, "Root")

    task = Task("T1")

    current = Context("C1")
    fullContext = []
    fullContext.append(current)

    qc = QualityConstraint(current, CommonMetrics.SECONDS, 15,
                           Comparison.LESS_OR_EQUAL_TO)
    interp = Interpretation()
    interp.addQualityConstraint(qc)

    task.addApplicableContext(current)
    task.setProvidedQuality(current, CommonMetrics.SECONDS, 13)

    goal.addDependency(task)
    goal.addApplicableContext(current)

    plan = PragmaticPlanning().isAchievable(goal, fullContext, interp)
    assert len(plan.getTasks()) == 1