aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Teich <markus.teich@stusta.mhn.de>2016-10-15 20:30:46 +0200
committerMarkus Teich <markus.teich@stusta.mhn.de>2016-10-15 20:30:46 +0200
commitca00e6ba8edc207aa4e296a796b9bc60ebc7c60f (patch)
tree0c1322e0ef5b54187d5dc4f1f85235912c059cf5
parentda43b9311a53daa9c120735c60e9ba9e1955990c (diff)
downloadlibbrandt-ca00e6ba8edc207aa4e296a796b9bc60ebc7c60f.tar.gz
libbrandt-ca00e6ba8edc207aa4e296a796b9bc60ebc7c60f.zip
fixup test_brandt
-rw-r--r--test_brandt.c37
1 files changed, 26 insertions, 11 deletions
diff --git a/test_brandt.c b/test_brandt.c
index 8a27748..0db012c 100644
--- a/test_brandt.c
+++ b/test_brandt.c
@@ -60,7 +60,7 @@ expected_outcome (uint16_t i)
60 int32_t highest_bidder = -1; 60 int32_t highest_bidder = -1;
61 int32_t highest_bid = -1; 61 int32_t highest_bid = -1;
62 int32_t mpf_highest_bidder; 62 int32_t mpf_highest_bidder;
63 int32_t mpf_highest_bid; 63 int32_t mpf_highest_bid = -1;
64 int32_t prev_mpf_highest_bidder = -1; 64 int32_t prev_mpf_highest_bidder = -1;
65 uint16_t winners = MIN (tcase.m, tcase.n); 65 uint16_t winners = MIN (tcase.m, tcase.n);
66 uint16_t cur_winner = 0; 66 uint16_t cur_winner = 0;
@@ -82,17 +82,22 @@ expected_outcome (uint16_t i)
82 } 82 }
83 83
84 /* find M+1st highest bidder to determine selling price */ 84 /* find M+1st highest bidder to determine selling price */
85 for (uint16_t m = 0; m <= MIN (tcase.m, tcase.n - 1); m++) 85 for (uint16_t h = 0; h < tcase.n; h++)
86 if (tcase.bids[h] > mpf_highest_bid)
87 mpf_highest_bid = tcase.bids[prev_mpf_highest_bidder = h];
88 for (uint16_t m = 0; m < MIN (tcase.m, tcase.n - 1); m++)
86 { 89 {
90 mpf_highest_bidder = -1;
91 mpf_highest_bid = -1;
87 for (uint16_t h = 0; h < tcase.n; h++) 92 for (uint16_t h = 0; h < tcase.n; h++)
88 { 93 {
89 mpf_highest_bidder = -1;
90 mpf_highest_bid = -1;
91 if (tcase.bids[h] > mpf_highest_bid && 94 if (tcase.bids[h] > mpf_highest_bid &&
92 (-1 == prev_mpf_highest_bidder || 95 (tcase.bids[h] < tcase.bids[prev_mpf_highest_bidder] ||
93 tcase.bids[h] < tcase.bids[prev_mpf_highest_bidder] || 96 (tcase.bids[h] == tcase.bids[prev_mpf_highest_bidder] &&
94 h > prev_mpf_highest_bidder)) 97 h > prev_mpf_highest_bidder)))
98 {
95 mpf_highest_bid = tcase.bids[mpf_highest_bidder = h]; 99 mpf_highest_bid = tcase.bids[mpf_highest_bidder = h];
100 }
96 } 101 }
97 prev_mpf_highest_bidder = mpf_highest_bidder; 102 prev_mpf_highest_bidder = mpf_highest_bidder;
98 } 103 }
@@ -224,7 +229,7 @@ cb_result (void *auction_closure,
224 if (0 == results_len) 229 if (0 == results_len)
225 { 230 {
226 weprintf ("expected result is: %p", must); 231 weprintf ("expected result is: %p", must);
227 weprintf ("computed result is: (nil) (from agent %d)", *s); 232 weprintf ("computed result is: (nil) (by agent %d)", *s);
228 233
229 if (NULL != must) 234 if (NULL != must)
230 tcase.ret = 1; 235 tcase.ret = 1;
@@ -237,7 +242,7 @@ cb_result (void *auction_closure,
237 must[i].status, 242 must[i].status,
238 must[i].price); 243 must[i].price);
239 weprintf ( 244 weprintf (
240 "computed result is: bidder %d got status %d with price %d (from agent %d)", 245 "computed result is: bidder %d got status %d with price %d (by agent %d)",
241 results[i].bidder, 246 results[i].bidder,
242 results[i].status, 247 results[i].status,
243 results[i].price, 248 results[i].price,
@@ -332,6 +337,12 @@ test_auction (uint16_t n,
332 tcase.outcome_public = outcome_public; 337 tcase.outcome_public = outcome_public;
333 tcase.ret = 0; 338 tcase.ret = 0;
334 339
340 weprintf ("######################################");
341 weprintf ("testing %s auction with m = %d and %s outcome",
342 tcase.m > 0 ? "M+1ST PRICE" : "FIRST PRICE",
343 tcase.m,
344 tcase.outcome_public ? "PUBLIC" : "PRIVATE");
345 weprintf ("######################################");
335 tcase.ad = GNUNET_new_array (tcase.n + 1, struct BRANDT_Auction *); 346 tcase.ad = GNUNET_new_array (tcase.n + 1, struct BRANDT_Auction *);
336 tcase.id = GNUNET_new_array (tcase.n + 1, uint16_t); 347 tcase.id = GNUNET_new_array (tcase.n + 1, uint16_t);
337 for (uint16_t i = 0; i <= tcase.n; i++) 348 for (uint16_t i = 0; i <= tcase.n; i++)
@@ -367,8 +378,12 @@ main (int argc, char *argv[])
367 edc = GNUNET_CRYPTO_ecc_dlog_prepare (1024, 16); 378 edc = GNUNET_CRYPTO_ecc_dlog_prepare (1024, 16);
368 BRANDT_init (edc); 379 BRANDT_init (edc);
369 380
370 ret |= test_auction (4, 3, (uint16_t[]) { 1, 2, 0, 2 }, 0, 1) || 381 ret |= 0 ||
371 test_auction (4, 3, (uint16_t[]) { 1, 2, 0, 2 }, 0, 0); 382 test_auction (2, 2, (uint16_t[]) { 1, 0 }, 1, 0) ||
383 test_auction (3, 2, (uint16_t[]) { 0, 0, 1 }, 2, 0) ||
384 test_auction (3, 2, (uint16_t[]) { 0, 1, 1 }, 0, 0) ||
385 test_auction (3, 2, (uint16_t[]) { 0, 1, 1 }, 0, 1) ||
386 0;
372 387
373 GNUNET_CRYPTO_ecc_dlog_release (edc); 388 GNUNET_CRYPTO_ecc_dlog_release (edc);
374 return ret; 389 return ret;