diff options
author | Markus Teich <markus.teich@stusta.mhn.de> | 2016-11-22 03:17:01 +0100 |
---|---|---|
committer | Markus Teich <markus.teich@stusta.mhn.de> | 2016-11-22 03:17:01 +0100 |
commit | 5706e91058ff6aa4b23b6fb13871853a54a5c4d2 (patch) | |
tree | a10f6e774ff6bd9eae30410613f30b90c153ca6a /test_brandt.c | |
parent | a74e1503752e310fbfc8dda142c5803eff86dc88 (diff) | |
download | libbrandt-5706e91058ff6aa4b23b6fb13871853a54a5c4d2.tar.gz libbrandt-5706e91058ff6aa4b23b6fb13871853a54a5c4d2.zip |
add m+1st price auctions with public outcome
Diffstat (limited to 'test_brandt.c')
-rw-r--r-- | test_brandt.c | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/test_brandt.c b/test_brandt.c index 46ec90d..d18b17a 100644 --- a/test_brandt.c +++ b/test_brandt.c | |||
@@ -54,7 +54,7 @@ static struct testcase tcase; | |||
54 | 54 | ||
55 | 55 | ||
56 | static struct BRANDT_Result * | 56 | static struct BRANDT_Result * |
57 | expected_outcome (uint16_t i) | 57 | expected_outcome (uint16_t i, uint16_t *rlen) |
58 | { | 58 | { |
59 | struct BRANDT_Result *ret = NULL; | 59 | struct BRANDT_Result *ret = NULL; |
60 | int32_t highest_bidder = -1; | 60 | int32_t highest_bidder = -1; |
@@ -65,6 +65,8 @@ expected_outcome (uint16_t i) | |||
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; |
67 | 67 | ||
68 | *rlen = 0; | ||
69 | |||
68 | if (0 == tcase.n) | 70 | if (0 == tcase.n) |
69 | return NULL; | 71 | return NULL; |
70 | 72 | ||
@@ -81,6 +83,7 @@ expected_outcome (uint16_t i) | |||
81 | ret->bidder = highest_bidder; | 83 | ret->bidder = highest_bidder; |
82 | ret->price = highest_bid; | 84 | ret->price = highest_bid; |
83 | ret->status = BRANDT_bidder_won; | 85 | ret->status = BRANDT_bidder_won; |
86 | *rlen = 1; | ||
84 | return ret; | 87 | return ret; |
85 | } | 88 | } |
86 | 89 | ||
@@ -89,7 +92,7 @@ expected_outcome (uint16_t i) | |||
89 | { | 92 | { |
90 | if (tcase.outcome_public || i == tcase.n) | 93 | if (tcase.outcome_public || i == tcase.n) |
91 | { | 94 | { |
92 | ret = GNUNET_new_array (tcase.n, struct BRANDT_Result); | 95 | ret = GNUNET_new_array ((*rlen = tcase.n), struct BRANDT_Result); |
93 | for (uint16_t h = 0; h < tcase.n; h++) | 96 | for (uint16_t h = 0; h < tcase.n; h++) |
94 | { | 97 | { |
95 | ret[h].bidder = h; | 98 | ret[h].bidder = h; |
@@ -103,6 +106,7 @@ expected_outcome (uint16_t i) | |||
103 | ret->bidder = i; | 106 | ret->bidder = i; |
104 | ret->price = 0; | 107 | ret->price = 0; |
105 | ret->status = BRANDT_bidder_won; | 108 | ret->status = BRANDT_bidder_won; |
109 | *rlen = 1; | ||
106 | } | 110 | } |
107 | return ret; | 111 | return ret; |
108 | } | 112 | } |
@@ -154,6 +158,7 @@ expected_outcome (uint16_t i) | |||
154 | cur_winner++; | 158 | cur_winner++; |
155 | } | 159 | } |
156 | } | 160 | } |
161 | *rlen = cur_winner; | ||
157 | return ret; | 162 | return ret; |
158 | } | 163 | } |
159 | 164 | ||
@@ -250,7 +255,16 @@ cb_result (void *auction_closure, | |||
250 | uint16_t results_len) | 255 | uint16_t results_len) |
251 | { | 256 | { |
252 | uint16_t *s = (uint16_t *)auction_closure; | 257 | uint16_t *s = (uint16_t *)auction_closure; |
253 | struct BRANDT_Result *must = expected_outcome (*s); | 258 | uint16_t mustlen = -1; |
259 | struct BRANDT_Result *must = expected_outcome (*s, &mustlen); | ||
260 | |||
261 | if (mustlen != results_len) | ||
262 | { | ||
263 | weprintf ("expected result len is: %d", mustlen); | ||
264 | weprintf ("computed result len is: %d (by agent %d)", results_len, *s); | ||
265 | tcase.ret = 1; | ||
266 | goto quit; | ||
267 | } | ||
254 | 268 | ||
255 | if (0 == results_len) | 269 | if (0 == results_len) |
256 | { | 270 | { |
@@ -281,6 +295,7 @@ cb_result (void *auction_closure, | |||
281 | tcase.ret = 1; | 295 | tcase.ret = 1; |
282 | } | 296 | } |
283 | 297 | ||
298 | quit: | ||
284 | tcase.result_called[*s] = 1; | 299 | tcase.result_called[*s] = 1; |
285 | if (must) | 300 | if (must) |
286 | GNUNET_free (must); | 301 | GNUNET_free (must); |
@@ -406,17 +421,24 @@ main (int argc, char *argv[]) | |||
406 | BRANDT_init (edc); | 421 | BRANDT_init (edc); |
407 | 422 | ||
408 | ret |= 0 || | 423 | ret |= 0 || |
424 | // zero bidders | ||
409 | test_auction (0, 2, NULL, 0, 0) || | 425 | test_auction (0, 2, NULL, 0, 0) || |
410 | test_auction (0, 2, NULL, 0, 1) || | 426 | test_auction (0, 2, NULL, 0, 1) || |
411 | test_auction (0, 2, NULL, 1, 0) || | 427 | test_auction (0, 2, NULL, 1, 0) || |
412 | test_auction (0, 2, NULL, 2, 0) || | 428 | test_auction (0, 2, NULL, 2, 0) || |
429 | |||
430 | // too few bidders => outcome is lowest possible price | ||
413 | test_auction (1, 2, (uint16_t[]) { 1 }, 1, 0) || | 431 | test_auction (1, 2, (uint16_t[]) { 1 }, 1, 0) || |
414 | test_auction (1, 2, (uint16_t[]) { 0 }, 2, 0) || | 432 | test_auction (1, 2, (uint16_t[]) { 0 }, 2, 0) || |
415 | test_auction (2, 2, (uint16_t[]) { 1, 0 }, 2, 0) || | 433 | test_auction (2, 2, (uint16_t[]) { 1, 0 }, 2, 0) || |
416 | test_auction (2, 2, (uint16_t[]) { 1, 0 }, 1, 0) || | 434 | test_auction (2, 2, (uint16_t[]) { 1, 0 }, 1, 0) || |
417 | test_auction (3, 2, (uint16_t[]) { 0, 0, 1 }, 2, 0) || | 435 | test_auction (3, 2, (uint16_t[]) { 0, 0, 1 }, 2, 0) || |
436 | |||
437 | // general checks of all four algorithms | ||
418 | test_auction (3, 2, (uint16_t[]) { 0, 1, 1 }, 0, 0) || | 438 | test_auction (3, 2, (uint16_t[]) { 0, 1, 1 }, 0, 0) || |
419 | test_auction (3, 2, (uint16_t[]) { 0, 1, 1 }, 0, 1) || | 439 | test_auction (3, 2, (uint16_t[]) { 0, 1, 1 }, 0, 1) || |
440 | test_auction (3, 2, (uint16_t[]) { 0, 1, 1 }, 2, 0) || | ||
441 | test_auction (3, 2, (uint16_t[]) { 0, 1, 1 }, 2, 1) || | ||
420 | 0; | 442 | 0; |
421 | 443 | ||
422 | GNUNET_CRYPTO_ecc_dlog_release (edc); | 444 | GNUNET_CRYPTO_ecc_dlog_release (edc); |