def test_DPL():
    df = pd.DataFrame({"x": ["a", "a", "b", "b"], "y": [1, 1, 0, 1]})
    res = metric_one_vs_all(DPL,
                            df["x"],
                            label=df["y"],
                            positive_label_index=(df["y"] == 1))
    assert res["a"] == -0.5
    assert res["b"] == 0.5
    return
def test_CI():
    sensitive_facet_index = dfB[0] == "F"
    assert CI(dfB[0], sensitive_facet_index) == approx(-1 / 6)

    sensitive_facet_index = dfB[0] == "M"
    assert CI(dfB[0], sensitive_facet_index) == approx(1 / 6)

    # Continuous Facet, Binary Label
    sensitive_facet_index = dfC[0] > 1.0
    assert CI(dfC[0], sensitive_facet_index) == approx(-1 / 3)

    sensitive_facet_index = dfC[0] < 1.0
    assert CI(dfC[0], sensitive_facet_index) == approx(1 / 3)

    # Multicategory Facet, Binary Label

    response = metric_one_vs_all(CI, dfM[0])
    assert response["M"] == approx(1 / 3)
    assert response["F"] == approx(1 / 4)
    assert response["O"] == approx(5 / 12)
def test_CDD():
    x = pd.Series([
        "M",
        "M",
        "M",
        "F",
        "F",
        "F",
        "F",
        "M",
        "M",
        "M",
        "M",
        "F",
        "M",
        "M",
        "F",
        "M",
        "F",
        "F",
        "M",
        "M",
        "F",
        "M",
        "M",
        "F",
    ])
    positive_label_index = pd.Series([
        0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0
    ])
    group_variable = pd.Series([
        1, 0, 2, 2, 1, 1, 2, 1, 1, 2, 0, 1, 2, 0, 1, 1, 1, 2, 0, 1, 0, 0, 1, 1
    ])

    response = metric_one_vs_all(
        CDDL,
        x,
        positive_label_index=positive_label_index == 1,
        group_variable=group_variable)
    assert response["F"] == approx(0.3982142857)
    assert response["M"] == approx(-0.3982142857)