示例#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())
示例#2
0
def test_shouldThereBeMoreThanOneApplicableQCreturnTheStricterOne():
    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)

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

    assert stricter == qc.stricterQC(stricter)

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

    fullContext.append(anotherContext)
    assert stricter in \
        goal.interp.getQualityConstraints(fullContext)
示例#3
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
示例#4
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)
示例#5
0
task1 = Task("task1")
task2 = Task("task2")
task3 = Task("task3")
task4 = Task("task4")

task2.addApplicableContext(c2)

task1.setProvidedQuality(None, MpersMetrics.SECONDS, 80)
task2.setProvidedQuality(None, MpersMetrics.SECONDS, 60)
task3.setProvidedQuality(None, MpersMetrics.SECONDS, 100)
task4.setProvidedQuality(None, MpersMetrics.SECONDS, 200)

goal = Pragmatic(Decomposition.OR, "g1")

goal.addDependency(task1)
goal.addDependency(task2)
goal.addDependency(task3)
goal.addDependency(task4)

qc1 = QualityConstraint(None, MpersMetrics.SECONDS, 180, Comparison.LESS_THAN)
qc2 = QualityConstraint(c2, MpersMetrics.SECONDS, 90, Comparison.LESS_THAN)
goal.interp.addQualityConstraint(qc1)
goal.interp.addQualityConstraint(qc2)


def test_C1():
    fullContext = [c1, c2, c3, c4]

    plan = Planning().isAchievable(goal, fullContext, goal.interp)