def create_plan(tier, separate=False):
    plan = HealthPlan()
    plan.tier = tier
    if separate:
        plan.medical_deductible = 500
    else:
        plan.deductible = 500
    return plan
def check_tier_determination(av_array):
    test_health_plan = HealthPlan()
    test_health_plan.av = av_array[0]
    assert_almost_equal(test_health_plan.av,
                        av_array[0],
                        3,
                        "Av is not equal to correct value. Should be {0} is {1}".format(av_array[0],test_health_plan.av))
    assert test_health_plan.tier == av_array[1], "Tier does not match expected tier. Expected tier is {0} actual tier is {1}".format(av_array[0], test_health_plan.tier)
def create_plan(tier, separate=False):
    plan = HealthPlan()
    plan.tier = tier
    if separate:
        plan.medical_deductible = 500
    else:
        plan.deductible = 500
    return plan
def check_json(json_hash):
    test_health_plan = HealthPlan()
    test_health_plan.parse_JSON(json.dumps(json_hash))
    for key, value in json_hash.items():
        if isinstance(value, dict):
            for subkey, subvalue in value.items():
                check_attribute_value(test_health_plan, key + '_' + subkey, subvalue)
        else:
            check_attribute_value(test_health_plan, key, value)
def check_json(json_hash):
    test_health_plan = HealthPlan()
    test_health_plan.parse_JSON(json.dumps(json_hash))
    for key, value in json_hash.items():
        if isinstance(value, dict):
            for subkey, subvalue in value.items():
                check_attribute_value(test_health_plan, key + '_' + subkey,
                                      subvalue)
        else:
            check_attribute_value(test_health_plan, key, value)
def check_tier_determination(av_array):
    test_health_plan = HealthPlan()
    test_health_plan.av = av_array[0]
    assert_almost_equal(
        test_health_plan.av, av_array[0], 3,
        "Av is not equal to correct value. Should be {0} is {1}".format(
            av_array[0], test_health_plan.av))
    assert test_health_plan.tier == av_array[
        1], "Tier does not match expected tier. Expected tier is {0} actual tier is {1}".format(
            av_array[0], test_health_plan.tier)
def check_determine_coinsurance_expenses_integrated(test_plan_array):
    test_plan = HealthPlan()
    test_plan.coinsurance = test_plan_array[2]
    test_plan.deductible = test_plan_array[0]
    test_plan.moop = test_plan_array[1]

    calc._determine_moop(test_plan, test_plan.deductible)
    coinsurance = calc._determine_coinsurance_expenses(test_plan.deductible,
                                                       test_plan)
    assert_almost_equal(
        coinsurance, test_plan_array[3], 2,
        "Expected expenses for coinsurance are not correct, "
        "actual {0}, expected {1}".format(coinsurance, test_plan_array[3]))
def check_determine_expenses_after_moop(test_plan_array):
    test_plan = HealthPlan()
    test_plan.coinsurance = test_plan_array[2]
    test_plan.deductible = test_plan_array[0]
    test_plan.moop = test_plan_array[1]

    calc._determine_moop(test_plan, test_plan.deductible)
    calc._determine_coinsurance_expenses(test_plan.deductible, test_plan)
    after_moop_exepenses = calc._determine_expenses_after_moop()
    assert_almost_equal(
        after_moop_exepenses, test_plan_array[3], 2,
        "Expected expenses after moop are not correct, actual "
        "{0}, expected {1}".format(after_moop_exepenses, test_plan_array[3]))
def test__determine_moop_integrated():
    test_plan = HealthPlan()
    test_plan.deductible = 1000
    test_plan.coinsurance = 0.9
    test_plan.moop = 2000
    test_plan.tier = Tier.platinum

    calc._set_metal_tier(test_plan)
    calc._determine_moop(test_plan, test_plan.deductible)
    assert_almost_equal(
        calc._moop_cost_level,
        11372.76,
        0,
        ("Integrated plan moop not correct, actual {0}, " "expected {1}".format(calc._moop_cost_level, 11372.76)),
    )
def check_determine_coinsurance_expenses_integrated(test_plan_array):
    test_plan = HealthPlan()
    test_plan.coinsurance = test_plan_array[2]
    test_plan.deductible = test_plan_array[0]
    test_plan.moop = test_plan_array[1]

    calc._determine_moop(test_plan, test_plan.deductible)
    coinsurance = calc._determine_coinsurance_expenses(test_plan.deductible, test_plan)
    assert_almost_equal(
        coinsurance,
        test_plan_array[3],
        2,
        "Expected expenses for coinsurance are not correct, "
        "actual {0}, expected {1}".format(coinsurance, test_plan_array[3]),
    )
def check_determine_expenses_after_moop(test_plan_array):
    test_plan = HealthPlan()
    test_plan.coinsurance = test_plan_array[2]
    test_plan.deductible = test_plan_array[0]
    test_plan.moop = test_plan_array[1]

    calc._determine_moop(test_plan, test_plan.deductible)
    calc._determine_coinsurance_expenses(test_plan.deductible, test_plan)
    after_moop_exepenses = calc._determine_expenses_after_moop()
    assert_almost_equal(
        after_moop_exepenses,
        test_plan_array[3],
        2,
        "Expected expenses after moop are not correct, actual "
        "{0}, expected {1}".format(after_moop_exepenses, test_plan_array[3]),
    )
