Exemplo n.º 1
0
def test_solve_is_after_unsolvable():
    r = RankingProblem()
    r.set_items(["Dog", "Cat"])
    r.is_after("Cat", "Dog")
    r.is_after("Dog", "Cat")

    with pytest.raises(UnsolvableModelError):
        r.solve()
Exemplo n.º 2
0
def test_solve_is_before_unsolvable():
    unsolvable_results = []

    r = RankingProblem()
    r.set_items(["Dog", "Cat"])
    r.is_before("Cat", "Dog")
    r.is_before("Dog", "Cat")

    with pytest.raises(UnsolvableModelError):
        r.solve()
def test_ranking_problem_solve_not_equal_correct():

    expected_results = [
        (
            "Blue",
            "Green",
            "Red",
        ),
        (
            "Blue",
            "Red",
            "Green",
        ),
        (
            "Red",
            "Blue",
            "Green",
        ),
        (
            'Red',
            'Green',
            'Blue',
        ),
    ]

    r = RankingProblem()
    r.set_items(["Red", "Green", "Blue"])
    # given there's a constraints that .items must be different
    # will evaluate against FIRST
    r.not_equal("Green", FIRST)

    actual_results = r.solve()

    assert (actual_results == expected_results)
Exemplo n.º 4
0
def test_solve_is_before_partially_specified():

    expected_results = [
        (
            "Cat",
            "Dog",
            "Mouse",
        ),
        (
            "Cat",
            "Mouse",
            "Dog",
        ),
        (
            "Mouse",
            "Cat",
            "Dog",
        ),
    ]

    r = RankingProblem()
    r.set_items(["Dog", "Cat", "Mouse"])
    r.is_before("Cat", "Dog")
    actual_results = r.solve()

    assert (len(actual_results) == 3)
    assert (actual_results[0] == expected_results[0])
    assert (actual_results[1] == expected_results[1])
    assert (actual_results[2] == expected_results[2])
Exemplo n.º 5
0
def test_can_solve_when_similar_steps():
    """
    New Email before Send Email
    Attach Image after Create New Email
    Send Email after Attach Image
    """
    expected_results = [
        ("New_Email", "Attach_Image", "Send_Email"),
    ]

    r = RankingProblem()

    for step_descriptions in [
        "New Email", "Send Email",
        "Attach Image", "Create New Email"
    ]:
        r.add_item(step_descriptions)

    r.is_before("New_Email", "Send_Email").\
        is_after("Attach_Image", "New_Email"). \
        is_after("Send_Email", "Attach_Image")

    actual_results = r.solve()

    assert (actual_results == expected_results)
Exemplo n.º 6
0
def test_solve_returns_list():
    expected_results = get_all_combinations(["Dog", "Cat", "Mouse"])

    r = RankingProblem()
    r.set_items(["Dog", "Cat", "Mouse"])
    actual_results = r.solve()

    assert(actual_results == expected_results)
Exemplo n.º 7
0
def test_ranking_problem_solve_not_last_correct():
    r = RankingProblem()
    r.set_items({"Blue", "Red", "Green", "Yellow", "Blue", "Purple"})
    r.not_last("Purple")

    actual_results = r.solve()

    for actual_result in actual_results:
        assert (actual_result[-1] != "Purple")
Exemplo n.º 8
0
def test_solve_is_after_unsolvable():
    unsolvable_results = []

    r = RankingProblem()
    r.set_items(["Dog", "Cat"])
    r.is_after("Cat", "Dog")
    r.is_after("Dog", "Cat")

    actual_results = r.solve()
    assert(actual_results == unsolvable_results)
Exemplo n.º 9
0
def test_solve_is_after_fully_specified_correct():
    expected_results = [("Dog", "Cat", "Mouse",)]

    r = RankingProblem()
    r.set_items(["Dog", "Cat", "Mouse"])
    r.is_after("Cat", "Dog")
    r.is_after("Mouse", "Cat")

    actual_result = r.solve()
    assert(actual_result == expected_results)
def test_ranking_problem_is_last_correct():
    rp = RankingProblem()
    expected_results = [
        ("b", "c", "a"),
        ("c", "b", "a"),
    ]
    rp.set_items(["a", "c", "b"])

    rp.is_last("a")

    actual_results = rp.solve()

    assert (actual_results == expected_results)
Exemplo n.º 11
0
def test_solve_is_before_fully_specified_incorrect():
    unexpected_results = get_all_combinations(["Mouse", "Cat", "Dog"],
                                              include_passed_values=False)

    r = RankingProblem()
    r.set_items(["Dog", "Cat", "Mouse"])
    r.is_before("Cat", "Dog")
    r.is_before("Mouse", "Cat")

    actual_results = r.solve()

    for actual_result in actual_results:
        for unexpected_result in unexpected_results:
            assert (unexpected_result != actual_result)
Exemplo n.º 12
0
def test_ranking_problem_solve_not_last_in_pair_correct():
    expected_results = [
        (
            "Red",
            "Blue",
        ),
    ]

    r = RankingProblem()
    r.set_items({"Blue", "Red"})
    r.not_last("Red")

    actual_results = r.solve()

    assert (actual_results == expected_results)
