def test(data, beta):
    """ Output the quantities necessary to compute the accuracy, precision, and recall of the prediction of labels in a dataset under a given β.
        
        The accuracy (ACC), precision (PRE), and recall (REC) are defined in terms of the following sets:

                 P = datapoints (x,y) in data for which <β,x> > 0
                 N = datapoints (x,y) in data for which <β,x> <= 0
                 
                 TP = datapoints in (x,y) in P for which y=+1  
                 FP = datapoints in (x,y) in P for which y=-1  
                 TN = datapoints in (x,y) in N for which y=-1
                 FN = datapoints in (x,y) in N for which y=+1

        For #XXX the number of elements in set XXX, the accuracy, precision, and recall of parameter vector β over data are defined as:
         
                 ACC(β,data) = ( #TP+#TN ) / (#P + #N)
                 PRE(β,data) = #TP / (#TP + #FP)
                 REC(β,data) = #TP/ (#TP + #FN)

        Inputs are:
             - data: an RDD containing pairs of the form (x,y)
             - beta: vector β

        The return values are
             - ACC, PRE, REC
       
    """
    P = N = TP = FP = TN = FN = 0
    for (x, y) in data:
        if beta.dot(x) > 0:
            P += 1
            if y == 1:
                TP += 1
            else:
                FP += 1
        else:
            N += 1
            if y == -1:
                TN += 1
            else:
                FN += 1

    ACC = 1. * (TP + TN) / (P + N)
    PRE = 1. * TP / (TP + FP)
    REC = 1. * TP / (TP + FN)
    return ACC, PRE, REC