Ejemplo n.º 1
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())
Ejemplo n.º 2
0
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
Ejemplo n.º 3
0
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])
Ejemplo n.º 4
0
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
Ejemplo n.º 5
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().isAchievable(mpers.rootGoal, fullContext, None)

    assert tasks is not None

    for task in tasks.getTasks():
        found = 0

        if task.identifier == "notifyCentralBySMS":
            found = 1
        if task.identifier == "confirmEmergencyByCall":
            found = 1
        if task.identifier == "notifyBySoundAlert":
            found = 1
        if task.identifier == "sendInfoBySMS":
            found = 1
        if task.identifier == "identifyLocationByVoiceCall":
            found = 1
        if task.identifier == "accessLocationFromTriangulation":
            found = 1

        assert found == 0
Ejemplo n.º 6
0
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
Ejemplo n.º 7
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
Ejemplo n.º 8
0
def test_aGoalOrDecomposedWithTwoTasksMayNotBeAchievable():
    goal = Goal(Decomposition.OR, "Root")

    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, 17)

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

    goal.addApplicableContext(current)

    interp = Interpretation()
    interp.addQualityConstraint(qc)

    plan = PragmaticPlanning().isAchievable(goal, fullContext, interp)
    assert goal.decomposition is Decomposition.OR
    assert plan is None
Ejemplo n.º 9
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)
Ejemplo n.º 10
0
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
Ejemplo n.º 11
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)
Ejemplo n.º 12
0
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
Ejemplo n.º 13
0
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
Ejemplo n.º 14
0
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])
Ejemplo n.º 15
0
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])
Ejemplo n.º 16
0
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
    ])
Ejemplo n.º 17
0
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
Ejemplo n.º 18
0
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)
Ejemplo n.º 19
0
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)
Ejemplo n.º 20
0
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
    ])
Ejemplo n.º 21
0
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
Ejemplo n.º 22
0
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)
Ejemplo n.º 23
0
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 = PragmaticPlanning().isAchievable(mpers.rootGoal, fullContext, None)
    assert plan is not None

    assert False is assertPlan(
        plan,
        [mpers.tasks.accessLocationFromGPSTask, mpers.tasks.centralCallTask])
Ejemplo n.º 24
0
def test_aNonApplicableRootGoalIsNotAchievable():
    goal = Goal(Decomposition.AND, "G1")
    current = Context("C1")
    fullContext = []

    qc = QualityConstraint(current, CommonMetrics.SECONDS,
                           15, Comparison.LESS_OR_EQUAL_TO)
    goal.addApplicableContext(Context("C2"))

    interp = Interpretation()
    interp.addQualityConstraint(qc)

    assert PragmaticPlanning().isAchievable(goal, fullContext, interp) is None
Ejemplo n.º 25
0
def test_ContextSet4_emergencyIsDetectedGoal(mpers):
    fullContext = [
        mpers.contexts.c1, mpers.contexts.c2, mpers.contexts.c3,
        mpers.contexts.c6, mpers.contexts.c7
    ]

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

    assert assertPlan(plan, [
        mpers.tasks.notifyCentralBySMSTask,
        mpers.tasks.confirmEmergencyByCallTask
    ])
Ejemplo n.º 26
0
def test_ContextSet4_centralReceivesInfoGoal(mpers):
    fullContext = [
        mpers.contexts.c1, mpers.contexts.c2, mpers.contexts.c3,
        mpers.contexts.c6, mpers.contexts.c7
    ]

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

    assert assertPlan(plan, [
        mpers.tasks.accessLocationFromTriangulationTask,
        mpers.tasks.accessDataFromDatabaseTask,
        mpers.tasks.sendInfoByInternetTask
    ])
Ejemplo n.º 27
0
def test_shouldProvideSpecificContextMetric():
    task = Task("T2")
    currentContext = Context("C1")
    baseline = None
    fullContext = []

    fullContext.append(currentContext)
    fullContext.append(baseline)

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

    assert 50 == PragmaticPlanning().myProvidedQuality(task,
                                                       MpersMetrics.METERS,
                                                       fullContext)
Ejemplo n.º 28
0
def test_ContextSet1_centralReceivesInfoGoal(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 = PragmaticPlanning().isAchievablePlan(
        mpers.goals.centralReceivesInfoGoal, fullContext, None)

    assert assertPlan(plan, [
        mpers.tasks.getInfoFromResponsibleTask,
        mpers.tasks.sendInfoByInternetTask
    ])
Ejemplo n.º 29
0
def aTaskMayNotBeAchievable():
    task = Task("T1")

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

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

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

    interp = Interpretation()
    interp.addQualityConstraint(qc)

    assert PragmaticPlanning().isAchievable(task, fullContext, interp) is None
Ejemplo n.º 30
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().isAchievable(mpers.rootGoal, fullContext, None)

    assert tasks is not None

    for task in tasks.getTasks():
        found = 0

        if task.identifier == "acceptEmergency":
            found = 1

        assert found == 0