예제 #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()
예제 #2
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
예제 #3
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())
예제 #4
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
예제 #5
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
예제 #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
예제 #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
예제 #8
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])
예제 #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)
예제 #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
예제 #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)
예제 #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
예제 #13
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
예제 #14
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
예제 #15
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])
예제 #16
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])
예제 #17
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
    ])
예제 #18
0
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()
예제 #19
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
예제 #20
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)
예제 #21
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)
예제 #22
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
    ])
예제 #23
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
예제 #24
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)
예제 #25
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])
예제 #26
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
예제 #27
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().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 == "sendInfoBySMS":
            found = 1
        if task.identifier == "confirmEmergencyByCall":
            found = 1

        assert found == 0
예제 #28
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
    ])
예제 #29
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
예제 #30
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
    ])