fixup test_brandt

This commit is contained in:
Markus Teich 2016-10-15 20:30:46 +02:00
parent da43b9311a
commit ca00e6ba8e

View File

@ -60,7 +60,7 @@ expected_outcome (uint16_t i)
int32_t highest_bidder = -1; int32_t highest_bidder = -1;
int32_t highest_bid = -1; int32_t highest_bid = -1;
int32_t mpf_highest_bidder; int32_t mpf_highest_bidder;
int32_t mpf_highest_bid; int32_t mpf_highest_bid = -1;
int32_t prev_mpf_highest_bidder = -1; int32_t prev_mpf_highest_bidder = -1;
uint16_t winners = MIN (tcase.m, tcase.n); uint16_t winners = MIN (tcase.m, tcase.n);
uint16_t cur_winner = 0; uint16_t cur_winner = 0;
@ -82,17 +82,22 @@ expected_outcome (uint16_t i)
} }
/* find M+1st highest bidder to determine selling price */ /* find M+1st highest bidder to determine selling price */
for (uint16_t m = 0; m <= MIN (tcase.m, tcase.n - 1); m++) for (uint16_t h = 0; h < tcase.n; h++)
if (tcase.bids[h] > mpf_highest_bid)
mpf_highest_bid = tcase.bids[prev_mpf_highest_bidder = h];
for (uint16_t m = 0; m < MIN (tcase.m, tcase.n - 1); m++)
{ {
mpf_highest_bidder = -1;
mpf_highest_bid = -1;
for (uint16_t h = 0; h < tcase.n; h++) for (uint16_t h = 0; h < tcase.n; h++)
{ {
mpf_highest_bidder = -1;
mpf_highest_bid = -1;
if (tcase.bids[h] > mpf_highest_bid && if (tcase.bids[h] > mpf_highest_bid &&
(-1 == prev_mpf_highest_bidder || (tcase.bids[h] < tcase.bids[prev_mpf_highest_bidder] ||
tcase.bids[h] < tcase.bids[prev_mpf_highest_bidder] || (tcase.bids[h] == tcase.bids[prev_mpf_highest_bidder] &&
h > prev_mpf_highest_bidder)) h > prev_mpf_highest_bidder)))
{
mpf_highest_bid = tcase.bids[mpf_highest_bidder = h]; mpf_highest_bid = tcase.bids[mpf_highest_bidder = h];
}
} }
prev_mpf_highest_bidder = mpf_highest_bidder; prev_mpf_highest_bidder = mpf_highest_bidder;
} }
@ -224,7 +229,7 @@ cb_result (void *auction_closure,
if (0 == results_len) if (0 == results_len)
{ {
weprintf ("expected result is: %p", must); weprintf ("expected result is: %p", must);
weprintf ("computed result is: (nil) (from agent %d)", *s); weprintf ("computed result is: (nil) (by agent %d)", *s);
if (NULL != must) if (NULL != must)
tcase.ret = 1; tcase.ret = 1;
@ -237,7 +242,7 @@ cb_result (void *auction_closure,
must[i].status, must[i].status,
must[i].price); must[i].price);
weprintf ( weprintf (
"computed result is: bidder %d got status %d with price %d (from agent %d)", "computed result is: bidder %d got status %d with price %d (by agent %d)",
results[i].bidder, results[i].bidder,
results[i].status, results[i].status,
results[i].price, results[i].price,
@ -332,6 +337,12 @@ test_auction (uint16_t n,
tcase.outcome_public = outcome_public; tcase.outcome_public = outcome_public;
tcase.ret = 0; tcase.ret = 0;
weprintf ("######################################");
weprintf ("testing %s auction with m = %d and %s outcome",
tcase.m > 0 ? "M+1ST PRICE" : "FIRST PRICE",
tcase.m,
tcase.outcome_public ? "PUBLIC" : "PRIVATE");
weprintf ("######################################");
tcase.ad = GNUNET_new_array (tcase.n + 1, struct BRANDT_Auction *); tcase.ad = GNUNET_new_array (tcase.n + 1, struct BRANDT_Auction *);
tcase.id = GNUNET_new_array (tcase.n + 1, uint16_t); tcase.id = GNUNET_new_array (tcase.n + 1, uint16_t);
for (uint16_t i = 0; i <= tcase.n; i++) for (uint16_t i = 0; i <= tcase.n; i++)
@ -367,8 +378,12 @@ main (int argc, char *argv[])
edc = GNUNET_CRYPTO_ecc_dlog_prepare (1024, 16); edc = GNUNET_CRYPTO_ecc_dlog_prepare (1024, 16);
BRANDT_init (edc); BRANDT_init (edc);
ret |= test_auction (4, 3, (uint16_t[]) { 1, 2, 0, 2 }, 0, 1) || ret |= 0 ||
test_auction (4, 3, (uint16_t[]) { 1, 2, 0, 2 }, 0, 0); test_auction (2, 2, (uint16_t[]) { 1, 0 }, 1, 0) ||
test_auction (3, 2, (uint16_t[]) { 0, 0, 1 }, 2, 0) ||
test_auction (3, 2, (uint16_t[]) { 0, 1, 1 }, 0, 0) ||
test_auction (3, 2, (uint16_t[]) { 0, 1, 1 }, 0, 1) ||
0;
GNUNET_CRYPTO_ecc_dlog_release (edc); GNUNET_CRYPTO_ecc_dlog_release (edc);
return ret; return ret;