示例#1
0
def test_ranking_problem_add_item_incorrect():
    unexpected_values = ("gamma", )

    rp = RankingProblem()
    rp.add_item("beta")

    assert (rp._items != unexpected_values)
示例#2
0
def test_ranking_problem_add_item_correct():
    expected_values = ("test", )

    rp = RankingProblem()
    rp.add_item("test")

    assert (rp._items == expected_values)
示例#3
0
def test_item_variables_after_set_items():
    test_items = ["Cat", "Dog", "Mouse"]
    r = RankingProblem()
    r.set_items(test_items)

    assert (r._variables["Cat"] == [0, 1, 2])
    assert (r._variables["Dog"] == [0, 1, 2])
    assert (r._variables["Mouse"] == [0, 1, 2])
示例#4
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)
示例#5
0
def test_item_variable_names_after_set_items():
    test_items = ["Cat", "Dog", "Mouse"]
    r = RankingProblem()
    r.set_items(test_items)

    allowed_variable_keys = test_items + [FIRST, LAST, NEARBY]

    for key in r._variables:
        assert (key in allowed_variable_keys)
示例#6
0
def test_can_set_items():
    input_items = ["Cat", "Dog", "Mouse"]
    expected_items = (
        "Cat",
        "Dog",
        "Mouse",
    )

    r = RankingProblem()
    r.set_items(input_items)

    assert (expected_items == r._items)
示例#7
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)
示例#8
0
def test_items_are_a_copy():
    input_items = ["Cat", "Dog", "Mouse"]
    expected_items = (
        "Cat",
        "Dog",
        "Mouse",
    )

    r = RankingProblem()
    r.set_items(input_items)
    input_items.append("Monkey")

    assert (not tuple(input_items) == r._items)
    assert (expected_items == r._items)
示例#9
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()
def test_ranking_problem_remove_item_no_duplicates():
    rp = RankingProblem()
    rp.set_items(["alpha", "gamma"])
    rp.remove_item("alpha")
    rp.remove_item("gamma")
    rp.remove_item("alpha")

    assert(rp._items == tuple())
示例#11
0
def test_not_equal_fails_unknown_item():
    r = RankingProblem()
    r.set_items(["Dog", "Cat"])

    with pytest.raises(ValueError, match="Kat not in Items"):
        r.not_equal("Dog", "Kat")

    with pytest.raises(ValueError, match="Hound not in Items"):
        r.not_equal("Hound", "Cat")
def test_ranking_problem_remove_last_constraint_removes_constraint():
    rank_prob = RankingProblem()
    rank_prob.set_items(["Huey", "Dewey", "Louie"]).\
        is_before("Louie", "Dewey")

    number_of_constraints = rank_prob.number_of_constraints()
    rank_prob.remove_last_constraint()

    assert (number_of_constraints == rank_prob.number_of_constraints() + 1)
def test_can_call_item_links():
    r = RankingProblem()
    try:
        r.item_links
    except NameError:
        pytest.fail("Couldn't call item_links on RankingProblem")
    else:
        pass
示例#14
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()
示例#15
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)
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)
示例#17
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)
示例#18
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])
示例#19
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)
示例#20
0
def test_ranking_problem_set_items_bracket_notation():

    test_items = [
        "[Boil water in the kettle]", "[Get a cup from the cupboard]",
        "[Pour boiled water into cup]", "[Put tea bag into cup]", "[Drink tea]"
    ]

    expected_keys = [
        "Boil_water_in_the_kettle", "Get_a_cup_from_the_cupboard",
        "Pour_boiled_water_into_cup", "Put_tea_bag_into_cup", "Drink_tea"
    ]

    r = RankingProblem()
    r.set_items(test_items)

    allowed_variable_keys = expected_keys + [FIRST, LAST, NEARBY]

    for key in r._variables:
        assert (key in allowed_variable_keys)
示例#21
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")
示例#22
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)
示例#23
0
def test_is_before_constraint_set():
    r = RankingProblem()
    r.set_items(["Dog", "Cat"])
    r.is_after("Dog", "Cat")

    assert (r._constraints[0].items == ("Dog", "Cat"))
    assert (str(r._constraints[0]) == "Dog > Cat")
示例#24
0
def test_not_last_constraint_set():
    r = RankingProblem()
    r.set_items(["Dog"])
    r.not_last("Dog")

    assert (r._constraints[1][1] == ("Dog", LAST))
    assert (r._constraints[1][0]._func.__name__ == "not_equal")
示例#25
0
def test_not_last_constraint_set():
    r = RankingProblem()
    r.set_items(["Dog"])
    r.not_first("Dog")

    assert (r._constraints[0].items == ("Dog", "FIRST"))
    assert (str(r._constraints[0]) == "Dog != FIRST")
示例#26
0
def test_cannot_change_items():
    test_items = ["Cat", "Dog", "Mouse"]
    r = RankingProblem()
    r.set_items(test_items)

    with pytest.raises(ValueError, match="Items Already Set"):
        r.set_items(["Foo", "Bar"])
示例#27
0
def test_is_before_constraint_set():
    r = RankingProblem()
    r.set_items(["Dog", "Cat"])
    r.is_before("Dog", "Cat")

    assert (r._constraints[1][1] == ("Dog", "Cat"))
    assert (r._constraints[1][0]._func.__name__ == "is_before")
示例#28
0
def test_not_equal_constraint_set():
    r = RankingProblem()
    r.set_items(["Dog", "Cat"])
    r.not_equal("Dog", "Cat")

    assert (r._constraints[0].items == ("Dog", "Cat"))
    assert (str(r._constraints[0]) == "Dog != Cat")
示例#29
0
def test_ranking_problem_add_item_with_bracket_notation():
    expected_values = ("alpha", "beta", "gamma", "delta_force")

    rp = RankingProblem()
    rp.set_items(["alpha", "beta", "gamma"])
    rp.add_item("[delta force]")

    assert (rp._items == expected_values)
示例#30
0
def test_ranking_problem_add_item_after_set_list():
    expected_values = ("alpha", "beta", "gamma", "delta")

    rp = RankingProblem()
    rp.set_items(["alpha", "beta", "gamma"])
    rp.add_item("delta")

    assert (rp._items == expected_values)