# Path: automlk/metrics.py
# def gini(y_act, y_pred):
#     """
#     metrics gini = Gini coefficient (classification only)
# 
#     :param y_act: vector of actual values
#     :param y_pred: vector of predicted values
#     :return: gini
#     """
#     assert (len(y_act) == len(y_pred))
#     all = np.asarray(np.c_[y_act, y_pred, np.arange(len(y_act))], dtype=np.float)
#     all = all[np.lexsort((all[:, 2], -1 * all[:, 1]))]
#     totalLosses = all[:, 0].sum()
#     giniSum = all[:, 0].cumsum().sum() / totalLosses
#     giniSum -= (len(y_act) + 1) / 2.
#     return giniSum / len(y_act)
# 
# def gini_normalized(y_act, y_pred):
#     """
#     metrics normalized gini = Normalized Gini coefficient (classification only)
# 
#     :param y_act: vector of actual values
#     :param y_pred: vector of predicted values
#     :return: gini
#     """
#     return gini(y_act, y_pred) / gini(y_act, y_act)


from automlk.metrics import gini, gini_normalized


def test_gini():
    def fequ(a, b):
        return abs(a - b) < 1e-6

    def T(a, p, g, n):
        assert (fequ(gini(a, p), g))

# Path: automlk/metrics.py
# def gini(y_act, y_pred):
#     """
#     metrics gini = Gini coefficient (classification only)
# 
#     :param y_act: vector of actual values
#     :param y_pred: vector of predicted values
#     :return: gini
#     """
#     assert (len(y_act) == len(y_pred))
#     all = np.asarray(np.c_[y_act, y_pred, np.arange(len(y_act))], dtype=np.float)
#     all = all[np.lexsort((all[:, 2], -1 * all[:, 1]))]
#     totalLosses = all[:, 0].sum()
#     giniSum = all[:, 0].cumsum().sum() / totalLosses
#     giniSum -= (len(y_act) + 1) / 2.
#     return giniSum / len(y_act)
# 
# def gini_normalized(y_act, y_pred):
#     """
#     metrics normalized gini = Normalized Gini coefficient (classification only)
# 
#     :param y_act: vector of actual values
#     :param y_pred: vector of predicted values
#     :return: gini
#     """
#     return gini(y_act, y_pred) / gini(y_act, y_act)


# Path: tests/test_gini.py
from automlk.metrics import gini, gini_normalized



def test_gini():
    def fequ(a, b):
        return abs(a - b) < 1e-6

    def T(a, p, g, n):
        assert (fequ(gini(a, p), g))

        assert (fequ(gini_normalized(a, p), n))