Exemplo n.º 13
0
def test_solve_add_item_after_specifying_constraint():
    expected_results = [
        ("Dog", "Cat", "Mouse"),
        ('Dog', 'Mouse', 'Cat'),
        ("Mouse", "Dog", "Cat"),
    ]

    r = RankingProblem()
    r.set_items(["Cat", "Dog"])
    r.is_after("Cat", "Dog")
    r.add_item("Mouse")

    actual_results = r.solve()

    assert(actual_results == expected_results)
def test_ranking_problem_is_just_after_correct():
    rp = RankingProblem()
    expected_results = [('b', 'c', 'd', 'a', 'e'), ('b', 'c', 'd', 'e', 'a'),
                        ('b', 'c', 'e', 'd', 'a'), ('b', 'd', 'a', 'c', 'e'),
                        ('b', 'd', 'a', 'e', 'c'), ('b', 'd', 'c', 'a', 'e'),
                        ('b', 'd', 'c', 'e', 'a'), ('b', 'd', 'e', 'a', 'c'),
                        ('b', 'd', 'e', 'c', 'a'), ('b', 'e', 'c', 'd', 'a'),
                        ('b', 'e', 'd', 'a', 'c'), ('b', 'e', 'd', 'c', 'a'),
                        ('c', 'b', 'd', 'a', 'e'), ('c', 'b', 'd', 'e', 'a'),
                        ('c', 'b', 'e', 'd', 'a'), ('c', 'd', 'a', 'b', 'e'),
                        ('c', 'd', 'a', 'e', 'b'), ('c', 'd', 'b', 'a', 'e'),
                        ('c', 'd', 'b', 'e', 'a'), ('c', 'd', 'e', 'a', 'b'),
                        ('c', 'd', 'e', 'b', 'a'), ('c', 'e', 'b', 'd', 'a'),
                        ('c', 'e', 'd', 'a', 'b'), ('c', 'e', 'd', 'b', 'a'),
                        ('d', 'a', 'b', 'c', 'e'), ('d', 'a', 'b', 'e', 'c'),
                        ('d', 'a', 'c', 'b', 'e'), ('d', 'a', 'c', 'e', 'b'),
                        ('d', 'a', 'e', 'b', 'c'), ('d', 'a', 'e', 'c', 'b'),
                        ('d', 'b', 'a', 'c', 'e'), ('d', 'b', 'a', 'e', 'c'),
                        ('d', 'b', 'c', 'a', 'e'), ('d', 'b', 'e', 'a', 'c'),
                        ('d', 'c', 'a', 'b', 'e'), ('d', 'c', 'a', 'e', 'b'),
                        ('d', 'c', 'b', 'a', 'e'), ('d', 'c', 'e', 'a', 'b'),
                        ('d', 'e', 'a', 'b', 'c'), ('d', 'e', 'a', 'c', 'b'),
                        ('d', 'e', 'b', 'a', 'c'), ('d', 'e', 'c', 'a', 'b'),
                        ('e', 'b', 'c', 'd', 'a'), ('e', 'b', 'd', 'a', 'c'),
                        ('e', 'b', 'd', 'c', 'a'), ('e', 'c', 'b', 'd', 'a'),
                        ('e', 'c', 'd', 'a', 'b'), ('e', 'c', 'd', 'b', 'a'),
                        ('e', 'd', 'a', 'b', 'c'), ('e', 'd', 'a', 'c', 'b'),
                        ('e', 'd', 'b', 'a', 'c'), ('e', 'd', 'b', 'c', 'a'),
                        ('e', 'd', 'c', 'a', 'b'), ('e', 'd', 'c', 'b', 'a')]

    rp.set_items(["a", "b", "c", "d", "e"])

    rp.is_just_after("a", "d")

    actual_results = rp.solve()

    assert (actual_results == expected_results)
Exemplo n.º 15
0
def test_can_call_solve():
    r = RankingProblem()
    r.set_items(["Dog", "Cat", "Mouse"])
    r.is_after("Cat", "Dog")
    r.solve()
Exemplo n.º 16
0
def test_solve_returns_sorted_list():
    r = RankingProblem()
    r.set_items(["Dog", "Cat", "Mouse"])
    r.is_after("Cat", "Dog")
    assert(isinstance(r.solve(), List))
def test_ranking_problem_not_directly_before_or_after_correct():

    expected_results = [
        (
            "Blue",
            "Red",
            "Green",
            "Yellow",
        ),
        (
            "Blue",
            "Red",
            "Yellow",
            "Green",
        ),
        (
            "Blue",
            "Yellow",
            "Green",
            "Red",
        ),
        (
            "Blue",
            "Yellow",
            "Red",
            "Green",
        ),
        ("Green", "Red", "Blue", "Yellow"),
        ("Green", "Red", "Yellow", "Blue"),
        ("Green", "Yellow", "Blue", "Red"),
        ("Green", "Yellow", "Red", "Blue"),
        (
            "Red",
            "Blue",
            "Yellow",
            "Green",
        ),
        (
            "Red",
            "Green",
            "Yellow",
            "Blue",
        ),
        (
            "Yellow",
            "Blue",
            "Red",
            "Green",
        ),
        (
            "Yellow",
            "Green",
            "Red",
            "Blue",
        ),
    ]

    r = RankingProblem()
    r.set_items(["Red", "Blue", "Green", "Yellow"])
    r.not_directly_before_or_after("Blue", "Green")

    actual_results = r.solve()

    assert (actual_results == expected_results)