Ejemplo n.º 1
0
def test_shouldBeUnachievable():

    root = Goal(Decomposition.AND)

    context1 = Context("c1")
    context2 = Context("c2")

    current = []
    current.append(context1)

    task1 = Task()

    task2 = Task()

    task1.addApplicableContext(context2)
    task2.addApplicableContext(context2)

    root.addDependency(task1)
    root.addDependency(task2)

    deps = []
    deps.append(task1)
    deps.append(task2)

    plan = root.isAchievable(current, None)

    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_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.º 4
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.º 5
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 = root.isAchievable(current, None)
    assert plan

    assert task2 in plan.getTasks()