Exemplo n.º 1
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)
Exemplo n.º 2
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)
def test_ranking_problem_least_most_common_variable():
    expected_results = ("Red", "Blue")

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

    result = r.least_most_common_variable()

    try:
        assert (result == expected_results)
    except AssertionError:
        pytest.fail(
            "Failed to get expected variable_constraints_count from RankingProblem"
        )
Exemplo n.º 4
0
def test_solve_is_after_fully_specified_incorrect():
    unexpected_results = get_all_combinations(
        ["Dog", "Cat", "Mouse"],
        include_passed_values=False
    )

    r = RankingProblem()
    r.set_items(["Dog", "Cat", "Mouse"])
    r.is_after("Cat", "Dog")
    r.is_after("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_least_most_common_variable_returns_min_max():
    expected_results = ("Yellow", "Green")

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

    result = r.least_most_common_variable

    try:
        assert (result == expected_results)
    except AssertionError:
        pytest.fail(
            "Failed to get min and max counts items in variable_constraints_count from RankingProblem"
        )
Exemplo n.º 6
0
def test_solve_is_after_partially_specified():

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

    r = RankingProblem()
    r.set_items(["Dog", "Cat", "Mouse"])
    r.is_after("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])
def test_item_variables_after_remove_item():
    test_item_a = "a"
    test_item_b = "b"
    test_item_c = "c"

    r = RankingProblem()
    r.set_items([test_item_a, test_item_b, test_item_c])
    assert(r._variables[test_item_a] == [0, 1, 2])
    assert(r._variables[test_item_b] == [0, 1, 2])
    assert(r._variables[test_item_c] == [0, 1, 2])

    r.remove_item(test_item_a)
    assert(r._variables[test_item_b] == [0, 1])
    assert(r._variables[test_item_c] == [0, 1])

    r.remove_item(test_item_b)
    assert(r._variables[test_item_c] == [0])
def test_last_variable_after_set_items():
    test_item_a = "a"
    test_item_b = "b"
    test_item_c = "c"

    r = RankingProblem()
    r.set_items([test_item_a, test_item_b, test_item_c])
    assert(r._variables[LAST] == [2])
    assert (r._variables[FIRST] == [0])

    r.remove_item(test_item_a)
    assert(r._variables[LAST] == [1])
    assert (r._variables[FIRST] == [0])

    r.remove_item(test_item_b)
    assert(r._variables[LAST] == [0])
    assert(r._variables[FIRST] == [0])
Exemplo n.º 9
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)
def test_item_links():
    expected_results = {
        "Blue": ["Green"],
        "Orange": ["Green"],
        "Red": ["Green", "Yellow"],
        "Yellow": ["Green", "Red"],
        "Green": ["Blue", "Orange", "Red", "Yellow"]
    }

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

    result = r.item_links

    assert (expected_results == result)
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.º 12
0
def test_number_of_items_correct():
    test_items = ["Cat", "Dog", "Mouse"]
    r = RankingProblem()
    r.set_items(test_items)

    assert (r._number_of_items == len(test_items))
def test_ranking_problem_check_item_present_exception_on_invalid():
    r = RankingProblem()
    r.set_items(["Red", "Green"])

    with pytest.raises(ValueError, match="Blue not in Items"):
        assert (r.check_item_present("Blue"))
def test_can_call_ranking_problem_check_item_present():
    r = RankingProblem()
    r.set_items(["Red"])
    r.check_item_present("Red")
def test_last_variable_not_included_after_set_items():
    test_items = ["Cat", "Dog", "Mouse", "LAST"]
    r = RankingProblem()
    r.set_items(test_items)
    assert ("LAST" not in r._variables)
Exemplo n.º 16
0
def test_can_call_solve():
    r = RankingProblem()
    r.set_items(["Dog", "Cat", "Mouse"])
    r.is_after("Cat", "Dog")
    r.solve()
Exemplo n.º 17
0
def test_can_call_not_directly_above_or_below():
    r = RankingProblem()
    r.set_items(["Dog", "Cat"])
    r.not_directly_before_or_after("Dog", "Cat")
Exemplo n.º 18
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)
def test_ranking_problem_check_item_present_returns_bool():
    r = RankingProblem()
    r.set_items(["Red", "Green"])

    assert (isinstance(r.check_item_present("Red"), bool))
    assert (isinstance(r.check_item_present("Green"), bool))
Exemplo n.º 21
0
def test_can_call_not_equal():
    r = RankingProblem()
    r.set_items(["Dog", "Cat"])
    r.not_equal("Dog", "Cat")
Exemplo n.º 22
0
def test_can_call_is_before():
    r = RankingProblem()
    r.set_items(["Dog", "Cat"])
    r.is_before("Cat", "Dog")
Exemplo n.º 23
0
def test_not_directly_above_or_below_fails_on_unknown_item():
    r = RankingProblem()
    r.set_items(["Dog", "Cat"])
    with pytest.raises(ValueError, match="Kat not in Items"):
        r.not_directly_before_or_after("Dog", "Kat")
Exemplo n.º 24
0
def test_last_varible_after_set_items():
    test_items = ["Cat", "Dog", "Mouse"]
    r = RankingProblem()
    r.set_items(test_items)
    assert (r._variables[LAST] == [2])
Exemplo n.º 25
0
def test_is_before_fails_on_unknown_item():
    r = RankingProblem()
    r.set_items(["Dog"])
    with pytest.raises(ValueError, match="Cat not in Items"):
        r.is_after("Cat", "Dog")
Exemplo n.º 26
0
def test_can_call_not_first():
    r = RankingProblem()
    r.set_items(["Dog"])
    r.not_first("Dog")
def test_can_call_ranking_problem_not_directly_before_or_after():
    r = RankingProblem()
    r.set_items(["Read", "Blue", "Green", "Yellow"])
    r.not_directly_before_or_after("Blue", "Green")
def test_ranking_problem_check_item_present_correct():
    r = RankingProblem()
    r.set_items(["Red", "Green"])

    assert (r.check_item_present("Red"))
    assert (r.check_item_present("Green"))