def test_existing_av():
    test_plan = HealthPlan()
    test_plan.deductible = 500
    test_plan.coinsurance = 0.9
    test_plan.moop = 1000
    test_plan.av = 0.9065
    calc.calculate_av(test_plan)
    assert_almost_equal(
        test_plan.av,
        0.9065,
        3,
        "Av is not equal to correct value. Should be {0} is " "{1}".format(0.9065, test_plan.av),
    )
    assert test_plan.tier == Tier.platinum, (
        "Tier does not match expected tier. Expected tier is {0} actual tier"
        " is {1}".format(Tier.platinum, test_plan.tier)
    )
def test__determine_moop_separate():
    test_plan = HealthPlan()
    test_plan.medical_deductible = 500
    test_plan.medical_coinsurance = .8
    test_plan.drug_deductible = 500
    test_plan.drug_coinsurance = .8
    test_plan.moop = 2000

    calc._set_metal_tier(test_plan)
    calc._determine_moop(test_plan, test_plan.medical_deductible,
                         test_plan.drug_deductible)
    assert_almost_equal(
        calc._moop_cost_level, 6186.38, 0,
        "Seperate plan moop not correct, actual {0}, expected "
        "{1}".format(calc._moop_cost_level, 6186.38))
def test__determine_moop_floor():
    test_plan = HealthPlan()
    test_plan.medical_deductible = 500
    test_plan.medical_coinsurance = .8
    test_plan.drug_deductible = 500
    test_plan.drug_coinsurance = .8
    test_plan.moop = 2000
    calc._set_metal_tier(test_plan)
    calc._ActuarialValueCalculator__moop_floor = 9000

    calc._determine_moop(test_plan, test_plan.medical_deductible,
                         test_plan.drug_deductible)
    assert_almost_equal(
        calc._moop_cost_level, 9000, 0,
        "Integrated plan moop not correct, actual {0}, "
        "expected {1}".format(calc._moop_cost_level, 9000))
def test__determine_moop_integrated():
    test_plan = HealthPlan()
    test_plan.deductible = 1000
    test_plan.coinsurance = .9
    test_plan.moop = 2000
    test_plan.tier = Tier.platinum

    calc._set_metal_tier(test_plan)
    calc._determine_moop(test_plan, test_plan.deductible)
    assert_almost_equal(
        calc._moop_cost_level, 11372.76, 0,
        ("Integrated plan moop not correct, actual {0}, "
         "expected {1}".format(calc._moop_cost_level, 11372.76)))
def test_existing_av():
    test_plan = HealthPlan()
    test_plan.deductible = 500
    test_plan.coinsurance = .9
    test_plan.moop = 1000
    test_plan.av = .9065
    calc.calculate_av(test_plan)
    assert_almost_equal(
        test_plan.av, .9065, 3,
        "Av is not equal to correct value. Should be {0} is "
        "{1}".format(.9065, test_plan.av))
    assert test_plan.tier == Tier.platinum, \
        "Tier does not match expected tier. Expected tier is {0} actual tier" \
        " is {1}".format(Tier.platinum, test_plan.tier)
def test__determine_moop_separate():
    test_plan = HealthPlan()
    test_plan.medical_deductible = 500
    test_plan.medical_coinsurance = 0.8
    test_plan.drug_deductible = 500
    test_plan.drug_coinsurance = 0.8
    test_plan.moop = 2000

    calc._set_metal_tier(test_plan)
    calc._determine_moop(test_plan, test_plan.medical_deductible, test_plan.drug_deductible)
    assert_almost_equal(
        calc._moop_cost_level,
        6186.38,
        0,
        "Seperate plan moop not correct, actual {0}, expected " "{1}".format(calc._moop_cost_level, 6186.38),
    )
def test__determine_moop_floor():
    test_plan = HealthPlan()
    test_plan.medical_deductible = 500
    test_plan.medical_coinsurance = 0.8
    test_plan.drug_deductible = 500
    test_plan.drug_coinsurance = 0.8
    test_plan.moop = 2000
    calc._set_metal_tier(test_plan)
    calc._ActuarialValueCalculator__moop_floor = 9000

    calc._determine_moop(test_plan, test_plan.medical_deductible, test_plan.drug_deductible)
    assert_almost_equal(
        calc._moop_cost_level,
        9000,
        0,
        "Integrated plan moop not correct, actual {0}, " "expected {1}".format(calc._moop_cost_level, 9000),
    )
def create_plan_from_hash(plan_hash):
    result = HealthPlan()
    result.parse_JSON(json.dumps(plan_hash))
    return result
def create_plan_from_hash(plan_hash):
    result = HealthPlan()
    result.parse_JSON(json.dumps(plan_hash))
    return result