def test_all_pr():
 pos_scores = [(-1.0), 0.0, 2.0]
 neg_scores = [(-2.0), 0.0, 1.0]
 precision = [1.0, 1.0, 0.5, 0.5, 0.6, (3.0 / 6.0)]
 recall = [0.0, (1.0 / 3.0), (1.0 / 3.0), (2.0 / 3.0), 1.0, 1.0]
 (p, r) = all_pr(pos_scores, neg_scores)
 assert (len(p) == len(precision))
 assert (len(r) == len(recall))
 for i in xrange(len(p)):
  assert (p[i] == precision[i]), (i, p[i], precision[i])
  assert (recall[i] == recall[i])

def test_all_pr ( ) : pos_scores = [ ( - 1.0 ) , 0.0 , 2.0 ] neg_scores = [ ( - 2.0 ) , 0.0 , 1.0 ] precision = [ 1.0 , 1.0 , 0.5 , 0.5 , 0.6 , ( 3.0 / 6.0 ) ] recall = [ 0.0 , ( 1.0 / 3.0 ) , ( 1.0 / 3.0 ) , ( 2.0 / 3.0 ) , 1.0 , 1.0 ] ( p , r ) = all_pr ( pos_scores , neg_scores ) assert ( len ( p ) == len ( precision ) ) assert ( len ( r ) == len ( recall ) ) for i in xrange ( len ( p ) ) : assert ( p [ i ] == precision [ i ] ) , ( i , p [ i ] , precision [ i ] ) assert ( recall [ i ] == recall [ i ] )
tests that all_pr matches a hand-obtained solution .