Exemple #1
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
Exemple #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())
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
Exemple #4
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
Exemple #5
0
def test_shouldAddSeveralContextsAtOnce():
    context1 = Context("C1")
    context2 = Context("C2")

    task = Task("T1")

    assert task.applicableContext is None

    task.addApplicableContext([context1, context2])

    assert 2 == len(task.applicableContext)
Exemple #6
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
Exemple #7
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)
Exemple #8
0
def test_aTaskShouldBeAchievable():
    task = Task("T1")

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

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

    task.addApplicableContext(currentContext)
    task.setProvidedQuality(currentContext, CommonMetrics.SECONDS, 12)

    interp = Interpretation()
    interp.addQualityConstraint(qc)

    assert task in PragmaticPlanning().isAchievableTask(
        task, fullContext, interp).getTasks()
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()
Exemple #10
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
def test_shouldGetApplicableDependencies():
    root = Goal(Decomposition.AND, "root")

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

    task = Task("t1")
    goal = Goal(Decomposition.AND, "g1")
    delegation = Delegation("D1")

    task.addApplicableContext(context)

    root.addDependency(task)
    root.addDependency(goal)
    root.addDependency(delegation)

    deps = []
    deps.append(task)

    assert 1 == len(deps)
    assert task in deps