示例#1
0
def test_awl_needs_final_solver():
    input_share = {
        "husband": "1/4",
        "daughter_x2": "2/3",
        "mother": "1/6",
        "father_of_father": "1/6",
        "brother": "U",
    }

    actual_output = calculate_intermittent_asl(input_share)
    assert need_final_solver(actual_output) is True
示例#2
0
def test_father_asaba():
    input_share = {"daughter": "1/2", "father": "1/6 + U"}
    expected_output = {
        "inheritance_pool": {
            "daughter": "pool_1",
            "father": "pool_2",
            "remainder": "pool_3",
            "total_shares": "pool_4",
        },
        "share_pool": {"pool_1": 1, "pool_2": 1, "pool_3": 0, "pool_4": 2},
    }
    actual_output = calculate_intermittent_asl(input_share)
    assert need_final_solver(actual_output) is False
    assert actual_output == expected_output
示例#3
0
def test_regular_shares():
    input_share = {"husband": "1/4", "daughter": "1/2"}
    expected_output = {
        "inheritance_pool": {
            "husband": "pool_1",
            "daughter": "pool_2",
            "remainder": "pool_3",
            "total_shares": "pool_4",
        },
        "share_pool": {"pool_1": 1, "pool_2": 2, "pool_3": 1, "pool_4": 4},
    }
    actual_output = calculate_intermittent_asl(input_share)
    assert need_final_solver(actual_output) is True
    assert actual_output == expected_output
示例#4
0
def test_regular_asaba_shares():
    input_share = {"daughter": "U", "father": "1/6", "son": "U"}
    expected_output = {
        "inheritance_pool": {
            "father": "pool_1",
            "son": "pool_2",
            "daughter": "pool_2",
            "remainder": "pool_3",
            "total_shares": "pool_4",
        },
        "share_pool": {"pool_1": 1, "pool_2": 5, "pool_3": 0, "pool_4": 6},
    }
    actual_output = calculate_intermittent_asl(input_share)
    assert need_final_solver(actual_output) is True
    assert actual_output == expected_output
示例#5
0
def test_maternal_grandmother_shares():
    input_share = {
        "maternal_halfbrother": "share 1/3",
        "maternal_halfsister": "share 1/3",
        "grandmother_mother": "share 1/6",
        "grandmother_father": "share 1/6",
        "son_of_son": "U",
    }
    expected_output = {
        "inheritance_pool": {
            "maternal_halfbrother": "pool_1",
            "maternal_halfsister": "pool_1",
            "grandmother_mother": "pool_2",
            "grandmother_father": "pool_2",
            "son_of_son": "pool_3",
            "remainder": "pool_4",
            "total_shares": "pool_5",
        },
        "share_pool": {"pool_1": 2, "pool_2": 1, "pool_3": 3, "pool_4": 0, "pool_5": 6},
    }
    actual_output = calculate_intermittent_asl(input_share)
    assert need_final_solver(actual_output) is True
    assert actual_output == expected_output
示例#6
0
def generate_problems():
    problem_specs = request.json

    if int(problem_specs["n_types"]) < 1:
        abort(
            400,
            "The number of inheritors in a problem should be greater than or equal to 1",
        )

    if not (set(problem_specs["must_haves"]) - set(problem_specs["not_haves"])
            or set(problem_specs["not_haves"]) -
            set(problem_specs["must_haves"])):
        abort(
            400,
            "An inheritor cannot be in both the must have and ignore list at the same time",
        )

    if int(problem_specs["n_types"]) < len(problem_specs["must_haves"]):
        abort(
            400,
            "The total number of inheritors in the case should be greater than the number of inheritors who must be "
            "included",
        )

    if len(set(CASE_GEN.inheritors) - set(problem_specs["not_haves"])) == 0:
        abort(
            400,
            "Cannot generate cases where all inheritors have been asked to be excluded",
        )

    cases = generate_problems_lst(
        inheritors=CASE_GEN.inheritors,
        must_haves=problem_specs["must_haves"],
        not_haves=problem_specs["not_haves"],
        n_types=int(problem_specs["n_types"]),
        grand_father_and_siblings=bool(
            problem_specs.get("grand_father_and_siblings", "False")),
    )

    ret = []
    for case in cases:
        case_obj = {}
        case_obj["problem"] = copy.deepcopy(case)
        basic_shares_soln = solve(
            case=case,
            descendants=CASE_GEN.descendants,
            mahjoob=CASE_GEN.mahjoob,
            rank=CASE_GEN.rank,
            taseeb=CASE_GEN.taseeb,
        )
        case_obj["basic_shares"] = basic_shares_soln

        intermediate_shares_soln = calculate_intermittent_asl(case=case)
        case_obj["intermediate_shares"] = intermediate_shares_soln

        if need_final_solver(intermediate_shares_soln):
            case_obj["final_shares"] = calculate_asl(
                full_solver(copy.deepcopy(basic_shares_soln)))
        ret.append(case_obj)

    return json.dumps(ret)
示例#7
0
    basic_shares_soln = solve(
        case=case,
        descendants=CASE_GEN.descendants,
        mahjoob=CASE_GEN.mahjoob,
        rank=CASE_GEN.rank,
        taseeb=CASE_GEN.taseeb,
    )

    intermediate_shares_soln = calculate_intermittent_asl(case=case)

    solved_case = {
        "basic_shares": basic_shares_soln,
        "intermediate_shares": intermediate_shares_soln,
    }
    if need_final_solver(intermediate_shares_soln):
        solved_case["final_shares"] = calculate_asl(
            full_solver(copy.deepcopy(basic_shares_soln)))

    return solved_case


@app.route("/generate_problems", methods=["POST"])
def generate_problems():
    problem_specs = request.json

    if int(problem_specs["n_types"]) < 1:
        abort(
            400,
            "The number of inheritors in a problem should be greater than or equal to 1",
        )