Ejemplo n.º 1
0
def test_aGoalOrDecomposedWithTwoTasksMayNotBeAchievable():
    goal = Goal(Decomposition.OR)

    task1 = Task()
    task2 = Task()
    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.setIdentifier("Root")
    goal.addApplicableContext(current)

    interp = Interpretation()
    interp.addQualityConstraint(qc)

    plan = goal.isAchievable(fullContext, interp)
    assert goal.decomposition is Decomposition.OR
    assert plan is None
Ejemplo n.º 2
0
def test_aGoalAndDecomposedWithTwoTasksMayBeAchievable():
    goal = Goal(Decomposition.AND)

    task1 = Task()
    task2 = Task()

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

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

    interp = Interpretation()
    interp.addQualityConstraint(qc)

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

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

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

    goal.setIdentifier("Root")
    goal.addApplicableContext(current)

    plan = goal.isAchievable(fullContext, interp)
    assert 2 == len(plan.getTasks())
Ejemplo n.º 3
0
def test_aNonApplicableRootGoalIsNotAchievable():
    goal = Goal(Decomposition.AND)
    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 goal.isAchievable(fullContext, interp) is None
Ejemplo n.º 4
0
def test_shouldBeApplicable():
    goal = Goal(Decomposition.AND)
    task = Task()
    delegation = Delegation()

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

    fullContext.append(contextCurrent)

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

    assert True is goal.isApplicable(fullContext)
    assert True is task.isApplicable(fullContext)
    assert True is delegation.isApplicable(fullContext)
Ejemplo n.º 5
0
def test_shouldBeNotApplicable():
    goal = Goal(Decomposition.AND)
    task = Task()
    delegation = Delegation()

    context = Context("C1")

    task.addApplicableContext(context)

    goal.addApplicableContext(context)

    delegation.addApplicableContext(context)

    wrongContext = Context("C2")
    fullContext = []
    fullContext.append(wrongContext)

    assert False is goal.isApplicable(fullContext)
    assert False is task.isApplicable(fullContext)
    assert False is delegation.isApplicable(fullContext)